List of usage examples for com.itextpdf.text Document add
public boolean add(Element element) throws DocumentException
Element
to the Document
. From source file:com.devox.GUI.PDF.CrearReportePorEstado.java
@Override public void crear(File file) { try {//from w w w. j a v a 2 s. c o m Document document = new Document(PageSize.A4, 50f, 50f, 65f, 100f); file.createNewFile(); PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); setLogo(); CabeceraPieDePagina event = new CabeceraPieDePagina(); w.setPageEvent(event); document.newPage(); document.add(configurarInformacion()); document.add(new Paragraph("\n")); PdfPTable table = crearTabla(); agregarProductos(table); document.add(table); document.add(new Paragraph("\n")); document.add(new Paragraph("TOTAL: " + data.length + "FOLIOS.", FUENTE_FOLIO_CHICA)); document.close(); } catch (Exception ex) { Log.print(ex); } Object[] options = { "Abrir PDF", "No" }; int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options, options[0]); if (open == JOptionPane.YES_OPTION) { try { Desktop.getDesktop().open(file); } catch (IOException ex) { Log.print("No se encontr la ruta"); JOptionPane.showMessageDialog(null, "Error en el archivo"); } } }
From source file:com.devox.GUI.PDF.CrearReporteTarimas.java
@Override public void crear(File file) { try {/*from w ww .j a v a 2 s .c o m*/ Document document = new Document(PageSize.A4.rotate()); file.createNewFile(); PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); setLogo(); CabeceraPieDePagina event = new CabeceraPieDePagina(); w.setPageEvent(event); document.setMargins(50, 50, 100, 50); document.newPage(); document.add(configurarInformacion()); PdfPTable table = crearTabla(); agregarProductos(table); document.add(table); document.close(); } catch (Exception ex) { Log.print(ex); } Object[] options = { "Abrir PDF", "No" }; int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options, options[0]); if (open == JOptionPane.YES_OPTION) { try { Desktop.getDesktop().open(file); } catch (IOException ex) { Log.print("No se encontr la ruta"); JOptionPane.showMessageDialog(null, "Error en el archivo"); } } }
From source file:com.devox.GUI.PDF.ExportarAPDF.java
public void crearDestruccion(File file) { try {//from www. j av a2s . com Document document = new Document(PageSize.A4); file.createNewFile(); PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); setLogo(); CabeceraPieDePagina event = new CabeceraPieDePagina(); w.setPageEvent(event); document.setMargins(50, 50, 100, 220); document.newPage(); document.add(setUpInformation()); PdfPTable t = createTable(); addProductos(model, t); document.add(t); // document.close(); } catch (Exception ex) { Log.print(ex); Log.print(ex); } }
From source file:com.devox.GUI.PDF.ExportarAPDF.java
public void crearApto(File file) { try {/*from ww w . j a va 2 s.c o m*/ Document document = new Document(PageSize.A4); file.createNewFile(); PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); setLogo(); CabeceraPieDePagina event = new CabeceraPieDePagina(); w.setPageEvent(event); document.setMargins(50, 50, 100, 220); document.newPage(); document.add(setUpInformationTarimas()); // PdfPTable t = createTable(); // addProductos(model, t); // document.add(t); // document.close(); } catch (Exception ex) { Log.print(ex); Log.print(ex); } }
From source file:com.devox.GUI.PDF.ExportarAPDF.java
public void crearTarimas(File file) { try {//from w w w .j a va2s . com Document document = new Document(PageSize.A4.rotate()); file.createNewFile(); PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); setLogo(); CabeceraPieDePagina2 event = new CabeceraPieDePagina2(); w.setPageEvent(event); document.setMargins(50, 50, 100, 50); document.newPage(); document.add(setUpInformationTarimas()); PdfPTable t = createTableTarimas(); addProductosTarimas(t); document.add(t); // document.close(); } catch (Exception ex) { Log.print(ex); Log.print(ex); } }
From source file:com.dexter.fms.mbean.ReportsMBean.java
@SuppressWarnings("unchecked") public void createPDF(int type, String filename, int pageType) { try {//w w w. j av a 2s . c om FacesContext context = FacesContext.getCurrentInstance(); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new HeaderFooter()); writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788)); if (!document.isOpen()) { document.open(); } switch (pageType) { case 1: document.setPageSize(PageSize.A4); break; case 2: document.setPageSize(PageSize.A4.rotate()); break; } document.addAuthor("FMS"); document.addCreationDate(); document.addCreator("FMS"); document.addSubject("Report"); document.addTitle(getReport_title()); PdfPTable headerTable = new PdfPTable(1); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "satraklogo.jpg"; Hashtable<String, Object> params = new Hashtable<String, Object>(); params.put("partner", dashBean.getUser().getPartner()); GeneralDAO gDAO = new GeneralDAO(); Object pSettingsObj = gDAO.search("PartnerSetting", params); PartnerSetting setting = null; if (pSettingsObj != null) { Vector<PartnerSetting> pSettingsList = (Vector<PartnerSetting>) pSettingsObj; for (PartnerSetting e : pSettingsList) { setting = e; } } gDAO.destroy(); PdfPCell c = null; if (setting != null && setting.getLogo() != null) { Image logoImg = Image.getInstance(setting.getLogo()); logoImg.scaleToFit(212, 51); c = new PdfPCell(logoImg); } else c = new PdfPCell(Image.getInstance(logo)); c.setBorder(0); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); Paragraph stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { //font exception } Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph(getReport_title(), font)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); if (getReport_start_dt() != null && getReport_end_dt() != null) { stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(10); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); new Font(helvetica, 12, Font.NORMAL); Paragraph ch = new Paragraph("From " + getReport_start_dt() + " to " + getReport_end_dt(), font); c = new PdfPCell(ch); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); } stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); document.add(headerTable); PdfPTable pdfTable = exportPDFTable(type); if (pdfTable != null) document.add(pdfTable); //Keep modifying your pdf file (add pages and more) document.close(); String fileName = filename + ".pdf"; writeFileToResponse(context.getExternalContext(), baos, fileName, "application/pdf"); context.responseComplete(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.dexter.fuelcard.mbean.UtilMBean.java
public byte[] createInvoicePDF(int pageType, String title, String dateperiod, String amount, String chargeType, String chargeAmount, String total) { try {//www.j a v a2 s.c om Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new HeaderFooter()); writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788)); if (!document.isOpen()) { document.open(); } switch (pageType) { case 1: document.setPageSize(PageSize.A4); break; case 2: document.setPageSize(PageSize.A4.rotate()); break; } document.addAuthor("FUELCARD"); document.addCreationDate(); document.addCreator("FUELCARD"); document.addSubject("Invoice"); document.addTitle(title); PdfPTable headerTable = new PdfPTable(1); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "satraklogo.jpg"; PdfPCell c = new PdfPCell(Image.getInstance(logo)); c.setBorder(0); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); Paragraph stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { //font exception } Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph(title, font)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); if (dateperiod != null) { stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(10); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); new Font(helvetica, 12, Font.NORMAL); Paragraph ch = new Paragraph("For " + dateperiod, font); c = new PdfPCell(ch); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); } stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); document.add(headerTable); PdfPTable pdfTable = new PdfPTable(4); try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Charge Type", font)); // % per transaction or flat per license pdfTable.addCell(new Paragraph("Charge Amount", font)); // the amount of the charge setting if (chargeType.equalsIgnoreCase("Percent-Per-Tran")) { pdfTable.addCell(new Paragraph("Total Amount", font)); // the amount of the charge setting } else { pdfTable.addCell(new Paragraph("Total License", font)); // the amount of the charge setting } //pdfTable.addCell(new Paragraph("Description", font)); // the pdfTable.addCell(new Paragraph("Amount Due", font)); font = new Font(helvetica, 8, Font.NORMAL); pdfTable.addCell(new Paragraph(chargeType, font)); pdfTable.addCell(new Paragraph(chargeAmount, font)); pdfTable.addCell(new Paragraph(total, font)); pdfTable.addCell(new Paragraph(amount, font)); pdfTable.setWidthPercentage(100); if (pdfTable != null) document.add(pdfTable); //Keep modifying your pdf file (add pages and more) document.close(); return baos.toByteArray(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.docdoku.server.extras.TitleBlockGenerator.java
License:Open Source License
public InputStream generateBlockTitleToPDF(InputStream inputStream) throws IOException, DocumentException { File tmpDir = com.google.common.io.Files.createTempDir(); File blockTitleFile = new File(tmpDir, inputStream.toString()); ResourceBundle bundle = ResourceBundle.getBundle(BASE_NAME, pLocale); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(blockTitleFile)); document.open();//from w ww . j a v a2s . c o m // Main paragraph Paragraph preface = new Paragraph(); generateHeader(preface, bundle); generateTable(preface, bundle); addEmptyLine(preface, 1); if (!instanceAttributes.isEmpty()) { generateAttribute(preface, bundle); addEmptyLine(preface, 1); } if (workflow != null) { generateLyfeCycleState(preface, bundle); } document.add(preface); addMetaData(document); document.close(); tmpDir.deleteOnExit(); // Merge the pdf generated with the pdf given in the input stream //TODO: use PdfStamper to insert into the existing pdf. return mergePdfDocuments(new FileInputStream(blockTitleFile), inputStream); }
From source file:com.documents.services.LicenseRegistrationFormServiceImpl.java
License:Open Source License
@Override public void createPdf(List<String> infoList, String filePath) throws IOException, DocumentException { /**//from w w w . j a v a2 s . c o m * We insert here the path where we can find the JSON */ BufferedReader br = new BufferedReader( new FileReader("src\\main\\resources\\documentsAdditionalText.json")); List<String> jsonKeys = new ArrayList<>(); String jsonString; Paragraph emptyLines; jsonString = PdfUtility.initiliazeJson(br); JSONObject obj = new JSONObject(jsonString); jsonKeys.add(obj.getJSONObject("license_register_request").getString("head1")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("head2")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("head3")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("head4")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("introduction")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text1") + infoList.get(0)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text2") + infoList.get(1)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text3") + infoList.get(2)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text4") + infoList.get(3)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text5") + infoList.get(4)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text6") + infoList.get(5)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text7") + infoList.get(6)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text8") + infoList.get(7)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text9") + infoList.get(8)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text10") + infoList.get(9)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text11") + infoList.get(10)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text12") + infoList.get(11)); jsonKeys.add(obj.getJSONObject("license_register_request").getString("text13")); jsonKeys.add(obj.getJSONObject("license_register_request").getString("final")); /** * Generate the document with the content extracted from Json */ Document document = PdfUtility.initializeDocument(filePath); String paragraphElem = PdfUtility.concatenateString(jsonKeys.get(0), jsonKeys.get(1)); Paragraph paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(2)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(3)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); emptyLines = PdfUtility.addEmptyLine(3); document.add(emptyLines); PdfUtility.addTitle(document, jsonKeys.get(4)); emptyLines = PdfUtility.addEmptyLine(2); document.add(emptyLines); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(5)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(6)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(7)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(8), jsonKeys.get(9)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(10), jsonKeys.get(11)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(12), jsonKeys.get(13)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); PdfUtility.addEmptyLine(7); document.add(emptyLines); document.add(emptyLines); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(14)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); PdfUtility.addEmptyLine(3); document.add(emptyLines); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(15)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); PdfUtility.addEmptyLine(7); document.add(emptyLines); document.add(emptyLines); document.add(emptyLines); paragraphElem = PdfUtility.concatenateString(jsonKeys.get(16), jsonKeys.get(17)); paragraph = new Paragraph(paragraphElem, PdfUtility.catFont); document.add(paragraph); PdfUtility.addEmptyLine(7); document.add(emptyLines); document.add(emptyLines); PdfUtility.addFooter(document, jsonKeys.get(18)); PdfUtility.finalizeDocument(document); }
From source file:com.elsys.generator.NewPdfGenerator.java
private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);//from w ww . jav a2 s . c om // Lets write a big header preface.add(new Paragraph("Bitwise operations", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); document.add(preface); // Start a new page document.newPage(); }