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

Clipped, Off-Page and White-on-White Text in PDF Extraction

See more PDF Text Extraction Examples

Demonstrates the "clippedText", "offPageText" and "obscuredText" filters. Text that a reader never sees - hidden by a clipping path, outside the crop box, or drawn in the same color as the box beneath it - is excluded by default, and the quality report notes what was skipped. Each kind can be included.

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 hidden_text.pdf

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

    CkJsonObject json = new CkJsonObject();
    CkJsonObject jsonOut = new CkJsonObject();

    //  The page has a visible paragraph plus three hidden lines: one drawn outside its clipping
    //  rectangle, one below the crop box, and one in white on a white box.
    success = pdf.ExtractText("text",json,jsonOut);
    if (success == false) {
        Log.i(TAG, pdf.lastErrorText());
        return;
        }

    Log.i(TAG, "---- default ----");
    Log.i(TAG, jsonOut.stringOf("text"));

    //  The quality report says what was left out.
    int i = 0;
    int count_i = jsonOut.SizeOfArray("quality.pages[0].issues");
    while (i < count_i) {
        jsonOut.put_I(i);
        Log.i(TAG, "issue: " + jsonOut.stringOf("quality.pages[0].issues[i].code"));
        i = i + 1;
        }

    //  Include everything.
    json.UpdateString("clippedText","include");
    json.UpdateString("offPageText","include");
    json.UpdateString("obscuredText","include");
    success = pdf.ExtractText("text",json,jsonOut);
    if (success == false) {
        Log.i(TAG, pdf.lastErrorText());
        return;
        }

    Log.i(TAG, "---- clippedText, offPageText, obscuredText: include ----");
    Log.i(TAG, jsonOut.stringOf("text"));

    //  Sample output:

    //  ---- default ----
    //  Visible Text
    //  
    //  This paragraph is visible. The page also carries three kinds of text a reader never sees.
    //  
    //  End of the visible text.
    //  issue: obscuredTextSkipped
    //  issue: clippedTextSkipped
    //  ---- clippedText, offPageText, obscuredText: include ----
    //  Visible Text
    //  
    //  This paragraph is visible. The page also carries three kinds of text a reader never sees.
    //  
    //  CLIPPED: this line is drawn outside its clipping rectangle.
    //  
    //  OBSCURED: this line is white on a white box.
    //  
    //  End of the visible text.
    //  
    //  OFFPAGE: this line sits below the crop box.

  }

  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."
  }
}