Codeunit "PDF Document"
Codeunit that provides helper functions for PDF processing.
Properties
| Name | Value |
|---|---|
| Access | Public |
| InherentEntitlements | X |
| InherentPermissions | X |
Methods
Initialize
This procedure initializes the internal state of the object by resetting attachment lists and clearing user and admin codes, as well as any additional document names.
procedure Initialize()
Load
This procedure is used to load a PDF document from a stream.
procedure Load(DocumentStream: InStream): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| DocumentStream | InStream |
Stream of the PDF document. |
Returns
| Type | Description |
|---|---|
| Boolean |
Returns true if the document is loaded successfully, otherwise false. |
ConvertPdfToImage
This procedure is used to convert a PDF file to an image.
procedure ConvertPdfToImage(var ImageStream: InStream, ImageFormat: Enum "Image Format", PageNumber: Integer): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| ImageStream | InStream |
Stream of the image file. |
| ImageFormat | Enum System.Utilities."Image Format" |
Image format to convert the PDF to. |
| PageNumber | Integer |
Page number to convert. |
Returns
| Type | Description |
|---|---|
| Boolean |
Whether or not the conversion was successful. |
ConvertToImage
Obsolete
This element will become obsolete from version 27.2. Use the ConvertPdfToImage procedure instead.
This procedure is used to convert a PDF file to an image.
[Obsolete(Use the ConvertPdfToImage procedure instead.,27.2)]
procedure ConvertToImage(var ImageStream: InStream, ImageFormat: Enum "Image Format", PageNumber: Integer)
Parameters
| Name | Type | Description |
|---|---|---|
| ImageStream | InStream |
Stream of the image file. |
| ImageFormat | Enum System.Utilities."Image Format" |
Image format to convert the PDF to. |
| PageNumber | Integer |
Page number to convert. |
GetDocumentAttachmentStream
This procedure is used to get the invoice attachment stream from a PDF file.
procedure GetDocumentAttachmentStream(PdfStream: InStream, var TempBlob: Codeunit "Temp Blob"): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| PdfStream | InStream |
Input stream of the PDF file. |
| TempBlob | Codeunit System.Utilities."Temp Blob" |
Temporary blob to store the attachment. |
Returns
| Type | Description |
|---|---|
| Boolean |
GetPdfProperties
Retrieves metadata properties from a PDF file, such as page size, author, title, and creation date.
procedure GetPdfProperties(DocumentInStream: InStream): JsonObject
Parameters
| Name | Type | Description |
|---|---|---|
| DocumentInStream | InStream |
Input stream of the PDF file. |
Returns
| Type | Description |
|---|---|
| JsonObject |
A JSON object containing the extracted PDF metadata. |
Remarks
The format of the returned JSON object looks like the following: { "pageWidth": 210.0, "pageHeight": 297.0, "pagecount": 3, "author": "Author Name", "creationDate": "2025-06-04T10:00:00", "creationTimeZone": "PT2H", "creator": "PDF Generator", "producer": "PDF Engine", "subject": "Invoice Document", "title": "Invoice #12345" }
GetPdfPageCount
Returns the number of pages in the provided PDF stream.
procedure GetPdfPageCount(DocumentInStream: InStream): Integer
Parameters
| Name | Type | Description |
|---|---|---|
| DocumentInStream | InStream |
Input stream of the PDF file. |
Returns
| Type | Description |
|---|---|
| Integer |
The number of pages in the PDF document. |
GetZipArchive
Initiates a download of a ZIP archive containing all embedded attachments from the provided PDF stream.
procedure GetZipArchive(PdfStream: InStream)
Parameters
| Name | Type | Description |
|---|---|---|
| PdfStream | InStream |
Input stream of the PDF file. |
Remarks
This procedure does not return the ZIP archive directly. Instead, it triggers a download dialog for the user, allowing them to save the ZIP file locally.
GetAttachmentNames
Retrieves the names of embedded file attachments from a PDF document.
procedure GetAttachmentNames(PdfStream: InStream): List of [Text]
Parameters
| Name | Type | Description |
|---|---|---|
| PdfStream | InStream |
The input stream representing the PDF file to inspect. |
Returns
| Type | Description |
|---|---|
| List of [Text] |
A list of strings containing the name of all embedded attachments found in the PDF. If no attachments are found, an empty list is returned. |
Remarks
This procedure is particularly useful for PDF/A-3 compliant documents that embed XML-based e-invoices, such as Factur-X, XRechnung, or ZUGFeRD formats. These formats typically include attachments like 'factur-x.xml', 'xrechnung.xml', or 'zugferd-invoice.xml' which are used for automated invoice processing.
AddAttachment
Configure the attachment lists. An empty name will reset the list. This procedure adds a new attachment to the PDF document with the specified metadata and relationship type.
procedure AddAttachment(AttachmentName: Text, PDFAttachmentDataType: Enum "PDF Attach. Data Relationship", MimeType: Text, FileName: Text, Description: Text, PrimaryDocument: Boolean)
Parameters
| Name | Type | Description |
|---|---|---|
| AttachmentName | Text |
Attachment name. If empty, the list will be reset. |
| PDFAttachmentDataType | Enum System.IO."PDF Attach. Data Relationship" |
Defines the relationship of the attachment to the PDF (e.g. supplementary, source, data, alternative). |
| MimeType | Text |
MIME type of the attachment (e.g., application/pdf, image/png). |
| FileName | Text |
The file name of the attachment as it should appear in the PDF. |
| Description | Text |
A textual description of the attachment. |
| PrimaryDocument | Boolean |
Indicates whether this attachment is the primary document. |
AddAttachment
Configure the attachment lists. An empty name will reset the list. This procedure adds a new attachment to the PDF document with the specified metadata and relationship type.
procedure AddAttachment(AttachmentName: Text, PDFAttachmentDataType: Enum "PDF Attach. Data Relationship", MimeType: Text, FileInStream: InStream, Description: Text, PrimaryDocument: Boolean)
Parameters
| Name | Type | Description |
|---|---|---|
| AttachmentName | Text |
Attachment name. If empty, the list will be reset. |
| PDFAttachmentDataType | Enum System.IO."PDF Attach. Data Relationship" |
Defines the relationship of the attachment to the PDF (e.g. supplementary, source, data, alternative). |
| MimeType | Text |
MIME type of the attachment (e.g., application/pdf, image/png). |
| FileInStream | InStream |
The stream with content to attach in the PDF. |
| Description | Text |
A textual description of the attachment. |
| PrimaryDocument | Boolean |
Indicates whether this attachment is the primary document. |
AddStreamToAppend
Add a stream to the list of files to append to the rendered document using a temporary file name.
procedure AddStreamToAppend(FileInStream: InStream)
Parameters
| Name | Type | Description |
|---|---|---|
| FileInStream | InStream |
Stream with file content. Platform will remove the temporary file when rendering has been completed. |
ProtectDocument
Protect the document with a user and admin code using text data type.
[NonDebuggable]
procedure ProtectDocument(User: Text, Admin: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| User | Text |
User code. |
| Admin | Text |
Admin code. |
ProtectDocument
Protect the document with a user and admin code using secrettext data type.
procedure ProtectDocument(User: SecretText, Admin: SecretText)
Parameters
| Name | Type | Description |
|---|---|---|
| User | SecretText |
User code. |
| Admin | SecretText |
Admin code. |
AttachmentCount
Returns the number of configured attachments. Validates that all attachment-related lists (names, MIME types, data types, filenames, and descriptions) are synchronized in length. Throws an error if any of the lists are out of sync.
procedure AttachmentCount(): Integer
Returns
| Type | Description |
|---|---|
| Integer |
The total number of attachments configured. |
AppendedDocumentCount
Returns the number of additional document names that have been appended. This count reflects how many supplementary documents are currently tracked.
procedure AppendedDocumentCount(): Integer
Returns
| Type | Description |
|---|---|
| Integer |
The total number of additional document names. |
ToJson
Converts the internal state of the PDF document configuration into a structured JSON payload. This includes metadata such as version, primary document, attachments, additional documents, and protection settings.
[NonDebuggable]
procedure ToJson(RenderingPayload: JsonObject): JsonObject
Parameters
| Name | Type | Description |
|---|---|---|
| RenderingPayload | JsonObject |
The base JSON object to which the PDF configuration will be applied. |
Returns
| Type | Description |
|---|---|
| JsonObject |
A JsonObject representing the complete rendering payload with all configured properties. |
Remarks
Throws an error if the payload already contains a primary document or protection block, as these cannot be overwritten.