PDFiumPas 文件

SaveAs 方法

组件: TPdf  ·  单元: PDFium
将 PDF 文档副本保存到指定流中。若 PdfVersion 为 pv13 到 pv17,保存输出会针对目标版本进行规范化与校验,包括增量输出中已有的 catalog /Version 覆盖。校验器覆盖 PDF 1.1 到 1.7 / ISO 32000-1 的完整特性时间线:过滤器(FlateDecode、JBIG2Decode、JPXDecode)、对象流与 xref 流、透明度(SMask、ca/CA、混合模式)、Tagged PDF(StructTreeRoot、MarkInfo)、颜色空间(ICCBased、DeviceN)、页面框(BleedBox/TrimBox/ArtBox)、输出意图、可选内容、AcroForm、CID/Type 0 和 OpenType 字体、AES 与 AES-256 加密(CFM AESV2/AESV3)、所有受版本限制的注释子类型(Widget、Sound、Movie、FreeText、Line、Square、Circle、Highlight、Underline、StrikeOut、Stamp、Ink、Popup、FileAttachment、TrapNet、Squiggly、PrinterMark、Polygon、PolyLine、Caret、Screen、Watermark、3D、Redact)、受版本限制的动作类型(SubmitForm、ResetForm、ImportData、Hide、Named、JavaScript、Trans、SetState、Rendition、GoToE、GoTo3DView)以及 catalog 条目(Perms、Legal、Collection、Requirements、NeedsRendering)。任何超出所选目标版本的内容都会抛出 EPdfError。若文档没有现成的 OpenAction 且目标版本支持它,已保存的 PDF 会以适合高度缩放在第一页打开。试用版会在保存时应用试用水印

Syntax

function SaveAs(Stream: TStream; Option: TSaveOption = saNone; PdfVersion: TPdfVersion = pvUnknown): Boolean;

StreamTStream value that receives the PDF data
OptionTSaveOption. Save option: saNone for a normal save, saIncremental for an incremental update, saNoIncremental to force a full rewrite, or saRemoveSecurity to remove security while saving
PdfVersionTPdfVersion target; use pvUnknown to preserve the current version

 

function SaveAs(const FileName: string; Option: TSaveOption = saNone; PdfVersion: TPdfVersion = pvUnknown): Boolean;

FileNamestring. The output file path. A sibling temporary file is completed first, then atomically replaces the destination
OptionTSaveOption. Save option: saNone, saIncremental, saNoIncremental, or saRemoveSecurity
PdfVersionTPdfVersion target; use pvUnknown to preserve the current version

Return Value

Returns True if the document was saved successfully, or False on failure

Description

Saves the current document to a file path or a TStream

The PdfVersion parameter specifies the output PDF version; pass pvUnknown to keep the document's existing version

The Compressed property controls stream compression. Hybrid-reference, xref-stream and object-stream inputs are preserved when a classic-xref rewrite cannot retain their complete cross-reference semantics

Explicit PDF-version checks follow the active cross-reference revision chain and active object-stream members, so stale or unreferenced object bodies do not affect the requested version gate

The file overload leaves an existing destination unchanged if compression, post-processing or version validation fails

Conformance behaviour

Example

// Save to file
Pdf.SaveAs('output.pdf');

// Save to stream
var MS: TMemoryStream;
MS := TMemoryStream.Create;
try
  Pdf.SaveAs(MS);
  MS.SaveToFile('output.pdf');
finally
  MS.Free;
end;

See Also

LoadDocument, Compressed, CreateDocument