/PrintPageRange entry of the document's
/ViewerPreferences dictionary.property PrintPageRanges: TPdfPrintPageRanges; // read only
PDF 1.7 added /PrintPageRange to /ViewerPreferences as a
sequence of integer pairs that describe the page ranges a viewer should pre-select in
its Print dialog (PDF 32000-1 § 12.2 Table 150). PDFium parses that array and
surfaces it through this property as a Pascal dynamic array of
TPdfPrintPageRange records, each holding a StartPage and
EndPage in one-based numbering.
When the document does not include the entry the returned array is empty
(Length(Result) = 0) — treat that as "print all pages". When
a single page is recommended, the corresponding range has equal StartPage
and EndPage values, e.g. (3, 3) for "page 3 only".
Pair the result with PrintCopies, PrintScaling and PrintPaperHandling when wiring a print dialog so all four hints can be displayed to the user. Like the other print preferences this is advisory only; PDFium does not enforce the range during rendering.
// Build a comma-separated string like "1-3, 7, 10-12".
var Ranges: TPdfPrintPageRanges;
var S: string;
var I: Integer;
begin
Ranges := Pdf1.PrintPageRanges;
if Length(Ranges) = 0 then Exit;
for I := 0 to High(Ranges) do
begin
if S <> '' then S := S + ', ';
if Ranges[I].StartPage = Ranges[I].EndPage then
S := S + IntToStr(Ranges[I].StartPage)
else
S := S + Format('%d-%d', [Ranges[I].StartPage, Ranges[I].EndPage]);
end;
editRanges.Text := S;
end;