Technical Article

PDF/X Validation in Delphi with the PDFium Component

A one-page flyer with a Helvetica headline looks perfect in every viewer on the designer's desk, because each viewer quietly substitutes a system font for Helvetica. The print service provider's RIP gets no such latitude. Every part of ISO 15930 requires every font program used on the page to travel inside the file, and the standard 14 base fonts are not exempt, so the flyer comes back with "font not embedded" for a font nobody on the design side ever saw missing. Checks like that one, along with the page boxes, the trapping declaration and the output intent, can run inside your own Delphi application before the upload button is pressed

What a PDF/X file has to prove to a printer it has never met

PDF/X exists for blind exchange: a designer sends a file to a printer they have never spoken to, and the printer produces correct output without a phone call about missing fonts or a linked image that stayed behind on someone's laptop. Fonts must be embedded because the receiving RIP cannot be assumed to own them. External references are banned because the file has to be complete in itself. Interactive features are banned because ink has no click handler

PDFium Component reports which part a file claims through the TPdfXConformance enum. pxc1a is PDF/X-1a:2001 (ISO 15930-1), the strict CMYK-plus-spot exchange on a PDF 1.3/1.4 base. pxc3 is PDF/X-3:2002 (ISO 15930-3), which admits RGB, Lab and ICC-based color tied to the output intent. pxc4 is PDF/X-4:2010 (ISO 15930-7), which allows live transparency and layers on PDF 1.6. pxc6 is PDF/X-6 (ISO 15930-9), built on PDF 2.0. A file with no PDF/X identification at all comes back as pxcNone, and pxcUnknown is what you get when no document is loaded

Identification itself is a small bundle of markers that have to agree with each other. The XMP packet carries pdfxid:GTS_PDFXVersion together with the extension schema description and xmp:CreateDate / xmp:ModifyDate; the Info dictionary repeats /GTS_PDFXVersion, and the two strings must match. The catalog's /OutputIntents entry names the printing condition the file was prepared for, with /S /GTS_PDFX, an /OutputConditionIdentifier and, for a complete exchange, an embedded ICC profile in /DestOutputProfile. The trailer needs an /ID, and encryption is ruled out entirely. Each of these maps to its own value in TPdfXValidationIssue, from pvxiMissingPdfXIdentifier through pvxiInfoVersionMismatch, pvxiOutputIntentMissingIdentifier and pvxiEncryptionPresent

Running TPdf.ValidatePdfX as a print gate

TPdf.ValidatePdfX takes no arguments and returns a TPdfXValidationResult record with two fields, Conformance and Issues (a Pascal set of TPdfXValidationIssue), plus an IsCompliant method. PDF/X validation belongs to the Enterprise edition: add FPdfEnterprise to a uses clause, with Lib\Enterprise and Lib\SmallBusiness on the search path, so the validator is linked into your executable. Without that unit the call raises EPdfEnterpriseRequired, which is easy to spot on the first test run

IsCompliant is strict on purpose. It returns True only when Conformance is one of pxc1a, pxc3, pxc4 or pxc6 and the issue set is empty, and that includes pvxiMissingTitle. The standard words the Title as a recommendation, while most of the other checks are hard requirements. Bouncing a customer's job because the Info dictionary has no /Title is the kind of rejection that makes people stop trusting the gate, so split the set and keep the advisory items out of the pass/fail decision:

uses
  PDFium, FPdfPdfx,
  FPdfEnterprise; // links the PDF/X validator (Enterprise edition)

const
  // Your own policy: issues reported to the user but not blocking the upload
  AdvisoryIssues: TPdfXValidationIssues = [pvxiMissingTitle];

function PrintGate(const FileName: string;
  out Blocking, Advisory: TPdfXValidationIssues): Boolean;
var
  Pdf: TPdf;
  Res: TPdfXValidationResult;
begin
  Pdf := TPdf.Create(nil);
  try
    Pdf.FileName := FileName;
    Pdf.Active := True;

    Res := Pdf.ValidatePdfX;
    Advisory := Res.Issues * AdvisoryIssues;
    Blocking := Res.Issues - AdvisoryIssues;

    // Same conformance test IsCompliant uses, minus the advisory items
    Result := (Res.Conformance in [pxc1a, pxc3, pxc4, pxc6]) and
      (Blocking = []);
  finally
    Pdf.Free;
  end;
end;

A file that never claimed to be PDF/X fails this gate with a long issue list: no XMP metadata, no identifier, no output intent, no Info version entry. That list is still worth showing, because it reads as a to-do list for whoever has to export the file again. One more property of ValidatePdfX matters in an editing application: it checks the document as the component would save it right now, so pages you added or metadata you changed after loading are part of what gets validated

Why do print shops reject PDFs without a TrimBox?

