Delphi DLL Requires Chilkat v11.7.0+
Delphi DLL
Why a PDF Optimization Was Skipped
See more PDF Optimization Examples
Demonstrates the "skipped" array, which lists the options that were asked for but not applied, each with a reason and, where it is page-specific, the pages. An option is skipped when it is reserved for a later release (mergeFontSubsets, compactType1Fonts), when the rules of the file forbid it (objectStreams in a PDF/A-1 file), or when the content could not be parsed safely (tidyContent and coalesceContent on a page whose content stream the parser does not understand). Nothing is ever changed on a guess: an option that cannot be applied safely is skipped and reported.Chilkat Delphi DLL Downloads
var
success: Boolean;
pdf: HCkPdf;
json: HCkJsonObject;
jsonOut: HCkJsonObject;
i: Integer;
numSkipped: Integer;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The PDF used in this example is available at grand_canyon_hiking_guide.pdf
pdf := CkPdf_Create();
success := CkPdf_LoadFile(pdf,'qa_data/pdf/grand_canyon_hiking_guide.pdf');
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
// Ask for the two options that are reserved for a later release.
json := CkJsonObject_Create();
CkJsonObject_UpdateBool(json,'mergeFontSubsets',True);
CkJsonObject_UpdateBool(json,'compactType1Fonts',True);
jsonOut := CkJsonObject_Create();
success := CkPdf_Optimize(pdf,'audit',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
i := 0;
numSkipped := CkJsonObject_SizeOfArray(jsonOut,'skipped');
Memo1.Lines.Add('skipped: ' + IntToStr(numSkipped));
while i < numSkipped do
begin
CkJsonObject_putI(jsonOut,i);
Memo1.Lines.Add(' ' + CkJsonObject__stringOf(jsonOut,'skipped[i].option') + ' - ' + CkJsonObject__stringOf(jsonOut,'skipped[i].reason'));
i := i + 1;
end;
// A skipped option is not a failure: Optimize returns true, the other options are applied, and the
// report says exactly what was left undone.
CkPdf_Dispose(pdf);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(jsonOut);