PLExecuteVCRDataMerge
Compliance, variable content, document editing
Requires the Small Business edition — declared in the Small Business unit PDFlibSBDataMerge, which the Single edition does not include; the Enterprise edition includes it
Description
Merges field values into the marked-content placeholders of an ISO 16613-1 (PDF/VCR-1) template read from InputStream and writes the merged document to OutputStream. The output starts with the unchanged bytes of the template; when at least one placeholder was replaced, an incremental update carrying the rewritten content streams is appended
The function is the stream-based merge behind the TPDFlib.ExecuteVCRDataMerge* methods: ExecuteVCRDataMerge, ExecuteVCRDataMergeCurrent and ExecuteVCRDataMergeBatch each call it for one template and one set of values, and ExecuteVCRDataMergeEx is the DLL and ActiveX form of the first. It needs the Small Business edition or the Enterprise edition and is declared in the Small Business unit PDFlibSBDataMerge
The function returns no error code; callers that need LastErrorCode use the methods
Syntax
Delphi
Function PLExecuteVCRDataMerge(InputStream: TStream;
Const Password, FieldValues: WideString;
OutputStream: TStream; RequireAll: Boolean = False): Boolean;Parameters
| InputStream | The PDF/VCR template to read, as a seekable stream. Set its position to 0 before the call, as the library's own callers do. The function does not take ownership and does not close the stream. The template has to open with Password and pass the PDF/VCR structure validation |
|---|---|
| Password | The password that opens the template, or an empty string for a document that is not encrypted; a wrong password makes the function return False |
| FieldValues | The replacement values as Name=Value lines separated by semicolons or line breaks, or as a JSON object whose values are scalars (a string, number, boolean or null). Names are case-sensitive and a later duplicate replaces the earlier value; null is an explicit empty value. An empty string supplies no values |
| OutputStream | Receives the merged document. On success the stream is truncated and rewritten with the complete template followed by the incremental update, so earlier content is lost. The function does not take ownership and does not close the stream |
| RequireAll | True requires every placeholder of the template to receive a value and to be updated; the first placeholder without a value, on a page that cannot be resolved, or whose text cannot be replaced makes the function return False. The default False leaves such placeholders unchanged and still returns True |
Return values
| True | The template was accepted and the merge finished: OutputStream holds the template, followed by an incremental update when at least one placeholder was replaced |
|---|---|
| False | The merge was rejected and nothing was written to OutputStream. Reasons: a stream is Nil, the template cannot be opened with Password, it fails the PDF/VCR structure validation, FieldValues starts with a brace but is not a JSON object with scalar values, a value cannot be encoded with the font in effect at its placeholder, a content stream that would be rewritten is also drawn by another page, or RequireAll is True and a placeholder was not updated |
Remarks
Each value replaces the text inside the marked-content sequence of its placeholder and is encoded with the font selected at the replaced text operand; a character that this font cannot show rejects the whole merge. When the page content is an array of streams, the streams are tried in order; a marked-content span that crosses the boundary between two streams is replaced in the concatenated content, which is written into the first member while the other members are emptied. Because that moves content between streams, such a page is rejected when another page draws any of these streams, and a single content stream shared with another page is rejected as well
The function has no exception handler: an exception raised by a stream or by the parser propagates to the caller after the temporary objects were freed. The TPDFlib.ExecuteVCRDataMerge method catches such failures and sets LastErrorCode to 608 (PDFLIB_ERROR_PDFVCR_COMPLIANCE) for a rejected merge and to 401 for any other error
While it runs, the function installs a validation context for the calling thread; the context is removed again before the function returns. ExecuteVCRDataMergeBatch calls the function with RequireAll set to True and writes through a bounded stream that caps the size of each record
Example
Template:= TFileStream.Create('template.pdf', fmOpenRead or fmShareDenyWrite);
Try
Merged:= TMemoryStream.Create;
Try
If PLExecuteVCRDataMerge(Template, '', 'Customer=Alice Smith;Amount=45.00', Merged) Then
Merged.SaveToFile('merged.pdf');
Finally
Merged.Free;
End;
Finally
Template.Free;
End;See also
ExecuteVCRDataMerge, ExecuteVCRDataMergeCurrent, ExecuteVCRDataMergeBatch, ExecuteVCRDataMergeEx, GetPDFVCRManifest