PDF Xpress for .NET - User Guide > How To > Modify PDF Document Content > Create, Modify & Delete Annotations |
PDF Xpress™ provides the capability to export PDF annotations to an XFDF file (ExportXfdf). The application may then read, modify, and write annotations to the XFDF file. When the application calls ImportXfdf, these modifications are applied to the annotations within the PDF document.
NotateXpress may be used in conjunction with PDF Xpress to provide programmatic or application end-user annotation capabilities. |
PDF Xpress supports a subset of PDF native annotations:
PDF Xpress creates XFDF that complies with the published XML Schema: http://partners.adobe.com/public/developer/en/xml/xfdf.xsd However, PDF Xpress created XFDF will contain only data for PDF Xpress supported annotations. For more information on PDF Xpress support of XFDF elements and attributes, see Frequently Asked Questions: http://www.accusoft.com/pdfxpressfaq.htm |
Annotations can be retrieved from a PDF document by calling the ExportXfdf method. This method writes PDF annotations from the PDF document into an XFDF file.
C# Example |
Copy Code
|
---|---|
// This code demonstrates how to export annotations from a single-page PDF document Accusoft.PdfXpressSdk.PdfXpress pdfXpress1 = null; Accusoft.PdfXpressSdk.Document document = null; XfdfOptions xfdfoptions = null; try { pdfXpress1 = new PdfXpress(); pdfXpress1.Initialize(); document = new Document(pdfXpress1, "C:\\mynewfile.pdf"); xfdfoptions = new XfdfOptions(); xfdfoptions.WhichAnnotation = XfdfOptions.AllAnnotations; xfdfoptions.WhichPage = 0; byte[] xfdf = document.ExportXfdf(xfdfoptions); Encoding encoding = System.Text.Encoding.Unicode; string xml = encoding.GetString(xfdf); using (StreamWriter sw = new StreamWriter("C:\\sample.xfdf")) { sw.Write(xml); } } catch (System.Exception) { } finally { if (null != document) { document.Dispose(); } if (null != pdfXpress1) { pdfXpress1.Dispose(); } } |
Annotations can be written to a PDF document by calling the ImportXfdf method. This method takes an XFDF file as input, and stores the annotations as part of the PDF document.
C# Example |
Copy Code
|
---|---|
// This code demonstrates how to write annotations to a PDF file Accusoft.PdfXpressSdk.PdfXpress pdfxpress1 = null; XfdfOptions xo = null; try { pdfxpress1 = new PdfXpress(); pdfxpress1.Initialize(); pdfxpress1.Documents.Add("C:\\test.pdf"); xo = new XfdfOptions(); xo.CanCreateAnnotations = true; byte[] xfdf = File.ReadAllBytes("C:\\many21.xfdf"); pdfxpress1.Documents[0].ImportXfdf(xo, xfdf); } catch (System.Exception) { } finally { if (null != pdfxpress1) { pdfxpress1.Dispose(); } } |