PDFium Delphi Component Docs

SaveAsPdfR method

Requires Small Business or Enterprise since 3.266.0; link FPdfSmallBusiness and remove any stale Lib\Enterprise\FPdfPdfrEngine.pas during manual upgrades

Component: TPdf  ·  Unit: PDFium
Saves the current document as a PDF/R-1 conformant file (ISO 23504-1:2020, the raster image transport and storage subset of PDF used for scanned documents)

Syntax

function SaveAsPdfR(const FileName: string): Boolean; overload;
function SaveAsPdfR(const FileName: string; const Options: TPdfRSaveOptions): Boolean; overload;

Description

SaveAsPdfR performs the regular SaveAs first, then writes a single complete revision that attaches PDF/R-1 file-format markers. ISO 23504-1 6.7 forbids incremental updates except for digital signatures, so the final cross-reference table lists every live object and carries no /Prev entry. PDF/R-1 (ISO 23504-1:2020) is the strict raster-image transport subset of PDF used by the TWAIN Working Group for scanned document workflows; it carries a fixed-size raster buffer per page, supports bitonal / greyscale / RGB images and FlateDecode / CCITTFaxDecode / DCTDecode compression only

The post-processing injects five classes of bytes into the saved stream:

The output stays byte-identical to the base SaveAs result up to the end of the original PDF; the new objects are appended and the final cross-reference section is rebuilt as one complete table (and the source catalog / Info are replaced with stripped versions via same-object-number rewriting). The two overloads differ only in how the configuration is passed in: the file-name- only form uses TPdfRSaveOptions.Default with auto-population of the four Info fields and DocumentId from FPDF_GetMetaText / FPDF_GetFileIdentifier

An unencrypted source saved under a %PDF-2.0 header has that header rewritten to %PDF-1.7: §6.2.2 admits only %PDF-1.4 through %PDF-1.7 and §6.2.3 reserves 2.0 for an encrypted file, so a 2.0 header cannot survive a conversion into PDF/R. The header line is a fixed eight bytes, so rewriting it in place leaves every recorded object offset valid. An encrypted source is copied through unchanged (it must keep 2.0), and a signed source keeps its bytes untouched because its signature covers the header

Returns True on success

Remarks

Example

// Simple PDF/R-1 output; only meaningful when the source PDF is
// already a raster scan (one image per page, allowed filters only).
if Pdf1.SaveAsPdfR('C:\Scan.pdfr.pdf') then
  ShowMessage('Saved with PDF/R-1 markers');

// Validate to see whether structural rules are also satisfied
Pdf1.FileName := 'C:\Scan.pdfr.pdf';
Pdf1.Active := True;
if Pdf1.ValidatePdfR.IsCompliant then
  ShowMessage('PDF/R-1 conformant');

See Also

SaveAsPdfRToStream, ValidatePdfR, PdfRConformance, SaveAsPdfA, SaveAsPdfX