1/* $Id: quickreference.java 14574 2005-10-29 16:27:43Z bonefish $
2 *
3 * PDFlib/PDI client: mini imposition demo
4 */
5
6import java.io.*;
7import com.pdflib.pdflib;
8import com.pdflib.PDFlibException;
9
10public class quickreference
11{
12    public static void main (String argv[])
13    {
14	int manual, page;
15	int font, row, col;
16	final int maxrow = 2, maxcol = 2;
17	int i, startpage = 1, endpage = 4;
18	final float width = 500, height = 770;
19	int pageno;
20	pdflib p = null;
21	String infile = "reference.pdf";
22	/* This is where font/image/PDF input files live. Adjust as necessary.*/
23	String searchpath = "../data";
24
25	try{
26	    p = new pdflib();
27
28	    if (p.open_file("quickreference.pdf") == -1) {
29		throw new Exception("Error: " + p.get_errmsg());
30	    }
31
32	    p.set_parameter("SearchPath", searchpath);
33
34	    p.set_info("Creator", "quickreference.java");
35	    p.set_info("Author", "Thomas Merz");
36	    p.set_info("Title", "imposition demo (Java)");
37
38	    manual = p.open_pdi(infile, "", 0);
39	    if (manual == -1) {
40		throw new Exception("Error: " + p.get_errmsg());
41	    }
42
43	    row = 0;
44	    col = 0;
45
46	    p.set_parameter("topdown", "true");
47
48	    for (pageno = startpage; pageno <= endpage; pageno++) {
49		if (row == 0 && col == 0) {
50		    p.begin_page(width, height);
51		    font = p.load_font("Helvetica-Bold", "winansi", "");
52		    p.setfont(font, 18);
53		    p.set_text_pos(24, 24);
54		    p.show("PDFlib Quick Reference");
55		}
56
57		page = p.open_pdi_page(manual, pageno, "");
58
59		if (page == -1) {
60		    throw new Exception("Error: " + p.get_errmsg());
61		}
62
63		p.fit_pdi_page(manual, width/maxcol*col,
64		    (row + 1) * height/maxrow, "scale " + (float)1/maxrow);
65		p.close_pdi_page(page);
66
67		col++;
68		if (col == maxcol) {
69		    col = 0;
70		    row++;
71		}
72		if (row == maxrow) {
73		    row = 0;
74		    p.end_page();
75		}
76	    }
77
78	    // finish the last partial page
79	    if (row != 0 || col != 0)
80		p.end_page();
81
82	    p.close();
83	    p.close_pdi(manual);
84
85        } catch (PDFlibException e) {
86	    System.err.print("PDFlib exception occurred in quickreference sample:\n");
87	    System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +
88			    ": " + e.getMessage() + "\n");
89        } catch (Exception e) {
90            System.err.println(e.getMessage());
91        } finally {
92            if (p != null) {
93		p.delete();			/* delete the PDFlib object */
94            }
95        }
96    }
97}
98