1 20 package gnu.jpdf; 21 22 import java.awt.*; 23 import java.io.*; 24 import java.util.*; 25 26 27 41 public class PDFJob extends PrintJob implements Serializable 42 { 43 56 57 58 62 protected transient OutputStream os; 63 64 67 protected PDFDocument pdfDocument; 68 69 73 protected PDFPage page; 74 75 78 protected int pagenum; 79 80 81 83 91 public PDFJob() { 92 this(null); 93 } 94 95 103 public PDFJob(OutputStream os) { 104 this(os, "PDF Doc"); 105 } 106 107 119 public PDFJob(OutputStream os, String title) { 120 this.os = os; 121 this.pdfDocument = new PDFDocument(); 122 pagenum = 0; 123 pdfDocument.getPDFInfo().setTitle(title); 124 } 125 126 127 139 public Graphics getGraphics(int orient) { 140 page = new PDFPage(orient); 142 pdfDocument.add(page); 143 pagenum++; 144 145 return new graphic(page,this); 147 } 148 149 150 151 152 153 157 public void end() { 158 try { 159 pdfDocument.write(os); 160 } catch(IOException ioe) { 161 ioe.printStackTrace(); 164 } 165 166 os = null; 168 pdfDocument = null; 169 } 170 171 172 173 181 public Graphics getGraphics() { 182 return getGraphics(PDFPage.PORTRAIT); 183 } 184 185 186 187 192 public Dimension getPageDimension() { 193 if (page == null) { 194 System.err.println("PDFJob.getPageDimension(), page is null"); 195 } 196 Rectangle r = page.getMedia(); 197 198 int rot = page.getOrientation(); 201 if(rot == 90 || rot == 270) { 202 return new Dimension(r.height-r.y,r.width-r.x); 203 } 204 return new Dimension(r.width-r.x,r.height-r.y); 205 } 206 207 208 211 212 213 221 public int getPageResolution() { 222 return 72; 223 } 224 225 226 227 228 235 public boolean lastPageFirst() { 236 return false; 237 } 238 239 241 242 243 249 public PDFDocument getPDFDocument() { 250 return pdfDocument; 251 } 252 253 259 public PDFPage getCurrentPage() { 260 return page; 261 } 262 263 269 public int getCurrentPageNumber() { 270 return pagenum; 271 } 272 273 274 275 283 public PDFOutline addOutline(String title) { 284 return page.addOutline(title); 285 } 286 287 299 public PDFOutline addOutline(String title,int x,int y,int w,int h) { 300 return page.addOutline(title,x,y,w,h); 301 } 302 303 312 public PDFAnnot addNote(String note,int x,int y,int w,int h) { 313 return page.addNote(note,x,y,w,h); 314 } 315 316 317 324 class graphic extends PDFGraphics implements PrintGraphics { 325 328 private PDFJob job; 329 330 334 graphic(PDFPage page,PDFJob job) { 335 super(); 336 this.init(page); 337 this.job = job; 338 } 339 340 343 graphic(PDFPage page,PDFJob job,PrintWriter pw) { 344 super(); 345 this.init(page,pw); 346 this.job = job; 347 } 348 349 362 public Graphics create() { 363 closeBlock(); 364 graphic g = new graphic(getPage(),job,getWriter()); 365 366 g.clipRectangle = new Rectangle(clipRectangle); 368 369 return (Graphics) g; 370 } 371 372 376 public PrintJob getPrintJob() { 377 return (PrintJob)job; 378 } 379 380 } 382 } 384 | Popular Tags |