The TrimBox is the finished page, the rectangle left after the guillotine cuts. The MediaBox that every PDF page carries is only the sheet: it holds the bleed, crop marks, registration targets and color bars. Imposition software places pages on a press sheet by their TrimBoxes, and without one the operator has to guess where your business card ends. A wrong guess trims away the bleed or leaves a white sliver along one edge

PDFium Component diagram of a print-ready PDF page showing the MediaBox sheet with bleed, crop marks, color bars and registration marks around the TrimBox rectangle that imposition software reads, with pvxiMissingTrimBox raised when the key is absent
The MediaBox is the full sheet with bleed, crop marks and color bars, while the TrimBox is the finished page the guillotine must find, and the box a PDF/X producer should write on every page

ValidatePdfX runs three geometry checks. pvxiMissingTrimBox fires when no /TrimBox key appears anywhere in the file. pvxiTrimBoxWithArtBox fires when a page carries /TrimBox and /ArtBox together. pvxiPageBoxOutsideMediaBox fires when a /TrimBox or /BleedBox reaches past the /MediaBox, which describes an area the press cannot image. Rectangles may list their corners in either order, so both are normalized before comparison

The box checks read rectangles written directly in each page dictionary. Boxes inherited from a /Pages node or stored as indirect references are left out of the containment test, so a file built that way is judged on the presence of its TrimBox alone. If your own producer writes boxes, write them directly on every page so each one gets the full containment test

The /Trapped key in the Info dictionary answers a different production question. Trapping slightly overlaps adjacent colors so that press misregistration does not open white gaps between them, and the printer needs to know whether that has been done already: trapping an already-trapped file doubles the overlaps, while skipping it on an untrapped file risks visible gaps. PDF/X therefore wants /Trapped /True or /Trapped /False. A missing key or /Unknown forces a human to open the file, and the component reports it as pvxiTrappedNotSet

Structural prohibitions, and which part they apply to

The structural layer of ValidatePdfX inspects the file's dictionaries rather than rendering anything, and stream contents are kept out of the scan. A JPEG whose compressed data happens to contain the bytes /JavaScript cannot produce a false hit. ValidatePdfX runs these checks whatever part the file claims:

  • pvxiLzwForbidden: a /LZWDecode filter appears anywhere; Flate does the same job and is what a re-export should use
  • pvxiJavaScriptForbidden: a /JavaScript action or name tree is present
  • pvxiFormFieldsForbidden: an /AcroForm dictionary or an /XFA entry exists
  • pvxiAdditionalActions: an /AA additional-actions dictionary is present
  • pvxiEmbeddedFilesForbidden: /EmbeddedFiles or a /FileAttachment annotation is present
  • pvxiOpiForbidden: an /OPI or /Alternates entry points at replaceable image content stored somewhere else

Two further checks depend on the part the file claims, and ValidatePdfX gates them on the detected Conformance. pvxiTransparencyForbidden applies to PDF/X-1a and PDF/X-3 only, where a transparency group or an active soft mask is not allowed; PDF/X-4 and PDF/X-6 files may keep live transparency, so the same objects there raise nothing. pvxiColorSpaceForbidden applies to PDF/X-1a alone and fires on /DeviceRGB, /CalRGB or /Lab, because X-1a is a CMYK-and-spot exchange and the device-independent spaces arrive with X-3. A file whose part could not be identified is never flagged for a rule that might not apply to it

PDF/X-1a also gets a closer look at its output profile. The embedded /DestOutputProfile has to be an ICC version 2 output (prtr) profile with a CMYK data space and the lookup tables a RIP needs for color conversion, and the stream's /N must be 4. An sRGB profile pasted in by a generic PDF writer, or a damaged profile, produces pvxiInvalidOutputProfile. The writer side applies the same test: SaveAsPdfX with Conformance set to pxc1a raises EArgumentException when IccProfileData is not a usable ICC v2 CMYK output profile, instead of writing a file the validator would reject a minute later

Diagram of TPdf.ValidatePdfX in the PDFium Component for Delphi running a byte-level token scan with marker, content and page geometry checks and a PDFium object-model font embedding pass, merging into one TPdfXValidationResult record
ValidatePdfX fans one loaded document through the byte-level content checks and the PDFium object-model font pass, then merges both layers into a single typed result record

Font embedding, checked twice

Fonts get two checks because a byte scan can answer only part of the question. The structural layer raises pvxiFontNotEmbedded when the file uses fonts but carries no /FontFile, /FontFile2 or /FontFile3 program at all. That rule is deliberately conservative: counting font descriptors against font programs looks precise but misfires on files where several fonts share one descriptor. The cost is that a document with nine fonts embedded and one system font slipped in passes the byte scan

