Unicode C Requires Chilkat v11.7.0+
Unicode C
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 Unicode C Downloads
#include <C_CkPdfW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkPdfW pdf;
HCkJsonObjectW json;
HCkJsonObjectW jsonOut;
int i;
int numSkipped;
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 = CkPdfW_Create();
success = CkPdfW_LoadFile(pdf,L"qa_data/pdf/grand_canyon_hiking_guide.pdf");
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
return;
}
// Ask for the two options that are reserved for a later release.
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateBool(json,L"mergeFontSubsets",TRUE);
CkJsonObjectW_UpdateBool(json,L"compactType1Fonts",TRUE);
jsonOut = CkJsonObjectW_Create();
success = CkPdfW_Optimize(pdf,L"audit",json,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
return;
}
i = 0;
numSkipped = CkJsonObjectW_SizeOfArray(jsonOut,L"skipped");
wprintf(L"skipped: %d\n",numSkipped);
while (i < numSkipped) {
CkJsonObjectW_putI(jsonOut,i);
wprintf(L" %s - %s\n",CkJsonObjectW_stringOf(jsonOut,L"skipped[i].option"),CkJsonObjectW_stringOf(jsonOut,L"skipped[i].reason"));
i = i + 1;
}
// A skipped option is not a failure: Optimize returns true, the other options are applied, and the
// report says exactly what was left undone.
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
}