public void beginDraw() { // long t0 = System.currentTimeMillis(); if (document == null) { document = new Document(new Rectangle(width, height)); try { if (file != null) { // BufferedOutputStream output = new BufferedOutputStream(stream, 16384); output = new BufferedOutputStream(new FileOutputStream(file), 16384); } else if (output == null) { throw new RuntimeException( "PGraphicsPDF requires a path " + "for the location of the output file."); } writer = PdfWriter.getInstance(document, output); document.open(); content = writer.getDirectContent(); // template = content.createTemplate(width, height); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Problem saving the PDF file."); } // System.out.println("beginDraw fonts " + (System.currentTimeMillis() - t)); g2 = content.createGraphics(width, height, getMapper()); // g2 = template.createGraphics(width, height, mapper); } // System.out.println("beginDraw " + (System.currentTimeMillis() - t0)); super.beginDraw(); }
protected int writePdf(PdfWriter w, boolean spacing) throws IOException { DataOutputStream dos = w.getDataOutputStream(); int count = 2; // for [ and ] dos.write('['); boolean first = true; for (Iterator p = _a.iterator(); p.hasNext(); ) { PdfObject obj = (PdfObject) p.next(); if (first) { count += obj.writePdf(w, false); first = false; } else { count += obj.writePdf(w, true); } } dos.write(']'); return count; }