ConvertToPDFA
PDF/A
Requires the Enterprise edition — in Delphi, C++Builder and Lazarus code create the library as TPDFlibEnterprise (unit PDFlibEnterprise); the Enterprise DLL and ActiveX builds provide it unchanged; other editions keep the method, which returns 0, an empty string or False and sets LastErrorCode to 900 (PDFLIB_ERROR_ENTERPRISE_REQUIRED)
Description
Turns the open document into an archival one and checks the result
Syntax
Delphi
Function TPDFlib.ConvertToPDFA(TargetMode: Integer): Integer; Virtual;ActiveX
Function PDFlib::ConvertToPDFA(TargetMode As Long) As LongDLL
int DLConvertToPDFA(int InstanceID, int TargetMode);Parameters
| TargetMode | The part and level to convert to, using the same numbering as SetPDFAMode |
|---|
Return values
| 1 | The private conversion passed the implemented PDF/A checks and replaced the selected document |
|---|---|
| 0 | It does not, or TargetMode was outside 1 to 11. Read GetPDFAConversionReport for what stands in the way |
Remarks
Conversion runs on a private snapshot and only adopts a successfully written, checked and reopened result; failure preserves the original page content, scripts, fields and existing resource handles
Successful adoption retains the selected document ID, page, origin and measurement scale, but child resource and iterator handles must be reacquired because the document is rebuilt
The pipeline removes document JavaScript, additional actions and forbidden action types, while permitted GoTo and URI navigation actions are retained; embedded files and file attachment annotations forbidden by the target part, and hidden annotations, are removed, form and annotation appearances repaired, and available matching fonts embedded
For PDF/A-1, pages containing reached transparency resources are composited at 300 dpi onto opaque white before transparency is removed, including vector opacity, blend modes, image soft masks and transparency groups; annotation constant opacity also triggers compositing when it cannot remain in the chosen archival form
Composited pages become opaque images including visible annotations and form fields; selectable text and interactivity on those pages are replaced by pixels, and semantic accessibility still requires review; pages without such resources keep their existing content
The report identifies each rasterized page, resolution and loss of text/interactivity; use ConvertToPDFAEx for an explicit resolution and regional fidelity policy; this legacy entry point is equivalent to policy 0 at 300 dpi
PDF/A-1 output uses PDF 1.4 and traditional cross-references, with later page tab/presentation-template entries removed; PDF/A-4 output uses PDF 2.0, missing trailer identifiers are supplied, and absent metadata dates are omitted instead of being emitted as empty date values
Level A targets receive the existing basic structure synthesis where needed; an sRGB output intent is added when absent and the existing bounded device-color reconciliation is attempted, but missing font programs, unsupported resources, arbitrary color-profile repair and human semantic decisions can still block conversion
Reports describe attempted repairs as well as the final commit outcome; a rejected attempt can therefore list a planned removal while the original object remains intact
A successful result establishes the implemented finite checks, with fullCertification=false; it does not certify complete normative coverage or visual fidelity for every possible PDF input
Invalid targets, conversion or validation failures use LastErrorCode 409; an open authoring scope uses the existing scope error, and cancellation or failed compositing leaves the original document selected
Example
PDF.LoadFromFile('invoice.pdf', '');
if PDF.ConvertToPDFA(3) = 1 then // PDF/A-2b
PDF.SaveToFile('invoice-pdfa.pdf')
else
ShowMessage(PDF.GetPDFAConversionReport);See also
GetPDFAConversionReport, SetPDFAMode, RepairDocumentMetadata, CheckFileCompliance