pCOS Cookbook

cookbook

pages/page_transparency

Identify transparent pages.

Download Java Code     Show Output     Show Input PDF

package com.pdflib.cookbook.pcos.pages;

import com.pdflib.IpCOS;
import com.pdflib.cookbook.pcos.pcos_cookbook_example;

/**
 * Identify transparent pages using the "usespagetransparency" and
 * "usesanytransparency" pseudo objects.
 * <p>
 * Required software: pCOS interface 8 (TET 4.1+, TET PDF IFilter 4.1+,
 * PDFlib+PDI 9.0, PPS 9.0 pCOS 4.0)
 * <br>
 * Required data: PDF document
 * 
 * @version $Id: page_transparency.java,v 1.2 2016/06/24 10:01:02 stm Exp $
 */
public class page_transparency extends pcos_cookbook_example {

    /* This is where the data files are. Adjust as necessary. */
    private final static String SEARCH_PATH = "../input";

    public void example_code(IpCOS p, int doc) throws Exception {

        System.out.println("File name: " + p.pcos_get_string(doc, "filename"));

        int pagecount = (int) p.pcos_get_number(doc, "length:pages");

        for (int page = 0; page < pagecount; page++) {
            System.out.println("Page " + (page + 1) + ": ");

            boolean usespagetransparency =
                p.pcos_get_number(doc, "pages[" + page + "]/usespagetransparency") != 0;
            boolean usesanytransparency =
                p.pcos_get_number(doc, "pages[" + page + "]/usesanytransparency") != 0;
            
            System.out.println("  Transparency in page contents: "
                + (usespagetransparency ? "true" : "false"));

            System.out.println("  Transparency in page contents or annotations: "
                + (usesanytransparency ? "true" : "false"));
            
            System.out.println();
        }
    }

    public page_transparency(String[] argv, String readable_name, String search_path,
        String full_rcs_file_name, String revision) {
        super(argv, readable_name, search_path, full_rcs_file_name, revision);
    }

    public static void main(String argv[]) {
        page_transparency example = new page_transparency(argv, "Page transparency", SEARCH_PATH,
            "$RCSfile: page_transparency.java,v $", "$Revision: 1.2 $");
        example.execute();
    }
}