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

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean 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

    CkPdf pdf = new CkPdf();
    success = pdf.LoadFile("qa_data/pdf/grand_canyon_hiking_guide.pdf");
    if (success == false) {
        Log.i(TAG, pdf.lastErrorText());
        return;
        }

    //  Ask for the two options that are reserved for a later release.
    CkJsonObject json = new CkJsonObject();
    json.UpdateBool("mergeFontSubsets",true);
    json.UpdateBool("compactType1Fonts",true);

    CkJsonObject jsonOut = new CkJsonObject();
    success = pdf.Optimize("audit",json,jsonOut);
    if (success == false) {
        Log.i(TAG, pdf.lastErrorText());
        return;
        }

    int i = 0;
    int numSkipped = jsonOut.SizeOfArray("skipped");
    Log.i(TAG, "skipped: " + String.valueOf(numSkipped));
    while (i < numSkipped) {
        jsonOut.put_I(i);
        Log.i(TAG, "   " + jsonOut.stringOf("skipped[i].option") + " - " + jsonOut.stringOf("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.

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}