Import XMP Annotation Data to PDF or Image in C#

XMP annotations can be stored in one of the following ways:

  • XML file

  • Stream object

  • Base64-encoded string

To import XMP annotations to the currently opened file in the AnnotationManager object, use the LoadAnnotationsFromXMP method for XML files and Stream objects, and the LoadAnnotationsFromXMPBase64 method for the encoded string.

In the following example, the XMP annotations from a template image are applied to another image:

using AnnotationManager annotationManager = new AnnotationManager();
// Load the template image to the `AnnotationManager` object.
annotationManager.InitFromFile(@"C:\temp\template.jpg");
// Save the annotations from the template image to an XML file.
annotationManager.SaveAnnotationsToXMP(@"C:\temp\annotTemplate.xml");
// Load the source image to the `AnnotationManager` object.
annotationManager.InitFromFile(@"C:\temp\source.jpg");
// Load the XML file with the annotations to the `AnnotationManager` object.
annotationManager.LoadAnnotationsFromXMP(@"C:\temp\annotTemplate.xml");
// Flatten the annotations into the image.
annotationManager.BurnAnnotationsToPage(false);
// Save the image to a file.
annotationManager.SaveDocumentToJPEG(@"C:\temp\output.jpg", 100);
Using annotationManager As AnnotationManager = New AnnotationManager()
    ' Load the template image to the `AnnotationManager` object.
    annotationManager.InitFromFile("C:\temp\template.jpg")
    ' Save the annotations from the template image to an XML file.
    annotationManager.SaveAnnotationsToXMP("C:\temp\annotTemplate.xml")
    ' Load the source image to the `AnnotationManager` object.
    annotationManager.InitFromFile("C:\temp\source.jpg")
    ' Load the XML file with the annotations to the `AnnotationManager` object.
    annotationManager.LoadAnnotationsFromXMP("C:\temp\annotTemplate.xml")
    ' Flatten the annotations into the image.
    annotationManager.BurnAnnotationsToPage(False)
    ' Save the image to a file.
    annotationManager.SaveDocumentToJPEG("C:\temp\output.jpg", 100)
End Using
Used Methods

Related Topics

An XML Forms Data Format (XFDF) file stores data from annotations located in PDF documents. It contains the annotation structure and the values submitted to it.

Importing XFXF Data from a File

To import the annotation data from a file, use the ImportXFDFDataFromFile method with the following required parameters:

  • FilePath — The file path of the XFDF file.

  • ImportFormFields — A Boolean value that specifies whether to import the form field data.

  • ImportAnnotations — A Boolean value that specifies whether to import the annotation data.

The example below imports a PDF annotation from an XFDF file:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
gdpicturePDF.ImportXFDFDataFromFile(@"C:\temp\annotation.xfdf", true, true);
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    gdpicturePDF.ImportXFDFDataFromFile("C:\temp\annotation.xfdf", True, True)
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using
Used Methods

Related Topics

Importing XFXF Data from a Database

To import the annotation data from a database, save the XFDF information from the database as a Stream object, and then use the ImportXFDFDataFromStream method with the following required parameters:

  • Stream — The Stream object containing XFDF information.

  • ImportFormFields — A Boolean value that specifies whether to import the form field data.

  • ImportAnnotations — A Boolean value that specifies whether to import the annotation data.

The example below imports a PDF annotation from a Stream object containing XFDF information:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
gdpicturePDF.ImportXFDFDataFromStream(XFDFStream, true, true);
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    gdpicturePDF.ImportXFDFDataFromStream(XFDFStream, True, True)
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using
Used Methods

Related Topics