Back to Devexpress

XmpDocument.RegisterNamespace(String, String) Method

officefileapi-devexpress-dot-pdf-dot-xmp-dot-xmpdocument-dot-registernamespace-x28-system-dot-string-system-dot-string-x29.md

latest5.0 KB
Original Source

XmpDocument.RegisterNamespace(String, String) Method

Registers the namespace in the XMP packet.

Namespace : DevExpress.Pdf.Xmp

Assembly : DevExpress.Pdf.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public bool RegisterNamespace(
    string namespaceUri,
    string preferredPrefix
)
vb
Public Function RegisterNamespace(
    namespaceUri As String,
    preferredPrefix As String
) As Boolean

Parameters

NameTypeDescription
namespaceUriString

The namespace URI.

| | preferredPrefix | String |

The preferred prefix.

|

Returns

TypeDescription
Boolean

true , if the namespace is registered successfully; otherwise, false.

|

Remarks

When you add a new node to the packet, you can use an XmpName class object or a string to specify the node name. In the latter case, make sure that the specified prefix is registered. You can call the RegisterNamespace method to register the prefix.

The code sample below registers the prefix and adds a new node to the packet:

csharp
using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
    // Load a document:
    pdfDocumentProcessor.LoadDocument("Documents//Invoice_blank.pdf");
    PdfDocument document = pdfDocumentProcessor.Document;

    XmpDocument generatedMetadata = new XmpDocument();

    // Register namespaces:
    document.RegisterNamespace("http://ns.adobe.com/xap/1.0/", "xmp");

    // Add items with "xmp" prefix:
    XmpArray array = document.CreateArray("xmp:Identifier", XmpArrayType.Unordered);
    array.Add("identifier1");
    array.Add("identifier2");
    array.Add("identifier3");
    document.CreateSimpleValue("xmp:Label", "Demo");

    // Embed generated metadata to the document:
    document.SetMetadata(generatedMetadata);

    // Save the result:
    pdfDocumentProcessor.SaveDocument("Invoice_new.pdf");
}
vb
Using pdfDocumentProcessor As New PdfDocumentProcessor()
  ' Load a document:
  pdfDocumentProcessor.LoadDocument("Documents//Invoice_blank.pdf")
  Dim document As PdfDocument = pdfDocumentProcessor.Document

  Dim generatedMetadata As New XmpDocument()

  ' Register namespaces:
  document.RegisterNamespace("http://ns.adobe.com/xap/1.0/", "xmp")

  ' Add items with "xmp" prefix:
  Dim array As XmpArray = document.CreateArray("xmp:Identifier", XmpArrayType.Unordered)
  array.Add("identifier1")
  array.Add("identifier2")
  array.Add("identifier3")
  document.CreateSimpleValue("xmp:Label", "Demo")

  ' Embed generated metadata to the document:
  document.SetMetadata(generatedMetadata)

  ' Save the result:
  pdfDocumentProcessor.SaveDocument("Invoice_new.pdf")
End Using

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the RegisterNamespace(String, String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

pdf-document-api-xmp-example/CS/XmpMetadataExamples/Program.cs#L43

csharp
XmpStructure dimensions = editedMetadata.CreateStructure(structureName);
editedMetadata.RegisterNamespace("http://ns.adobe.com/xap/1.0/sType/Dimensions#", "stDim");
dimensions.Add("stDim:h", 11);

pdf-document-api-xmp-example/VB/XmpMetadataExamples/Program.vb#L35

vb
Dim dimensions As XmpStructure = editedMetadata.CreateStructure(structureName)
editedMetadata.RegisterNamespace("http://ns.adobe.com/xap/1.0/sType/Dimensions#", "stDim")
dimensions.Add("stDim:h", 11)

See Also

XmpDocument Class

XmpDocument Members

DevExpress.Pdf.Xmp Namespace