pCOS Cookbook

cookbook

pages/page_labels

Print all page labels.

Download Java Code  Show Output  Show Input (articles.pdf) 

/*
 * Print all page labels.
 * <p>
 * Required software: pCOS interface 3 (PDFlib+PDI/PPS 7.x, TET 2.2,
 * PLOP 3.x) <br>
 * Required data: PDF document
 */
package com.pdflib.cookbook.pcos.pages;

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

public class page_labels 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"));

        System.out.println("Page labels:");

        String objtype = p.pcos_get_string(doc, "type:/Root/PageLabels");
        if (objtype.equals("null")) {
            System.out.println("[no page labels available]");
        }
        else {
            int pagecount = (int) p.pcos_get_number(doc, "length:pages");

            for (int page = 0; page < pagecount; page++) {
                String label = p.pcos_get_string(doc, "pages[" + page
                    + "]/label");
                System.out.println("Page " + (page + 1) + ": '" + label + "'");
            }
        }
    }

    public page_labels(String[] argv, String readable_name, String search_path) {
        super(argv, readable_name, search_path);
    }

    public static void main(String argv[]) {
        page_labels example = new page_labels(argv, "Page Labels", SEARCH_PATH);
        example.execute();
    }
}