List of usage examples for com.itextpdf.text.pdf PdfContentByte PdfContentByte
public PdfContentByte(final PdfWriter wr)
PdfContentByte
-object. From source file:de.tf.capmath.puzzle.pdf.PdfUtil.java
License:Open Source License
public static void image2Pdf(File pdf, BufferedImage image) throws IOException, DocumentException { logger.info(String.format("Writing PDF to %s", pdf.getAbsolutePath())); Document document = new Document(PageSize.A4, 5, 5, 5, 5); PdfWriter writer = null;//from w ww . ja va 2 s. c o m try { writer = PdfWriter.getInstance(document, new FileOutputStream(pdf)); document.open(); PdfContentByte pdfCB = new PdfContentByte(writer); Image img = Image.getInstance(pdfCB, image, 1); document.add(img); } finally { document.close(); writer.close(); } }
From source file:mkl.testarea.itext5.pdfcleanup.PdfCleanUpRenderListener.java
License:Open Source License
public void registerNewContext(PdfDictionary resources, PdfContentByte canvas) { canvas = canvas == null ? new PdfContentByte(pdfStamper.getWriter()) : canvas; contextStack.push(new PdfCleanUpContext(resources, canvas)); }
From source file:net.apocalypselabs.symat.TasksExport.java
License:Open Source License
private void savePdfFile(String html, String path) { Platform.runLater(new Runnable() { @Override//from w w w. ja v a 2s. c o m public void run() { try { String k = html; OutputStream file = new FileOutputStream(new File(path)); Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, file); document.open(); PdfContentByte pdfCB = new PdfContentByte(writer); WritableImage image = browser.snapshot(null, null); BufferedImage buffered = SwingFXUtils.fromFXImage(image, null); Image img = Image.getInstance(pdfCB, buffered, 1); document.open(); document.add(img); document.close(); savedMsg(); } catch (Exception ex) { Debug.stacktrace(ex); java.awt.EventQueue.invokeLater(() -> { JOptionPane.showInternalMessageDialog(Main.mainPane, "Error saving: " + ex.getMessage()); }); } } }); }
From source file:Print.Print.java
private void printToPDF(BufferedImage bufferedImage) { // define pdfprinter and within try clause create for (int i = 0; i < quantity; i++) { PdfWriter writer = null;/*from w w w.ja v a 2 s . c om*/ try { // define fileoutputstream and within try clause create FileOutputStream fos = null; document = new Document(PageSize.A4.rotate()); fos = new FileOutputStream(output + photoID + "-" + Integer.toString(i + 1) + ".pdf"); // create the writer object try { writer = PdfWriter.getInstance(document, fos); } catch (DocumentException ex) { System.out.println(ex.getMessage()); } // open the writer and the document and add the image into the document writer.open(); document.open(); try { PdfContentByte pdfCB = new PdfContentByte(writer); if (bufferedImage == null) { Image image = Image.getInstance(input); image.scaleToFit(640, 480); document.add(image); } else { Image image = Image.getInstance(pdfCB, bufferedImage, 1); image.scaleToFit(640, 480); document.add(Image.getInstance(image)); } } catch (DocumentException ex) { System.out.println(ex.getMessage()); } catch (IOException ex) { System.out.println(ex.getMessage()); } // close the document and writer document.close(); writer.close(); System.out.println("Printer done."); } catch (Exception e) { System.out.println(e.getMessage()); } } }
From source file:sistemas.Utils.java
static void imageToPDF(BufferedImage img, String path, String title) { try {//from w w w. ja va 2s .c om Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path)); document.open(); PdfContentByte pdfCB = new PdfContentByte(writer); Image image = Image.getInstance(pdfCB, img, 1); if (title.isEmpty()) document.add(new Paragraph("Grfico de ventas:\n")); else document.add(new Paragraph(title + ":\n")); document.add(image); // step 5 document.close(); //document.close(); } catch (Exception e) { e.printStackTrace(); } // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }