PDFlib
BASKET
PDFlib

interactive/articles

Create a list of all articles contained in a PDF document.

Download Java Code     Show Output     Show Input PDF

package com.pdflib.cookbook.pcos.interactive;


import com.pdflib.pCOS;

import com.pdflib.pCOSException;

import com.pdflib.cookbook.pcos.pcos_cookbook_example;


/**

 * Create a list of all articles contained in a PDF document

 * <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: articles.java,v 1.6 2010/09/27 13:24:25 stm Exp $

 */

public class articles 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(pCOS p, String filename) throws pCOSException,

        Exception {


        /* Open the PDF document */

        int doc = p.open_document(filename, "");

        if (doc == -1)

            throw new Exception("Error: " + p.get_errmsg());


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


        /* Get the number of articles in the document */

        int articlecount = (int) p.pcos_get_number(doc, "length:articles");

        System.out.print(articlecount + " articles");

        if (articlecount > 0) {

            System.out.print(":");

        }

        System.out.println();


        /* For all articles print all its beads */

        for (int i = 0; i < articlecount; ++i) {

            System.out.println("Title: '"

                + p.pcos_get_string(doc, "articles[" + i + "]/I/Title") + "'");


            int beadcount = (int) p.pcos_get_number(doc, "length:articles[" + i

                + "]/beads");


            for (int k = 0; k < beadcount; ++k) {

                System.out.println("    page "

                    + (int) p.pcos_get_number(doc, "articles[" + i + "]/beads["

                        + k + "]/destpage"));

            }

        }


        p.close_document(doc);

    }


    public articles(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[]) {

        articles example = new articles(argv, "Articles", SEARCH_PATH,

            "$RCSfile: articles.java,v $", "$Revision: 1.6 $");

        example.execute();

    }

}