PureBasic Requires Chilkat v11.7.0+
PureBasic
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 PureBasic Downloads
IncludeFile "CkPdf.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
; 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.i = CkPdf::ckCreate()
If pdf.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkPdf::ckLoadFile(pdf,"qa_data/pdf/grand_canyon_hiking_guide.pdf")
If success = 0
Debug CkPdf::ckLastErrorText(pdf)
CkPdf::ckDispose(pdf)
ProcedureReturn
EndIf
; Ask for the two options that are reserved for a later release.
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateBool(json,"mergeFontSubsets",1)
CkJsonObject::ckUpdateBool(json,"compactType1Fonts",1)
jsonOut.i = CkJsonObject::ckCreate()
If jsonOut.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkPdf::ckOptimize(pdf,"audit",json,jsonOut)
If success = 0
Debug CkPdf::ckLastErrorText(pdf)
CkPdf::ckDispose(pdf)
CkJsonObject::ckDispose(json)
CkJsonObject::ckDispose(jsonOut)
ProcedureReturn
EndIf
i.i = 0
numSkipped.i = CkJsonObject::ckSizeOfArray(jsonOut,"skipped")
Debug "skipped: " + Str(numSkipped)
While i < numSkipped
CkJsonObject::setCkI(jsonOut, i)
Debug " " + CkJsonObject::ckStringOf(jsonOut,"skipped[i].option") + " - " + CkJsonObject::ckStringOf(jsonOut,"skipped[i].reason")
i = i + 1
Wend
; 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::ckDispose(pdf)
CkJsonObject::ckDispose(json)
CkJsonObject::ckDispose(jsonOut)
ProcedureReturn
EndProcedure