ตำราอาหารการตรวจสอบก่อนการพิมพ์

cookbook นี้จัดกลุ่ม preflight APIs และ demos เป็น recipes ตามงาน ใช้ API reference เมื่อต้องการ signatures ที่ exact และใช้ page นี้เมื่อต้องการ working path สำหรับ application, build script หรือ CI job

เลือกรูปแบบเอาต์พุต

var
  PDF: THotPDF;
begin
  PDF := THotPDF.Create(nil);
  try
    PDF.SavePreflightReport('Input.pdf', 'Input.preflight.txt');
    PDF.SavePreflightReport('Input.pdf', 'Input.preflight.json', '', pfJSON);
    PDF.SavePreflightReport('Input.pdf', 'Input.preflight.html', '', pfHTML);
    PDF.SavePreflightReport('Input.pdf', 'Input.preflight.csv', '', pfCSV);
  finally
    PDF.Free;
  end;
end;

text output byte-stable และ diff-friendly JSON เหมาะสำหรับ pipeline ingestion HTML เป็น self-contained และเปิดได้โดยตรงหรือ save เป็น CI artifact CSV ใช้ stable columns สำหรับ spreadsheet และ batch-report workflows

ตรวจสอบความถูกต้องของเอกสาร PDF/VT

var
  PDF: THotPDF;
  Report: AnsiString;
begin
  PDF := THotPDF.Create(nil);
  try
    if not PDF.ValidatePDFVT('Input.pdf', Report) then
      WriteLn(string(Report));
  finally
    PDF.Free;
  end;
end;

PDF/VT report focus ที่ ISO 16612-2 identification และ document-part structure: XMP GTS_PDFVTVersion ใน element text หรือ RDF attribute form, modification-date matching, PDF/X base marker, output intent, DPartRoot, DPartRootNode, NodeNameList, และ page-level DPart coverage

ใช้โปรไฟล์

var
  PDF: THotPDF;
  Report: AnsiString;
begin
  PDF := THotPDF.Create(nil);
  try
    Report := PDF.CreatePreflightReportWithProfile(
      'Input.pdf', '', 'project-preflight.ini', pfJSON);
  finally
    PDF.Free;
  end;
end;

profiles suppress named checks, warnings หรือ hints ทั้งหมด ใช้ ValidatePreflightProfile ก่อน apply profile ที่ user เขียนเองเมื่อการ fail closed สำคัญกว่าการ ignore obsolete name แบบเงียบ ๆ

สร้างโปรไฟล์ที่ใช้ซ้ำได้จากค่าที่กำหนดไว้ล่วงหน้า

var
  PDF: THotPDF;
  Profile: THPDFPreflightProfile;
begin
  PDF := THotPDF.Create(nil);
  try
    Profile := PDF.GetBuiltInPreflightProfile('compact');
    Profile.DisableWarnings := 'OpenAction,JavaScript,URIAction';
    PDF.SavePreflightProfile(Profile, 'compact-no-actions.ini');
  finally
    PDF.Free;
  end;
end;

ใช้ MergePreflightProfiles เพื่อรวม preset กับ project-specific names ใช้ DiffPreflightProfiles เพื่อตรวจ profile drift ก่อนอัปเดต shared configuration file

เก็บถาวรรายงานพร้อมกับ PDF

PDF.EmbedPreflightReportInPDF('Input.pdf', 'Input-with-report.pdf');
PDF.EmbedPreflightReportAsXMP('Input.pdf', 'Input-with-xmp-report.pdf');

text embedding path append comment block ที่อ่านได้หลัง final EOF marker ส่วน XMP path append payload รูปแบบ RDF สำหรับ archive workflows ที่ scan metadata packets

ตรวจสอบความถูกต้องของรายงานที่ฝังไว้

var
  OriginalReport: AnsiString;
  CurrentReport: AnsiString;
begin
  if not PDF.LoadAndValidatePreflightReport(
    'Input-with-report.pdf', OriginalReport, CurrentReport) then
    WriteLn(string(PDF.ComparePreflightReports(OriginalReport, CurrentReport)));
end;

validation path compare embedded fingerprint กับ preflight run ใหม่บน source bytes diff helper เป็น line-oriented และปรับให้เหมาะกับ HotPDF preflight reports

เรียกใช้ขั้นตอนการซ่อมแซมอย่างระมัดระวัง

var
  RepairsApplied: AnsiString;
begin
  if PDF.RepairPDFFromPreflightReport(
    'Broken.pdf', 'Broken-repaired.pdf', RepairsApplied) then
    WriteLn(string(RepairsApplied));
end;

repair helper ตั้งใจให้ scope แคบ โดยจัดการ trailing bytes หลัง final EOF marker และ missing EOF markers แต่ไม่ rebuild cross-reference tables หรือ rewrite streams

รวบรวมรายงานหลายฉบับ

Reports[0] := PDF.CreatePreflightReport('A.pdf');
Reports[1] := PDF.CreatePreflightReport('B.pdf');
Summary := PDF.AggregatePreflightReports(Reports);

aggregate output แสดง status line หนึ่งบรรทัดต่อ PDF และ totals สำหรับ processed reports, failures และ warnings เหมาะเมื่อ pipeline ต้องการ summary เดียว แม้จะเก็บ detailed reports ต่อ input file

ใช้เครื่องมือบรรทัดคำสั่ง

HotPDFPreflight Input.pdf -f json -o reports
HotPDFPreflight Input.pdf --pdfvt -o reports
HotPDFPreflight C:\Archive -r --preset compact -f text -o reports --aggregate reports\Aggregate.txt
HotPDFPreflight C:\Archive -r --profile project-preflight.ini -f html -o reports

CLI สะท้อน library workflow: input เป็นหนึ่ง file หรือ recursive directory, output แบบ text / JSON / HTML, optional password, optional profile, built-in preset, verbose progress และ aggregate summary

สร้างแดชบอร์ดแบบคงที่

PreflightDashboard C:\Archive C:\Archive\preflight-dashboard

dashboard demo เขียน index.html พร้อม per-file HTML reports ไม่ต้องมี web server จึง publish output เป็น static artifact ได้

ปรับให้เข้ากับตัวดึงข้อมูล JSON ในรูปแบบ veraPDF

Report := PDF.CreatePreflightReport('Input.pdf');
JSON := PDF.ConvertPreflightReportToVeraPDFStyle(Report);

adapter รักษา semantics ของ HotPDF ขณะ reshape failures เป็น validation-result structure ที่คุ้นเคยสำหรับ tooling ที่ consume JSON คล้าย veraPDF อยู่แล้ว

หัวข้อที่เกี่ยวข้อง

  • เมธอดรายงาน THotPDF Preflight
  • โครงสร้างแผนผัง Preflight API
  • การทดสอบความล้าการตรวจสอบก่อนการพิมพ์