Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.7.0+

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoPdf
    Variant vJson
    Handle hoJson
    Variant vJsonOut
    Handle hoJsonOut
    Integer i
    Integer iNumSkipped
    String sTemp1
    String sTemp2

    Move False To iSuccess

    //  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

    Get Create (RefClass(cComChilkatPdf)) To hoPdf
    If (Not(IsComObjectCreated(hoPdf))) Begin
        Send CreateComObject of hoPdf
    End
    Get ComLoadFile Of hoPdf "qa_data/pdf/grand_canyon_hiking_guide.pdf" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPdf To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Ask for the two options that are reserved for a later release.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateBool Of hoJson "mergeFontSubsets" True To iSuccess
    Get ComUpdateBool Of hoJson "compactType1Fonts" True To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
    If (Not(IsComObjectCreated(hoJsonOut))) Begin
        Send CreateComObject of hoJsonOut
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoJsonOut to vJsonOut
    Get ComOptimize Of hoPdf "audit" vJson vJsonOut To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPdf To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Move 0 To i
    Get ComSizeOfArray Of hoJsonOut "skipped" To iNumSkipped
    Showln "skipped: " iNumSkipped
    While (i < iNumSkipped)
        Set ComI Of hoJsonOut To i
        Get ComStringOf Of hoJsonOut "skipped[i].option" To sTemp1
        Get ComStringOf Of hoJsonOut "skipped[i].reason" To sTemp2
        Showln "   " sTemp1 " - " sTemp2
        Move (i + 1) To i
    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.


End_Procedure