PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Pdf
oleobject loo_Json
oleobject loo_JsonOut
long i
long li_NumSkipped
li_Success = 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
loo_Pdf = create oleobject
li_rc = loo_Pdf.ConnectToNewObject("Chilkat.Pdf")
if li_rc < 0 then
destroy loo_Pdf
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Pdf.LoadFile("qa_data/pdf/grand_canyon_hiking_guide.pdf")
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
return
end if
// Ask for the two options that are reserved for a later release.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateBool("mergeFontSubsets",1)
loo_Json.UpdateBool("compactType1Fonts",1)
loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Pdf.Optimize("audit",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut
return
end if
i = 0
li_NumSkipped = loo_JsonOut.SizeOfArray("skipped")
Write-Debug "skipped: " + string(li_NumSkipped)
do while i < li_NumSkipped
loo_JsonOut.I = i
Write-Debug " " + loo_JsonOut.StringOf("skipped[i].option") + " - " + loo_JsonOut.StringOf("skipped[i].reason")
i = i + 1
loop
// A skipped option is not a failure: Optimize returns true, the other options are applied, and the
// report says exactly what was left undone.
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut