當既有 PDF 必須在不重寫原始 bytes 的情況下擴充時,請呼叫 BeginIncrementalUpdate。HotPDF 會透過正常 load path 解析來源檔案,並保留原始檔案的 byte-for-byte copy 供後續 save step 使用

THotPDF

 

傳回頂部  方法  下一頁

載入既有 PDF,並將檔案切換為 append-only incremental update mode

 

Delphi syntax:

procedure BeginIncrementalUpdate(const SourceFile: TFileName); overload;

procedure BeginIncrementalUpdate(const SourceFile: TFileName; const Password: AnsiString); overload;

 

C++ syntax:

void __fastcall BeginIncrementalUpdate(System::Sysutils::TFileName SourceFile);

void __fastcall BeginIncrementalUpdate(System::Sysutils::TFileName SourceFile, const System::AnsiString Password);

 

說明

當既有 PDF 需要在不重寫原始 bytes 的前提下延伸時,請呼叫 BeginIncrementalUpdate。HotPDF 會解析作用中的 trailer 或 xref-stream dictionary,記下 permanent 與 modification ID,透過 file-backed stream 讓來源檔案保持寫入鎖定,並只保留有界的尾部探測區,而不是完整複製一份來源

 

透過 loaded-document API 做出的新 indirect objects 與修改會自動追蹤。若程式碼透過正式 mutation hooks 以外的路徑改動物件,請以 MarkDirty 標記

 

來源若是 Standard 加密,請把它的 user 或 owner password 傳給雙參數 overload;來源若是 public-key 加密,請指派 PubSecKeyMaterial 並呼叫單參數 overload。HotPDF 只在更新的生命週期內保留已驗證的檔案金鑰或 FEK,保留原始的字串、stream、中繼資料與 Identity crypt filter 原則,並從物件編號及其保留的 generation 兩者衍生舊式的每物件金鑰

加密字典繼承自來源修訂版,增量模式啟用期間無法導入、替換或重新設定。不支援的異質明確 crypt filter 重寫會在輸出前失敗,不會以不同原則輸出密文

 

這套流程適合在保留較早數位簽章所涵蓋位元組範圍的前提下,加入後續的簽章欄位、附加中繼資料,或擴充已簽署的文件。即使來源已包含多個修訂版,仍會使用作用中的 trailer

 

加入第二個簽章

文件載入後並沒有所謂的目前頁面,可簽署的欄位改用 AddLoadedSignedSignatureField 加入(它直接吃頁面索引)。它會保留簽章空間,讓 SignPDFWithPFX,或外部簽署器流程的 PreparePDFForSigning 與 InsertSignatureHex,在更新儲存後填入。新簽章涵蓋整個檔案,較早的簽章因為位元組沒被動過而持續有效

PDF := THotPDF.Create(nil);
try
  PDF.BeginIncrementalUpdate('Signed.pdf');
  PDF.AddLoadedSignedSignatureField(0, 300, 120, 500, 160, 'Approver', 8192);
  PDF.SaveIncrementalUpdate('Prepared.pdf');
finally
  PDF.Free;
end;
THotPDF.SignPDFWithPFX('Prepared.pdf', 'SignedTwice.pdf', 'Signer.pfx', 'password');

 

另請參閱: MarkDirty, SaveIncrementalUpdate, AddLoadedSignedSignatureField, GetIncrementalUpdateSourceInfo, AcroForm 支援, PDF Filter 支援