List of usage examples for com.lowagie.text.pdf PdfContentByte addTemplate
public void addTemplate(PdfTemplate template, float x, float y)
From source file:tufts.vue.PresentationNotes.java
License:Educational Community License
public static void createMapAsPDF(File file, LWMap map) { // step 1: creation of a document-object Document document = new Document(PageSize.LETTER.rotate()); try {/* ww w. j a v a 2s . c o m*/ GUI.activateWaitCursor(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); writer.setDefaultColorspace(PdfName.DEFAULTRGB, null); // writer.setStrictImageSequence(true); // step 3: we open the document document.open(); PdfContentByte cb = writer.getDirectContent(); // cb.setFontAndSize(arg0, arg1) PdfTemplate tp = cb.createTemplate(document.getPageSize().getWidth() - 70, document.getPageSize().getHeight() - 70); // tp.createGraphicsShapes(arg0, arg1) PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(document.getPageSize().getWidth() - 70, document.getPageSize().getHeight() - 70, getFontMapper(), false, 60.0f); Dimension page = new Dimension((int) document.getPageSize().getWidth() - 70, (int) document.getPageSize().getHeight() - 70); // compute zoom & offset for visible map components Point2D.Float offset = new Point2D.Float(); offset.x = 35; offset.y = 35; // center vertically only if landscape mode //if (format.getOrientation() == PageFormat.LANDSCAPE) //TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit) Rectangle2D bounds = map.getBounds(); double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true); // System.out.println(scale + " zoom factor..."); // set up the DrawContext DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle map, false); // todo: absolute links shouldn't be spec'd here // dc.setAntiAlias(true); dc.setMapDrawing(); // dc.setPDFRender(true); //dc.setPrioritizeQuality(false); // why was this low quality? dc.setPrintQuality(); //dc.setAntiAlias(false); // why was this turned off? was it redundant? dc.setClipOptimized(true); // dc.setDraftQuality(true); // dc.setRawDrawing(); //dc.setClipOptimized(false); dc.setInteractive(false); dc.setDrawPathways(false); // VUE.getActiveMap().draw(dc); LWPathway.setShowSlides(false); map.drawZero(dc); LWPathway.setShowSlides(true); g2d.dispose(); // document.add(new Paragraph(new Chunk().setAnchor("http://www.cnn.com"))); cb.addTemplate(tp, 0, 0); document.newPage(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } finally { GUI.clearWaitCursor(); } // step 5: we close the document document.close(); }
From source file:tufts.vue.PresentationNotes.java
License:Educational Community License
public static void createPresentationNotes8PerPage(File file) { //page size notes: //martin-top,left,right,bottom = 36 //widht :612/*from ww w . j av a 2 s.co m*/ //height : 792 //usable space 540 x 720 // step 1: creation of a document-object Document document = new Document(PageSize.LETTER); try { GUI.activateWaitCursor(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // writer.setDefaultColorspace(PdfName.DEFAULTRGB, null); // writer.setStrictImageSequence(true); // step 3: we open the document document.open(); // PdfPTable table; // PdfPCell cell; int entryCount = 0; int entryOnPage = 0; int currentIndex = VUE.getActivePathway().getIndex(); VUE.getActivePathway().setIndex(-1); for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) { final LWSlide slide = entry.produceSlide(); final LWComponent toDraw = (slide == null ? entry.node : slide); entryCount++; //String label = entry.getLabel(); PdfContentByte cb = writer.getDirectContent(); //cb.cr PdfTemplate tp = cb.createTemplate(SlideSizeX, SlideSizeY); Point2D.Float offset = new Point2D.Float(); Rectangle2D bounds = null; bounds = slide.getBounds(); Dimension page = null; page = new Dimension(SlideSizeX, 172); //PdfTemplate tp = cb.createTemplate(document.getPageSize().width()-80, document.getPageSize().height()-80); double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true); PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(SlideSizeX, SlideSizeY, getFontMapper(), false, 60.0f); DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle entry.isMapView() ? entry.getFocal() : slide, false); // todo: absolute links shouldn't be spec'd here dc.setClipOptimized(false); dc.setPrintQuality(); //slide.drawZero(dc); toDraw.drawFit(dc, 0); g2d.dispose(); //document.add(Image.getInstance(tp)); if (entryOnPage == 0) { drawSequenceNumber(writer, 36, 739, entryCount); cb.addTemplate(tp, 56, 583); } if (entryOnPage == 1) { drawSequenceNumber(writer, 296, 739, entryCount); cb.addTemplate(tp, 306, 583); } if (entryOnPage == 2) { drawSequenceNumber(writer, 36, 559, entryCount); cb.addTemplate(tp, 56, 403); } if (entryOnPage == 3) { drawSequenceNumber(writer, 296, 559, entryCount); cb.addTemplate(tp, 306, 403); } if (entryOnPage == 4) { drawSequenceNumber(writer, 36, 375, entryCount); cb.addTemplate(tp, 56, 219); } if (entryOnPage == 5) { drawSequenceNumber(writer, 296, 375, entryCount); cb.addTemplate(tp, 306, 219); } if (entryOnPage == 6) { drawSequenceNumber(writer, 36, 192, entryCount); cb.addTemplate(tp, 56, 36); //cb.addTemplate(drawLines(writer),296,18); } if (entryOnPage == 7) { drawSequenceNumber(writer, 296, 192, entryCount); cb.addTemplate(tp, 306, 36); } entryOnPage++; if (entryCount % 8 == 0) { document.newPage(); entryOnPage = 0; } } VUE.getActivePathway().setIndex(currentIndex); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } finally { GUI.clearWaitCursor(); } // step 5: we close the document document.close(); }
From source file:tufts.vue.PresentationNotes.java
License:Educational Community License
public static void createAudienceNotes(File file) { //page size notes: //martin-top,left,right,bottom = 36 //widht :612/*from w ww . ja v a2s . c o m*/ //height : 792 //usable space 540 x 720 // step 1: creation of a document-object Document document = new Document(PageSize.LETTER); try { GUI.activateWaitCursor(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // writer.setDefaultColorspace(PdfName.DEFAULTRGB, null); // writer.setStrictImageSequence(true); // step 3: we open the document document.open(); // PdfPTable table; // PdfPCell cell; int entryCount = 0; int entryOnPage = 0; int currentIndex = VUE.getActivePathway().getIndex(); VUE.getActivePathway().setIndex(-1); for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) { final LWSlide slide = entry.produceSlide(); final LWComponent toDraw = (slide == null ? entry.node : slide); entryCount++; //String label = entry.getLabel(); PdfContentByte cb = writer.getDirectContent(); //cb.cr PdfTemplate tp = cb.createTemplate(SlideSizeX, SlideSizeY); Point2D.Float offset = new Point2D.Float(); // center vertically only if landscape mode //if (format.getOrientation() == PageFormat.LANDSCAPE) //TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit) Rectangle2D bounds = null; bounds = slide.getBounds(); Dimension page = null; page = new Dimension(SlideSizeX, 172); //PdfTemplate tp = cb.createTemplate(document.getPageSize().width()-80, document.getPageSize().height()-80); double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true); PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(SlideSizeX, SlideSizeY, getFontMapper(), false, 60.0f); DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle entry.isMapView() ? entry.getFocal() : slide, false); // todo: absolute links shouldn't be spec'd here dc.setClipOptimized(false); dc.setPrintQuality(); toDraw.drawFit(dc, 0); g2d.dispose(); //document.add(Image.getInstance(tp)); if (entryOnPage == 0) { drawSequenceNumber(writer, 36, 739, entryCount); cb.addTemplate(tp, 56, 583); cb.addTemplate(drawLines(writer), 296, 565); } if (entryOnPage == 1) { drawSequenceNumber(writer, 36, 559, entryCount); cb.addTemplate(tp, 56, 403); cb.addTemplate(drawLines(writer), 296, 385); } if (entryOnPage == 2) { drawSequenceNumber(writer, 36, 375, entryCount); cb.addTemplate(tp, 56, 219); cb.addTemplate(drawLines(writer), 296, 201); } if (entryOnPage == 3) { drawSequenceNumber(writer, 36, 192, entryCount); cb.addTemplate(tp, 56, 36); cb.addTemplate(drawLines(writer), 296, 18); } entryOnPage++; if (entryCount % 4 == 0) { document.newPage(); entryOnPage = 0; } } VUE.getActivePathway().setIndex(currentIndex); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } finally { GUI.clearWaitCursor(); } // step 5: we close the document document.close(); }
From source file:tufts.vue.PresentationNotes.java
License:Educational Community License
public static void createSpeakerNotes1PerPage(File file) { // step 1: creation of a document-object //This is a bit of a mess but because of hte bugs with drawing the slides //the easy way, we have no other choice but to render them directly onto the pdf //which makes it hard to use tables for stuff like formatting text...so we'll render // a blank table cell then render the image into it. Document document = new Document(); try {//from w ww .j a v a2 s . c o m GUI.activateWaitCursor(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // step 3: we open the document document.open(); PdfPTable table; PdfPCell cell; int currentIndex = VUE.getActivePathway().getIndex(); VUE.getActivePathway().setIndex(-1); for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) { final LWSlide slide = entry.produceSlide(); final LWComponent toDraw = (slide == null ? entry.node : slide); final String notes = entry.getNotes(); //String label = entry.getLabel(); PdfContentByte cb = writer.getDirectContent(); Point2D.Float offset = new Point2D.Float(); Rectangle2D bounds = null; //if (!entry.isMapView()) bounds = slide.getBounds(); //else //bounds = entry.getFocal().getBounds(); Dimension page = null; page = new Dimension(432, 324); PdfTemplate tp = cb.createTemplate(432, 324); double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true); PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(432, 324, getFontMapper(), false, 60.0f); DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle entry.isMapView() ? entry.getFocal() : slide, false); // todo: absolute links shouldn't be spec'd here dc.setClipOptimized(false); dc.setPrintQuality(); /*if (!entry.isMapView()) slide.drawZero(dc); else { entry.getFocal().draw(dc); }*/ toDraw.drawFit(dc, 0); g2d.dispose(); cb.addTemplate(tp, 80, 482); //Paragraph p = new Paragraph(); //p.setExtraParagraphSpace(330); // p.setSpacingBefore(330f); // p.setAlignment(Element.ALIGN_CENTER); Paragraph phrase = new Paragraph(notes); //phrase.setExtraParagraphSpace(340f); phrase.setSpacingBefore(320f); phrase.setKeepTogether(true); //cell = new PdfPCell(phrase); //cell.setBorder(0); // table = new PdfPTable(new float[]{ 1 }); // table.setWidthPercentage(100.0f); // table.getDefaultCell().setBorder(0); //table.getDefaultCell().setPaddingTop(30); //PdfPCell c2 = new PdfPCell(); //c2.setFixedHeight(340); //slides are 540x405 //c2.setBorder(0); //table.addCell(c2); //table.addCell(cell); //table.setKeepTogether(false); //cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); //p.add(table); //System.out.println("CELL HEIGHT : " + cell.getHeight()); //Section s1 = new Section(); //ColumnText chunk2 = new ColumnText(cb); //chunk2.setText(phrase); //chunk2.setSi //chunk2.setSimpleColumn(phrase,70, 330, document.getPageSize().width()-70,document.getPageSize().height()-70,15, Element.ALIGN_LEFT); // chunk2.go(); //PdfChunk chunk2 = new PdfChunk); Paragraph p2 = new Paragraph(" "); p2.setKeepTogether(false); phrase.setKeepTogether(false); // p2.setExtraParagraphSpace(230f); document.add(p2); document.add(phrase); document.newPage(); } VUE.getActivePathway().setIndex(currentIndex); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } finally { GUI.clearWaitCursor(); } // step 5: we close the document document.close(); }
From source file:views.HacerPedido.java
public void generatePDF(String nombreArchivo) throws DocumentException, FileNotFoundException, IOException { Document document = new Document(); PdfWriter writer;/*from ww w . j a v a2s .c om*/ String username = System.getProperty("user.name"); //String filepath = "/Users/alejandro/NetBeansProjects/QRGenerator/qrCode.png"; String filepath = "/Users/" + username + "/Desktop/" + nombreArchivo + ".pdf"; writer = PdfWriter.getInstance(document, new FileOutputStream(filepath)); // writer = PdfWriter.getInstance(document, new // FileOutputStream("my_jtable_fonts.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(500, 500); Graphics2D g2; g2 = tp.createGraphicsShapes(500, 500); // g2 = tp.createGraphics(500, 500); tablaPedidos.print(g2); g2.dispose(); //cb.addTemplate(tp, 30, 300); cb.addTemplate(tp, 75, 300); // //String archivo = System.getProperty("user.dir")+"/qrCode.png"; // String archivo = System.getProperty(filepath); // Desktop d = Desktop.getDesktop(); // d.open(new File(archivo)); // step 5: we close the document document.close(); }
From source file:vjmol.VJMol.java
License:GNU General Public License
protected void saveImage() { String strPath = m_txfImage.getText(); if (strPath == null || strPath.equals("")) return;//from www.j a va2 s.c o m StringTokenizer strTok = new StringTokenizer(strPath); if (strTok.hasMoreTokens()) strPath = strTok.nextToken(); strPath = new StringBuffer().append(m_strImageDir).append(File.separator).append(strPath).toString(); try { Image image = m_vjmolPanel.getImage(); File file = new File(strPath); FileOutputStream os = new FileOutputStream(strPath); String strFormat = (String) m_cmbFormat.getSelectedItem(); if (strFormat.equals("JPG")) { JpegEncoder jc = new JpegEncoder(image, 100, os); jc.Compress(); } else if (strFormat.equals("PPM")) { PpmEncoder pc = new PpmEncoder(image, os); pc.encode(); } else if (strFormat.equals("GIF")) { GifEncoder gc = new GifEncoder(image, os, true); gc.encode(); } else if (strFormat.equals("PNG")) { PngEncoder png = new PngEncoder(image); byte[] pngbytes = png.pngEncode(); os.write(pngbytes); } else if (strFormat.equals("BMP")) { BMPFile bmp = new BMPFile(); bmp.saveBitmap(os, image); } else if (strFormat.equals("PDF")) { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, os); document.open(); int w = m_vjmolPanel.getWidth(); int h = m_vjmolPanel.getHeight(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D g2 = tp.createGraphics(w, h); g2.setStroke(new BasicStroke(0.1f)); tp.setWidth(w); tp.setHeight(h); m_vjmolPanel.print(g2); g2.dispose(); cb.addTemplate(tp, 72, 720 - h); document.close(); } os.flush(); os.close(); } catch (Exception e) { e.printStackTrace(); } }