pCOS Cookbook

cookbook

interactive/renditions new

Retrieve all renditions which are accessible from JavaScript.

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

/*
 * Retrieve all renditions which are accessible from JavaScript.
 *
 * Required software: pCOS interface 8 (PDFlib+PDI/PPS 9, TET 4.1, PLOP 5.0)
 * Required data: PDF document
 */
package com.pdflib.cookbook.pcos.interactive;

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

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

    	// Use the pCOS pseudo object for simplified enumeration
        int renditionCount = (int) p.pcos_get_number(doc, "length:names/Renditions");
        System.out.println(renditionCount + " renditions found");

        for (int i = 0; i < renditionCount; ++i) {
        	String base = "names/Renditions"  + "[" + i + "]";
        	String objtype, path;

        	// The rendition name is the key in the name tree
            String name = p.pcos_get_string(doc, base + ".key");
        	System.out.print("rendition " + i + ": name='" + name + "'");
        
        	// Content type (MIME type)
        	path = base + "/C/CT";
        	objtype = p.pcos_get_string(doc, "type:" + path);
        	if (objtype.equals("string")) {
	            String mimetype = p.pcos_get_string(doc, path);
	        	System.out.print(", mimetype='" + mimetype + "'");
        	}
            
        	// Length of embedded data if present
        	path = base + "/C/D/EF/F/Params/Size";
        	objtype = p.pcos_get_string(doc, "type:" + path);
        	if (objtype.equals("number")) {
	            int length = (int) p.pcos_get_number(doc, path);
	        	System.out.print(", length=" + length);
        	}
        	
        	// Retrieve the actual rendition data for embedded renditions
        	path = base + "/C/D/EF/F";
        	objtype = p.pcos_get_string(doc, "type:" + path);
        	if (objtype.equals("stream")) {
        		byte[] data = p.pcos_get_stream(doc, "", path); 
        	}

        	System.out.println();
        }
    }

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

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