interactive/bookmarks
Retrieve all bookmarks.
Download Java Code Show Output Show Input (pCOS-path-reference.pdf)
/*
* Retrieve bookmarks.
*
* 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 bookmarks 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 bookmarkcount = (int) p.pcos_get_number(doc, "length:bookmarks");
if (bookmarkcount == 0) {
System.out.println("No bookmarks found");
}
else {
System.out.println(bookmarkcount + " bookmarks found:");
System.out.println();
for (int i = 0; i < bookmarkcount; ++i) {
int level = (int) p.pcos_get_number(doc, "bookmarks[" + i
+ "]/level");
int dest_page = (int) p.pcos_get_number(doc, "bookmarks[" + i
+ "]/destpage");
for (int j = 0; j < level * 4; j += 1) {
System.out.print(" ");
}
System.out.print(p.pcos_get_string(doc, "bookmarks[" + i
+ "]/Title"));
/* If the destination page is -1 the bookmark probably refers
* to a page which has been deleted.
*/
if (dest_page != -1) {
System.out.print(": page " + dest_page);
}
System.out.println();
}
}
}
public bookmarks(String[] argv, String readable_name, String search_path) {
super(argv, readable_name, search_path);
}
public static void main(String argv[]) {
bookmarks example = new bookmarks(argv, "Bookmarks", SEARCH_PATH);
example.execute();
}
}