Sample code for 30+ languages & platforms
PHP ActiveX 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 PHP ActiveX Downloads

PHP ActiveX
<?php

$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

$pdf = new COM("Chilkat.Pdf");
$success = $pdf->LoadFile('qa_data/pdf/grand_canyon_hiking_guide.pdf');
if ($success == 0) {
    print $pdf->LastErrorText . "\n";
    exit;
}

//  Ask for the two options that are reserved for a later release.
$json = new COM("Chilkat.JsonObject");
$json->UpdateBool('mergeFontSubsets',1);
$json->UpdateBool('compactType1Fonts',1);

$jsonOut = new COM("Chilkat.JsonObject");
$success = $pdf->Optimize('audit',$json,$jsonOut);
if ($success == 0) {
    print $pdf->LastErrorText . "\n";
    exit;
}

$i = 0;
$numSkipped = $jsonOut->SizeOfArray('skipped');
print 'skipped: ' . $numSkipped . "\n";
while ($i < $numSkipped) {
    $jsonOut->I = $i;
    print '   ' . $jsonOut->stringOf('skipped[i].option') . ' - ' . $jsonOut->stringOf('skipped[i].reason') . "\n";
    $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.

?>