PDFium Delphi Component Docs

SaveAsPageLabelled method

Component: TPdf  ·  Unit: PDFium
Writes a full PDF copy whose catalog /PageLabels number tree is replaced with the supplied ranges

Syntax

function SaveAsPageLabelled(Stream: TStream;
  const Ranges: TPdfPageLabelRanges;
  ReplaceExisting: Boolean;
  out Report: TPdfPageLabelReport): Boolean; overload;

function SaveAsPageLabelled(const FileName: string;
  const Ranges: TPdfPageLabelRanges;
  ReplaceExisting: Boolean;
  out Report: TPdfPageLabelReport): Boolean; overload;

Description

SaveAsPageLabelled writes a complete PDF copy where the document catalog carries a fresh /PageLabels number tree built from the supplied ranges. The numbering style, prefix text string, and start number of each range follow ISO 32000-1 §12.4.2

Internally PDFium first saves the document to a memory stream; the saved bytes are then rewritten to inject (or replace) the /PageLabels entry in the catalog and append a new cross-reference section. The visible page content is unchanged; only the page label metadata is rewritten

Existing /PageLabels entries are detected via a dictionary scan. When ReplaceExisting=False the call fails with a descriptive error rather than silently overwriting prior labels. When ReplaceExisting=True the prior /PageLabels entry is stripped before the new ranges are injected, so the resulting catalog has exactly one /PageLabels key

Parameters

Remarks

Example

var
  Ranges: TPdfPageLabelRanges;
  Report: TPdfPageLabelReport;
begin
  SetLength(Ranges, 2);
  Ranges[0].StartPageIndex := 0;
  Ranges[0].Style := plsDecimal;
  Ranges[0].StartNumber := 1;
  Ranges[1].StartPageIndex := 3;
  Ranges[1].Style := plsLowercaseRoman;
  Ranges[1].Prefix := 'Appendix ';
  Pdf1.SaveAsPageLabelled('C:\Labelled.pdf', Ranges, False, Report);
end;

See Also

PageLabel, SaveAs, SaveAsReproducible