pCOS Cookbook

cookbook

resources/fonts

Create a list of all fonts contained in a PDF document and check if they are embedded.

Download Java Code  Show Output  Show Input (pCOS-path-reference.pdf) 

/*
 * Create a list of all fonts contained in a PDF document and check if they are
 * embedded.
 *
 * Required software: pCOS interface 8 (PDFlib+PDI/PPS 9, TET 4.1, PLOP 5.0)
 * Required data: PDF document
 */
package com.pdflib.cookbook.pcos.resources;

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

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

        /* retrieve the number of fonts in the document */
        int fontcount = (int) p.pcos_get_number(doc, "length:fonts");
        System.out.println(fontcount + " fonts found in "
            + p.pcos_get_string(doc, "filename"));

        for (int i = 0; i < fontcount; i++) {
            System.out.print(p.pcos_get_string(doc, "fonts[" + i + "]/name"));
            boolean embedded = p.pcos_get_number(doc, "fonts[" + i
                + "]/embedded") != 0;
            if (embedded)
                System.out.println(" (embedded)");
            else
                System.out.println(" (not embedded)");
        }
    }

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

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