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

When XPath is set to a valid path, XElement points to the name of the element, with XParent, XNamespace, XPrefix, XChildren , and XText providing other properties of the element. The attributes of the current element are provided in the XAttributes collection.

BuildDOM must be set to True prior to parsing the document for the XPath functionality to be available.

Example (Setting XPath):

Document rootXML.XPath = "/"
Specific ElementXML.XPath = "/root/SubElement1/SubElement2/"
i-th ChildXML.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.

AttachmentsCollection of files attached to the current PDF.
InputDataThe input PDF data.
InputFileThe input PDF file to process.
OutputDataThe output PDF data.
OutputFileThe output file.
OverwriteIndicates whether or not the class should overwrite files.
XAttributesA collection of attributes of the current element.
XChildrenCollection of child elements of the currently selected XML element.
XCommentsA collection of comments of the current element.
XElementThe name of the current element.
XMLDeclarationSpecifies details of the XML declaration.
XNamespaceThe namespace of the current element.
XParentThe parent of the current element.
XPathProvides a way to point to a specific element in the document.
XPrefixThe prefix of the current element.
XSubTreeA snapshot of the current element in the document.
XTextThe 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.

AddAttachmentAdds Filename as an attachment to the PDF.
ConfigSets or retrieves a configuration setting.
GetAttrReturns the value of the specified attribute.
HasXPathDetermines whether a specific element exists in the document.
LoadLoads the PDF.
ParseAttachmentParses an XML document at the specified index.
ResetReset the class.
SaveSaves the PDF with one or more attachments.
SetInputStreamSets the stream from which the class will read the data.
SetOutputStreamAn output stream to write the PDF data to.

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.

AttachmentFired when an attachment is found.
ErrorInformation about errors during data delivery.
LogProvides 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.
CloseInputStreamAfterProcessingSpecifies whether or not the InputStream should be closed after processing.
CloseOutputStreamAfterProcessingSpecifies whether or not the OutputStream should be closed after processing.
LogLevelSpecifies the level of detail that is logged.
ZUGFeRDConformanceLevelSpecifies the ZUGFeRD Conformance Level.
ZUGFeRDModeSpecifies whether ZUGFeRDMode is enabled.
ZUGFeRDVersionSpecifies the ZUGFeRD version.
BuildInfoInformation about the product's build.
GUIAvailableTells the class whether or not a message loop is available for processing events.
LicenseInfoInformation about the current license.
UseDaemonThreadsWhether threads created by the class are daemon threads.
UseInternalSecurityAPITells the class whether or not to use the system security libraries or an internal implementation.

Copyright (c) 2021 /n software inc. - All rights reserved.
IPWorks EDI 2020 Java Edition - Version 20.0 [Build 7941]