PdfWriter writer = PdfWriter.getInstance(pdf, outputStream); pdf.addWriter(writer);
public static void render(Drawable drawable, Rectangle2D bounds, File file) { initialize(); Rectangle size = new Rectangle((float) bounds.getWidth(), (float) bounds.getHeight()); Document document = new Document(size); FileOutputStream fos; try { fos = new FileOutputStream(file); } catch (FileNotFoundException e) { throw new RuntimeException("The file " + file + "could not be created", e); } PdfWriter writer; try { writer = PdfWriter.getInstance(document, fos); } catch (DocumentException e) { throw new RuntimeException("An error occurred while creating a PdfWriter object.", e); } document.open(); PdfContentByte contentByte = writer.getDirectContent(); Graphics2D g = new PdfGraphics2D(contentByte, (float) bounds.getWidth(), (float) bounds.getHeight(), fontMapper); g.translate(-bounds.getX(), -bounds.getY()); drawable.draw(g); g.dispose(); document.close(); }
Document document=new Document(pageSize,leftMargin,rightMargin,topMargin,bottomMargin); try{ PdfWriter writer=PdfWriter.getInstance(document,outputStream); PageHeaderFooterEvent headerFooterEvent=new PageHeaderFooterEvent(report); writer.setPageEvent(headerFooterEvent);
/** * Initializes the PDF writer this export view uses to write the table document. * @param document The iText document to be written. * @param out The output stream to which the document is written. * @throws DocumentException If something goes wrong during initialization. */ @Override protected void initItextWriter(Document document, OutputStream out) throws DocumentException { PdfWriter.getInstance(document, out).setPageEvent(new PageNumber()); }
public static void main( String[] args ) throws DocumentException, IOException { // step 1 Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf")); // step 3 document.open(); // step 4 XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream("index.html")); //step 5 document.close(); System.out.println( "PDF Created!" ); } }
public PdfExportServer(OutputStream outStream, PdfExportParams entity) { try { styler = entity.getStyler() == null ? new PdfExportStylerDefaultImpl() : entity.getStyler(); document = styler.getDocument(); PdfWriter.getInstance(document, outStream); document.open(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } }
public PdfExportServer(OutputStream outStream, PdfExportParams entity) { try { styler = entity.getStyler() == null ? new PdfExportStylerDefaultImpl() : entity.getStyler(); document = styler.getDocument(); PdfWriter.getInstance(document, outStream); document.open(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } }
public void createDDPDF(File pdfFile) throws FileNotFoundException, DocumentException, SQLException { Document document=new Document(); PdfWriter.getInstance(document,new FileOutputStream(pdfFile)); document.open(); addTitlePage(document); createPDFBody(document); } // End of createDDPDF
@Override public void writeReportInternal(final File outputFile, final TestRunCoverageStatistics runStats) throws IOException { try { document = new Document(PageSize.A4.rotate()); writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); document.open(); addMetaData(runStats); addContent(runStats); document.close(); } catch (final Exception e) { throw new IOException(e); } }
public byte[] exportProcess(Process process, File outputFile) throws Exception { new ActivityNodeSequencer(process).assignNodeSequenceIds(); Document document = new Document(); DocWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); document.open(); document.setPageSize(PageSize.LETTER); Rectangle pageSize = document.getPageSize(); Chapter chapter = printProcessPdf(writer, 1, process, pageSize); document.add(chapter); document.close(); return Files.readAllBytes(Paths.get(outputFile.getPath())); }
public static void createPDFfromRTM(File pdfFile, ReportTableModel rtm) throws FileNotFoundException, DocumentException { Document document=new Document(); PdfWriter.getInstance(document,new FileOutputStream(pdfFile)); document.open(); PdfPTable pdftable = RTMUtil.createPDFTable(rtm); document.add(pdftable); document.close(); }
public static void main( String[] args ) throws FileNotFoundException, DocumentException { // step 1 Document document = new Document(); document.setPageSize(PageSize.A4); // step 2 PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf")); // step 3 document.open(); // step 4 create PDF contents document.add(TableBuilder.createTable()); //step 5 document.close(); System.out.println( "PDF Created!" ); } }
public static void main( String[] args ) { try { // 1. create the document Document document = new Document(); // 2. get PdfWriter PdfWriter.getInstance(document, new FileOutputStream("helloworld.pdf")); // 3. open the document document.open(); // 4. add the content document.add(new Paragraph("Hello World!")); // 5. close the document document.close(); System.out.println("Document created!"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } }
public void createDDPDF(OutputStream output) throws FileNotFoundException, DocumentException, SQLException { Document document = new Document(); PdfWriter.getInstance(document, output); document.open(); addTitlePage(document); createPDFBody(document); } //Function to create PDF Body
public static void main( String[] args ) { try { // 1. create the document page size: A4, margins: left:20 right:20 top:40 bottom:40 Document document = new Document(PageSize.A4, 20f,20f,40f,40); //for custom pagesize //Rectangle pagesize = new Rectangle(216f, 720f); // 2. get PdfWriter PdfWriter.getInstance(document, new FileOutputStream("pagesettings.pdf")); // 3. open the document document.open(); // 4. add the content document.add(new Paragraph("Hello World!")); // 5. close the document document.close(); System.out.println("Document created!"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } }
public static void saveChartAsPDF(OutputStream out, JFreeChart chart, int width, int height) throws DocumentException { Rectangle pagesize = new Rectangle(width, height); Document document = new Document(pagesize, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, out); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2, r2D); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); }
public void doExport(OutputStream out) throws DocumentException { Document document = new Document(); PdfWriter.getInstance(document, out); document.open(); PdfPTable pdf = new PdfPTable(table.getHeaders().size()); pdf.setWidthPercentage(100); title(pdf); header(pdf); body(pdf); document.add(pdf); document.close(); }
@Override protected final void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // IE workaround: write into byte array first. ByteArrayOutputStream baos = createTemporaryOutputStream(); // Apply preferences and build metadata. Document document = new Document(PageSize.A4.rotate(), 36, 36, 54, 36); PdfWriter writer = PdfWriter.getInstance(document, baos); prepareWriter(model, writer, request); buildPdfMetadata(model, document, request); // Build PDF document. document.open(); buildPdfDocument(model, document, writer, request, response); document.close(); // Flush to HTTP response. writeToResponse(response, baos); }
public ITextContext open(File fileOut) throws FileNotFoundException, DocumentException { this.document = createDocument(); this.fileOut = fileOut; this.pageNumber = new PageNumber(); this.tableOfContents = new TableOfContents(pageNumber); Function<PageInfos, Phrase> header = constant(new Phrase("")); Function<PageInfos, Phrase> footer = constant(new Phrase("")); OutputStream outStream = new FileOutputStream(fileOut); this.pdfWriter = PdfWriter.getInstance(document, outStream); this.pdfWriter.setBoxSize("art", getDocumentArtBox()); this.pdfWriter.setPageEvent(pageNumber); this.pdfWriter.setPageEvent(tableOfContents); this.pdfWriter.setPageEvent(new HeaderFooter(pageNumber, styles, header, footer)); // document.open(); return this; }
private static void createPDF(String path) throws Exception { Document pdfDoc = new Document(PageSize.A4); PdfWriter.getInstance(pdfDoc, new FileOutputStream(path)).setPdfVersion(PdfWriter.VERSION_1_7); pdfDoc.open(); Font myfont = new Font(); myfont.setStyle(Font.NORMAL); myfont.setSize(11); Paragraph para = new Paragraph("test", myfont); para.setAlignment(Element.ALIGN_JUSTIFIED); pdfDoc.add(para); pdfDoc.close(); }