/ViewerPreferences 字典中的 /PrintPageRange 項目property PrintPageRanges: TPdfPrintPageRanges; // read only
PDF 1.7 在 /ViewerPreferences 中加入了 /PrintPageRange,以一串整數對描述檢視器應在其列印對話框中預先選取的頁面範圍(PDF 32000-1 § 12.2 Table 150)。PDFium 會解析該陣列,並透過此屬性以 TPdfPrintPageRange 記錄的 Pascal 動態陣列形式公開,每筆記錄各持有以 1 為基底的 StartPage 與 EndPage
當文件不含此項目時,傳回的陣列為空(Length(Result) = 0)— 請將其視為「列印全部頁面」。當只建議單一頁面時,對應範圍的 StartPage 與 EndPage 值會相等,例如「只列印第 3 頁」為 (3, 3)
在組裝列印對話框時,可將結果與 PrintCopies、PrintScaling 與 PrintPaperHandling 搭配,讓全部四個提示都能顯示給使用者。與其他列印偏好一樣,這只是建議性質;PDFium 在算繪時不會強制套用該範圍
// 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;