Security change on December 1, 2026: TLS 1.2 will become the minimum standard for 365 business Print Agent. Details and system requirements
365 business development
365 business PDF

Pdf - Concatenate

Codeunit 5523674 bdev.Pdf - Concatenate merges PDF documents into a single one. Two of its overloads work on Temp Blob codeunits, the other two on a list of Base64 encoded documents - which is what you want when more than two documents are involved, because the order of the list is the order of the result.

All four overloads can produce several copies of the merged document in one go.

Code
pdfConcatenate: Codeunit "bdev.Pdf - Concatenate";

ConcatenateDocument(Codeunit, Codeunit)

Appends a second document to a document.

Code
procedure ConcatenateDocument(var document: Codeunit "Temp Blob"; document2: Codeunit "Temp Blob")
ParameterTypeDescription
documentCodeunit "Temp Blob"The base document. It is replaced by the merged result.
document2Codeunit "Temp Blob"The document to append.

Identical documents are merged only once

Both overloads that take two Temp Blob codeunits compare the two documents and drop the second one when it is byte-identical to the first. Appending a document to itself - to print a copy, for example - therefore does nothing. Use the copies parameter for that.

Example

Code
procedure AppendTermsAndConditions(var document: Codeunit "Temp Blob") var mySetup: Record "My Setup"; pdfConcatenate: Codeunit "bdev.Pdf - Concatenate"; termsAndConditions: Codeunit "Temp Blob"; begin mySetup.Get(); termsAndConditions.FromRecord(mySetup, mySetup.FieldNo("Terms and Conditions")); pdfConcatenate.ConcatenateDocument(document, termsAndConditions); end;

ConcatenateDocument(Codeunit, Codeunit, Integer, Boolean)

Appends a second document to a document and produces the given number of copies.

Code
procedure ConcatenateDocument(var document: Codeunit "Temp Blob"; document2: Codeunit "Temp Blob"; copies: Integer; grouped: Boolean)
ParameterTypeDescription
documentCodeunit "Temp Blob"The base document. It is replaced by the merged result.
document2Codeunit "Temp Blob"The document to append.
copiesIntegerThe number of copies of the merged document. 0 means no copy handling at all, the documents are merged once.
groupedBooleanThe copy order, see Copies and copy order.

ConcatenateDocument(List of [Text])

Merges a list of Base64 encoded PDF documents into one, in the order of the list.

Code
procedure ConcatenateDocument(documents: List of [Text]): Codeunit "Temp Blob"
ParameterTypeDescription
documentsList of [Text]The Base64 encoded PDF documents.

Returns the merged document as a Temp Blob codeunit.

Unlike the overloads above, the list is merged as it is - identical entries are kept and appear in the result as often as they are listed.

Example

Code
procedure MergeDocuments(var document: Codeunit "Temp Blob"; var attachment: Record "My Attachment"): Codeunit "Temp Blob" var convertBase64: Codeunit "Base64 Convert"; pdfConcatenate: Codeunit "bdev.Pdf - Concatenate"; documents: List of [Text]; stream: InStream; begin documents.Add(convertBase64.ToBase64(document.CreateInStream())); if (attachment.FindSet(false)) then repeat attachment.CalcFields(Content); attachment.Content.CreateInStream(stream); documents.Add(convertBase64.ToBase64(stream)); until attachment.Next() = 0; exit(pdfConcatenate.ConcatenateDocument(documents)); end;

ConcatenateDocument(List of [Text], Integer, Boolean)

Merges a list of Base64 encoded PDF documents into one and produces the given number of copies.

Code
procedure ConcatenateDocument(documents: List of [Text]; copies: Integer; grouped: Boolean): Codeunit "Temp Blob"
ParameterTypeDescription
documentsList of [Text]The Base64 encoded PDF documents.
copiesIntegerThe number of copies of the merged document. 0 means no copy handling at all.
groupedBooleanThe copy order, see Copies and copy order.

Returns the merged document as a Temp Blob codeunit.

Copies and copy order

copies is the number of copies of the merged document, produced by the PDF service rather than by the printer. grouped decides in which order they end up in the result. For a merge of the documents A and B with three copies:

groupedCopy orderResult
trueGroupedA A A B B B
falseCollatedA B A B A B

Collated is what a user expects when the result is stapled as a set - each copy is a complete document. Grouped is what you want when the copies are separated by document afterwards.

Collated is the default of the PDF service: the copy order is only sent when grouped is true. A copies value of 0 suppresses the copy handling altogether and leaves the merge as it is.

See also

Last modified on