PDFXML Class
Properties Methods Events Configuration Settings Errors
The PDFXML class provides a simple way to embed and parse PDF attachments.
Syntax
ipworksedi.pdfxml()
Remarks
The PDFXML class provides a simple way to embed and parse PDF attachments. While all file formats are supported as attachments, XML attachments may be directly navigated when using the component via the XPath related properties.
Getting Started
To start, specify a PDF file by either setting InputFile, InputData or calling SetInputStream. After an input source is set, call Load (not needed if data was provided to InputData).
Add an attachment by calling AddAttachment or adding an object to the Attachments collection.
Once an attachment has been added, specify an OutputFile or call SetOutputStream and call Save. If OutputFile is not set and SetOutputStream is not used, the data will be written to OutputData.
pdfxml.InputFile = "C:\input.pdf"; pdfxml.Load(); pdfxml.AddAttachment("C:\attachmentfile.txt"); pdfxml.OutputFile = "C:\output.pdf"; pdfxml.Save();
Parsing XML attachments
Attached XML files may be parsed by calling the ParseAttachment method. The class will try to parse the attachment at the specified Index. After ParseAttachment returns the document may be navigated by setting XPath.
XPath implements a subset of the XML XPath specification, allowing you to point to specific elements in the XML documents.
The path is a series of one or more element accessors separated by '/'. The path can be absolute (starting with '/') or relative to the current XPath location.
The following are possible values for an element accessor:
'name' | A particular element name |
name[i] | The i-th subelement of the current element with the given name |
[i] | The i-th subelement of the current element |
[last()] | The last subelement of the current element |
[last()-i] | The subelement located at the last location minus i in the current element |
name[@attrname="attrvalue"] | The subelement containing a particular value for a given attribute (supports single AND double quotes) |
.. | The parent of the current element |
BuildDOM must be set to True prior to parsing the document for the XPath functionality to be available.
Example (Setting XPath):
Document root | XML.XPath = "/" |
Specific Element | XML.XPath = "/root/SubElement1/SubElement2/" |
i-th Child | XML.XPath = "/root/SubElement1[i]" |
Example (Parse and Navigate):
pdfxml.InputFile = "C:\input.pdf"; pdfxml.Load(); pdfxml.ParseAttachment(0); pdfxml.XPath = "/root/element"; Console.WriteLine(pdfxml.XText);
ZUGFeRD Notes
ZUGFeRD compliant invoices can also be generated by when ZUGFeRDMode is set to True. For instance the code below will generate a ZUGFeRD 2.0 invoice with EXTENDED conformance level.
//Load pdfxml.InputFile = "C:\input.pdf"; pdfxml.Load(); //Configure for ZUGFeRD pdfxml.Config("ZUGFeRDMode=true"); pdfxml.Config("ZUGFeRDVersion=2.0"); pdfxml.Config("ZUGFeRDConformanceLevel=EXTENDED"); pdfxml.AddAttachment("C:\ZUGFeRD-invoice.xml"); // Save pdfxml.InputFile = "C:\input.pdf"; pdfxml.OutputFile = C:\zugferd_invoice_pdfa3b.pdf"; pdfxml.Save();
Property List
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
Attachments | Collection of files attached to the current PDF. |
InputData | The input PDF data. |
InputFile | The input PDF file to process. |
OutputData | The output PDF data. |
OutputFile | The output file. |
Overwrite | Indicates whether or not the class should overwrite files. |
XAttributes | A collection of attributes of the current element. |
XChildren | Collection of child elements of the currently selected XML element. |
XComments | A collection of comments of the current element. |
XElement | The name of the current element. |
XMLDeclaration | Specifies details of the XML declaration. |
XNamespace | The namespace of the current element. |
XParent | The parent of the current element. |
XPath | Provides a way to point to a specific element in the document. |
XPrefix | The prefix of the current element. |
XSubTree | A snapshot of the current element in the document. |
XText | The text of the current element. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
AddAttachment | Adds Filename as an attachment to the PDF. |
Config | Sets or retrieves a configuration setting. |
GetAttr | Returns the value of the specified attribute. |
HasXPath | Determines whether a specific element exists in the document. |
Load | Loads the PDF. |
ParseAttachment | Parses an XML document at the specified index. |
Reset | Reset the class. |
Save | Saves the PDF with one or more attachments. |
Event List
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
Attachment | Fired when an attachment is found. |
Error | Information about errors during data delivery. |
Log | Provides logging information. |
Configuration Settings
The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.
AttachmentParams[index] | Defines file parameters for PDF attachments. |
CloseInputStreamAfterProcessing | Specifies whether or not the InputStream should be closed after processing. |
CloseOutputStreamAfterProcessing | Specifies whether or not the OutputStream should be closed after processing. |
LogLevel | Specifies the level of detail that is logged. |
ZUGFeRDConformanceLevel | Specifies the ZUGFeRD Conformance Level. |
ZUGFeRDMode | Specifies whether ZUGFeRDMode is enabled. |
ZUGFeRDVersion | Specifies the ZUGFeRD version. |
BuildInfo | Information about the product's build. |
CodePage | The system code page used for Unicode to Multibyte translations. |
LicenseInfo | Information about the current license. |
UseInternalSecurityAPI | Tells the class whether or not to use the system security libraries or an internal implementation. |