1 /* $Id: quickreference.java,v 1.23 2006/09/28 13:31:21 tm Exp $ 2 * 3 * PDFlib+PDI client: mini imposition demo 4 */ 5 6 import java.io.*; 7 import com.pdflib.pdflib; 8 import com.pdflib.PDFlibException; 9 10 public class quickreference 11 { main(String argv[])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, endpage; 18 final double 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 /* This means we must check return values of load_font() etc. */ 29 p.set_parameter("errorpolicy", "return"); 30 31 if (p.begin_document("quickreference.pdf", "") == -1) 32 throw new Exception("Error: " + p.get_errmsg()); 33 34 p.set_parameter("SearchPath", searchpath); 35 36 p.set_info("Creator", "quickreference.java"); 37 p.set_info("Author", "Thomas Merz"); 38 p.set_info("Title", "imposition demo (Java)"); 39 40 manual = p.open_pdi_document(infile, ""); 41 if (manual == -1) 42 throw new Exception("Error: " + p.get_errmsg()); 43 44 row = 0; 45 col = 0; 46 47 p.set_parameter("topdown", "true"); 48 49 endpage = (int)p.pcos_get_number(manual, "length:pages"); 50 51 for (pageno = 1; pageno <= endpage; pageno++) { 52 if (row == 0 && col == 0) { 53 p.begin_page_ext(width, height, ""); 54 55 font = p.load_font("Helvetica-Bold", "unicode", ""); 56 if (font == -1) 57 throw new Exception("Error: " + p.get_errmsg()); 58 59 p.setfont(font, 18); 60 p.set_text_pos(24, 24); 61 p.show("PDFlib Quick Reference"); 62 } 63 64 page = p.open_pdi_page(manual, pageno, ""); 65 66 if (page == -1) 67 throw new Exception("Error: " + p.get_errmsg()); 68 69 p.fit_pdi_page(page, width/maxcol*col, 70 (row + 1) * height/maxrow, "scale " + (double) 1/maxrow); 71 p.close_pdi_page(page); 72 73 col++; 74 if (col == maxcol) { 75 col = 0; 76 row++; 77 } 78 if (row == maxrow) { 79 row = 0; 80 p.end_page_ext(""); 81 } 82 } 83 84 // finish the last partial page 85 if (row != 0 || col != 0) 86 p.end_page_ext(""); 87 88 p.end_document(""); 89 p.close_pdi_document(manual); 90 91 } catch (PDFlibException e) { 92 System.err.print("PDFlib exception occurred in quickreference sample:\n"); 93 System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() + 94 ": " + e.get_errmsg() + "\n"); 95 } catch (Exception e) { 96 System.err.println(e.getMessage()); 97 } finally { 98 if (p != null) { 99 p.delete(); 100 } 101 } 102 } 103 } 104