PDFium Delphi Component 文件

可选原生渲染

单元: PDFium
提供以能力门控的 Skia 渲染,以及用于精确专色版与叠印输出的带版本可选 ABI

能力查询

function GetSkiaRenderCapabilities: TPdfSkiaRenderCapabilities;
function GetPrintOutputCapabilities: TPdfPrintOutputCapabilities;

两个查询都会在必要时加载所选的 PDFium 模块,并只报告该确切模块中存在的导出

缺少可选导出绝不会妨碍正常的 PDFium 加载、位图渲染、编辑或保存

TPdfSkiaRenderCapabilities.PageSceneCache 表示 RenderPageSkiaByIndex 可以复用 TPdf 拥有的有界已解析页面缓存

TPdfSkiaRenderCapabilities.FormOverlay 表示单独的可选表单导出可以在页面内容之后绘制表单叠加层

只有当扩展返回确切的 PdfPrintOutputAbiVersion 值时,TPdfPrintOutputCapabilities.VersionCompatible 才为 true

打印输出扩展加载后 TPdfPrintOutputCapabilities.ExtensionPresent 即为 true,且 AbiVersion 携带其报告的原始 ABI 编号

SpotPlateRendering、OverprintDetection 和 OverprintPreview 分别门控 RenderSpotPlate、PageUsesOverprint 和 RenderOverprintPreview

Skia 页面与表单渲染

procedure TPdf.RenderPageSkia(Canvas: FPDF_SKIA_CANVAS; Width, Height: Integer; DrawFormOverlay: Boolean = True);
procedure TPdf.RenderPageSkiaByIndex(Canvas: FPDF_SKIA_CANVAS; PageNumber, Width, Height: Integer; DrawFormOverlay: Boolean = True);

调用方拥有原生 SkCanvas,并将其作为 FPDF_SKIA_CANVAS 传入

RenderPageSkia 绘制活动页,而 RenderPageSkiaByIndex 绘制任意从 1 开始的页面且不改变 PageNumber

在请求且存在表单填充环境时,表单叠加层通过单独的可选表单导出绘制在页面内容之后

原生 Skia API 接受像素尺寸,但不公开位图渲染器的旋转或标志参数

function TPdf.SpotPlates: TPdfSpotPlateInfos;
function TPdf.PageUsesOverprint: Boolean;
function TPdf.RenderSpotPlate(PlateIndex, Width, Height: Integer; Rotation: TRotation = ro0; Options: TRenderOptions = []; Color: TColor = clWhite): TBitmap;
function TPdf.RenderOverprintPreview(Width, Height: Integer; Rotation: TRotation = ro0; Options: TRenderOptions = []; Color: TColor = clWhite): TBitmap;

只有当版本、能力位和相应函数导出全部一致时,这些方法才调用可选的打印输出扩展

返回的位图由调用方持有,并使用与普通渲染相同的有界 PDFium 位图路径

扩展缺失时,每个操作都会抛出 EPdfError,而不是用 RGB 输出模拟色版或声称不准确的叠印行为

打印输出 ABI 版本 1

ExportContract
PDFiumPas_GetPrintOutputAbiVersion以 32 位无符号值返回 PdfPrintOutputAbiVersion
PDFiumPas_GetPrintOutputCapabilities返回声明的专色枚举、专色渲染、叠印检测和叠印预览能力位
PDFiumPas_PageCountSpotPlates为一个 FPDF_PAGE 返回有界的非负色版数量
PDFiumPas_PageGetSpotPlateName返回含结尾零的 UTF-8 字节数,且只在提供的缓冲区内写入
PDFiumPas_PageUsesOverprint为一个页面返回 32 位 FPDF_BOOL
PDFiumPas_RenderSpotPlate把一个从零开始的色版渲染到调用方持有的 FPDF_BITMAP
PDFiumPas_RenderOverprintPreview把色彩管理的叠印预览渲染到调用方持有的 FPDF_BITMAP

所有 ABI 函数使用 cdecl、32 位整数与 FPDF_BOOL 值、指针宽度的句柄,以及 PDFium 持有的页面语义

渲染函数必须同步完成,且不得保留提供的位图或页面句柄

未知能力位保留在 RawCapabilityBits 中,但不被视为受支持的行为

示例

SkiaCaps := GetSkiaRenderCapabilities;
if SkiaCaps.PageRender then
  Pdf.RenderPageSkiaByIndex(SkCanvas, 1, 1200, 1600);

PrintCaps := GetPrintOutputCapabilities;
if PrintCaps.SpotPlateEnumeration then
  Plates := Pdf.SpotPlates;

参见

TPdf.RenderPageByIndex, TPdf.ClearPageSceneCache