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(); }