The second layer closes that gap through the PDFium object model. TPdf.ValidatePdfX loads each page, walks its objects with FPDFPage_CountObjects and FPDFPage_GetObject, resolves every text object's font with FPDFTextObj_GetFont, and asks FPDFFont_GetIsEmbedded. One font that is not embedded adds pvxiPdfiumFontNotEmbedded and ends the walk, so on a 300-page catalog that fails on its cover the answer comes back after page one. This layer needs the PDFium library loaded and a build that exports FPDFFont_GetIsEmbedded; with a library that lacks the export, the layer is skipped and the byte-level verdict stands on its own

Both checks answer "embedded or not". When a customer asks which font on which page caused the rejection, the enumeration code in analyzing PDF font properties with PDFium in Delphi picks up where the validator's verdict stops. A short helper that turns each blocking issue into a sentence a designer understands goes a long way in the meantime:

// Your own helper: customer-facing text for the issues that block a job
function PdfXIssueText(Issue: TPdfXValidationIssue): string;
begin
  case Issue of
    pvxiMissingTrimBox:
      Result := 'No TrimBox: the finished page size is not defined';
    pvxiTrimBoxWithArtBox:
      Result := 'A page defines both TrimBox and ArtBox';
    pvxiPageBoxOutsideMediaBox:
      Result := 'TrimBox or BleedBox extends past the sheet';
    pvxiTrappedNotSet:
      Result := 'Trapped must be set to True or False';
    pvxiFontNotEmbedded, pvxiPdfiumFontNotEmbedded:
      Result := 'At least one font is not embedded';
    pvxiTransparencyForbidden:
      Result := 'Live transparency is not allowed in PDF/X-1a or PDF/X-3';
    pvxiColorSpaceForbidden:
      Result := 'RGB or Lab color is not allowed in PDF/X-1a';
    pvxiInvalidOutputProfile:
      Result := 'The output intent needs a CMYK printer profile';
  else
    Result := 'PDF/X requirement not met';
  end;
end;

procedure ReportBlocking(const Blocking: TPdfXValidationIssues);
var
  Issue: TPdfXValidationIssue;
begin
  for Issue in Blocking do
    Writeln('REJECT: ', PdfXIssueText(Issue));
end;

Checking the file on disk without the PDFium DLL

The structural layer is also available on its own as ValidatePdfXCompliance(Source: TStream), declared in the FPdfPdfx unit and implemented in FPdfPdfxEngine. It is plain Object Pascal with no dependency on the PDFium library, so it fits where a rendering engine is unwelcome: an upload handler on a web server, a CI step that vets generated artwork, or a Lazarus service on a platform where you would rather not ship native binaries. It reads the stream exactly as given, which makes it the right tool when the question is "what will the printer receive?" rather than "what would this document look like if saved again?"

uses
  Classes, FPdfPdfx,
  FPdfPdfxEngine; // byte-level PDF/X engine only, no PDFium library needed

function QuickPdfXGate(const FileName: string): Boolean;
var
  Fs: TFileStream;
  Res: TPdfXValidationResult;
begin
  Fs := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
  try
    Res := ValidatePdfXCompliance(Fs);
    // IsCompliant already rejects pxcNone and pxcUnknown
    Result := Res.IsCompliant;
  finally
    Fs.Free;
  end;
end;

The stream needs to be seekable, since the validator reads the cross-reference data from the end of the file. Compressed object streams and cross-reference streams, the usual layout of a PDF/X-4 file, are read like any other structure. On this path the font verdict is the byte-level one only, because the per-text-object check needs the PDFium object model. Run ValidatePdfXCompliance as the cheap first gate on every upload and reserve the full TPdf.ValidatePdfX for files that pass it; rejected files never cost a page load

Where the gate stops and certification starts

ValidatePdfX covers identification markers, the output intent and its profile, structural prohibitions, part-specific transparency and color rules, page geometry, the trapping declaration and font embedding down to individual text objects. Ink coverage limits, image resolution and spot color naming belong to a color-managed preflight engine, the tool a print house uses when it certifies a job. The value of the in-application gate is timing: every structural rejection described above shows up while the customer is still at the upload screen. The same TPdfXValidationResult also feeds the component's report generator, and building a batch preflight report CLI with the PDFium Component shows that pattern applied across a folder of files. PDF/X shares much of its machinery with archival PDF/A, from XMP identification to output intents, and the archival side is covered in PDF/A preflight validation with the PDFium Component

The PDF/X validators, the matching SaveAsPdfX writer for producing compliant output, and the PDF/A, PDF/UA, PDF/E and PDF/VT checks built the same way are part of the Enterprise edition of the PDFium Component for Delphi, C++Builder and Lazarus, so a print portal can check what it accepts with the same library it uses to render previews