pCOS Cookbook

cookbook

pages/page_size

Retrieve the MediaBox and Rotation key for all 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;

/**
 * Retrieve the MediaBox and Rotation key for all pages.
 * <p>
 * Required software: pCOS interface 3 (pCOS 3.x, PDFlib+PDI/PPS 7.x, TET 2.2,
 * PLOP 3.x) <br>
 * Required data: PDF document
 * 
 * @version $Id: page_size.java,v 1.7 2015/11/16 11:53:16 stm Exp $
 */
public class page_size 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) + ": ");

            System.out.println("width="
                + p.pcos_get_number(doc, "pages[" + page + "]/width")
                + ", height="
                + p.pcos_get_number(doc, "pages[" + page + "]/height"));

            String objtype = p.pcos_get_string(doc, "type:pages[" + page
                + "]/Rotate");
            if (objtype.equals("number")) {
                System.out.println("Rotate = "
                    + p.pcos_get_number(doc, "pages[" + page + "]/Rotate"));
            }

            System.out.print("MediaBox = ");

            for (int i = 0; i < 4; i++) {
                System.out.print(p.pcos_get_number(doc, "pages[" + page
                    + "]/MediaBox[" + i + "]")
                    + " ");
            }
            System.out.println();
        }
    }

    public page_size(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_size example = new page_size(argv, "Page size", SEARCH_PATH,
            "$RCSfile: page_size.java,v $", "$Revision: 1.7 $");
        example.execute();
    }
}