1 21 package gnu.jpdf; 22 23 import java.awt.*; 24 import java.io.*; 25 import java.util.*; 26 27 48 public class PDFDocument implements Serializable 49 { 50 51 57 58 61 protected int objser; 62 63 66 protected Vector objects; 67 68 71 private PDFCatalog catalog; 72 73 77 private PDFInfo info; 78 79 82 private PDFPageList pdfPageList; 83 84 87 private PDFOutline outline; 88 89 93 protected PDFObject defaultOutlineBorder; 94 95 99 public static final int USENONE = 0; 100 101 105 public static final int USEOUTLINES = 1; 106 107 111 public static final int USETHUMBS = 2; 112 113 119 public static final int FULLSCREEN = 3; 120 121 126 public static final String PDF_PAGE_MODES[] = { 127 "/UseNone", 128 "/UseOutlines", 129 "/UseThumbs", 130 "/FullScreen" 131 }; 132 133 136 private int fontid = 0; 137 138 141 private int imageid = 0; 142 143 146 private Vector fonts; 147 148 149 152 public PDFDocument() { 153 this(USENONE); 154 } 155 156 161 public PDFDocument(int pagemode) { 162 objser = 1; 163 objects = new Vector(); 164 fonts = new Vector(); 165 166 add(pdfPageList = new PDFPageList()); 168 add(catalog = new PDFCatalog(pdfPageList,pagemode)); 169 add(info = new PDFInfo()); 170 171 add(getOutline()); 173 } 174 175 176 177 190 public synchronized int add(PDFObject obj) 191 { 192 objects.addElement(obj); 193 obj.objser=objser++; obj.pdfDocument = this; 196 if(obj instanceof PDFPage) 198 pdfPageList.add((PDFPage)obj); 199 200 return obj.objser; 201 } 202 203 212 public PDFPage getPage(int page) { 213 return pdfPageList.getPage(page); 214 } 215 216 217 220 public PDFOutline getOutline() 221 { 222 if(outline==null) { 223 outline = new PDFOutline(); 224 catalog.setOutline(outline); 225 } 226 return outline; 227 } 228 229 239 public PDFFont getFont(String type,String font,int style) { 240 for(Enumeration en = fonts.elements(); en.hasMoreElements(); ) { 241 PDFFont ft = (PDFFont) en.nextElement(); 242 if(ft.equals(type,font,style)) 243 return ft; 244 } 245 246 fontid++; 248 PDFFont ft = new PDFFont("/F"+fontid,type,font,style); 249 add(ft); 250 fonts.addElement(ft); 251 return ft; 252 } 253 254 259 public String setImageName(PDFImage img) { 260 imageid++; 261 img.setName("/Image"+imageid); 262 return img.getName(); 263 } 264 265 266 270 public void setPDFInfo(PDFInfo info) { 271 this.info = info; 272 } 273 274 275 279 public PDFInfo getPDFInfo() { 280 return this.info; 281 } 282 283 284 298 public void write(OutputStream os) throws IOException 299 { 300 PDFOutput pos = new PDFOutput(os); 301 302 for(Enumeration en = objects.elements(); en.hasMoreElements(); ) 305 pos.write((PDFObject)en.nextElement()); 306 307 pos.close(); 309 310 os.flush(); 312 } 313 314 } | Popular Tags |