Preflight Cookbook

Αυτό το cookbook ομαδοποιεί τις preflight APIs και demos σε συνταγές προσανατολισμένες σε εργασίες. Χρησιμοποιήστε την API reference όταν χρειάζεστε ακριβείς signatures· χρησιμοποιήστε αυτή τη σελίδα όταν χρειάζεστε λειτουργική διαδρομή για εφαρμογή, build script ή CI job

Choose an output format

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 είναι byte-stable και φιλική σε diff. Το JSON είναι κατάλληλο για ingestion σε pipelines. Το HTML είναι self-contained και μπορεί να ανοιχτεί απευθείας ή να αποθηκευτεί ως CI artifact. Το CSV χρησιμοποιεί σταθερές στήλες για spreadsheet και batch-report workflows

Validate PDF/VT documents

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 εστιάζει στην ταυτοποίηση ISO 16612-2 και στη δομή document-part: XMP GTS_PDFVTVersion ως element text ή RDF attribute, αντιστοίχιση modification-date, PDF/X base marker, output intent, DPartRoot, DPartRootNode, NodeNameList και page-level DPart coverage

Apply a profile

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, or all hints. Use ValidatePreflightProfile before applying a user-authored profile when failing closed is more important than silently ignoring an obsolete name.

Δημιουργία επαναχρησιμοποιήσιμου προφίλ από preset

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 με ονόματα ειδικά για το έργο. Χρησιμοποιήστε το DiffPreflightProfiles για να ελέγξετε την απόκλιση προφίλ πριν ενημερώσετε ένα κοινόχρηστο αρχείο διαμόρφωσης

Archive the report with the PDF

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

Η διαδρομή text embedding προσαρτά ένα αναγνώσιμο comment block μετά τον τελικό EOF marker. Η διαδρομή XMP προσαρτά RDF-shaped payload για archive workflows που σαρώνουν metadata packets

Validate an embedded report

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 συγκρίνει το 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 παραμένει σκόπιμα στενός. Χειρίζεται trailing bytes μετά τον τελικό EOF marker και ελλείποντες EOF markers, αλλά δεν ξαναχτίζει cross-reference tables ούτε ξαναγράφει streams

Aggregate many reports

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

Η aggregate έξοδος παραθέτει μία γραμμή status ανά PDF και totals για processed reports, failures και warnings. Είναι χρήσιμη όταν ένα pipeline χρειάζεται μία σύνοψη παρότι τα 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 αντικατοπτρίζει τη ροή της βιβλιοθήκης: ένα αρχείο ή recursive directory input, text / JSON / HTML output, προαιρετικό password, προαιρετικό profile, built-in preset, verbose progress και aggregate summary

Build a static dashboard

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

Το dashboard demo γράφει ένα index.html μαζί με HTML reports ανά αρχείο. Δεν απαιτείται web server, οπότε η έξοδος μπορεί να δημοσιευτεί ως static artifact

Adapt to veraPDF-style JSON consumers

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

Ο adapter διατηρεί τα semantics του HotPDF ενώ αναδιαμορφώνει failures σε οικεία validation-result structure για εργαλεία που ήδη καταναλώνουν veraPDF-like JSON

Related Topics