List of usage examples for com.itextpdf.text Chunk NEWLINE
Chunk NEWLINE
To view the source code for com.itextpdf.text Chunk NEWLINE.
Click Source Link
From source file:user_details.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed int option = JOptionPane.showConfirmDialog(null, "Are you sure?"); if (option == 0) { Document document = new Document(); PdfWriter writer;/*from w w w . j a v a2 s. c o m*/ try { try { writer = PdfWriter.getInstance(document, new FileOutputStream("Your_Resume.pdf")); } catch (FileNotFoundException ex) { Logger.getLogger(user_details.class.getName()).log(Level.SEVERE, null, ex); } Font fontdesign1 = FontFactory.getFont("Times-Roman", 20, Font.BOLD); Font fontdesign2 = FontFactory.getFont("Times-Roman", 10, Font.ITALIC); Font fontdesign4 = FontFactory.getFont("Times-Roman", 12, Font.BOLD); Font fontdesign3 = FontFactory.getFont("Times-Roman", 11); document.open(); Paragraph namepara = new Paragraph(fname + " " + lname, fontdesign1); namepara.setAlignment(Element.ALIGN_CENTER); document.add(namepara); document.add(Chunk.NEWLINE); if (edu_details.equals("") || edu_details.equals("-")) { } else { Paragraph eduTitle = new Paragraph("EDUCATIONAL QUALIFICATION:", fontdesign4); document.add(eduTitle); Paragraph edupara = new Paragraph(edu_details, fontdesign3); document.add(edupara); } document.add(Chunk.NEWLINE); if (present_comp.equals("") || present_comp.equals("-")) { } else { Paragraph Present_compTitle = new Paragraph("CURRENT COMPANY AND POSITION:", fontdesign4); document.add(Present_compTitle); Paragraph Present_compPara = new Paragraph(present_comp, fontdesign3); document.add(Present_compPara); } document.add(Chunk.NEWLINE); if (past_emp.equals("") || past_emp.equals("-")) { } else { Paragraph Past_compTitle = new Paragraph("PAST EMPLOYMENT DETAILS:", fontdesign4); document.add(Past_compTitle); Paragraph Past_compPara = new Paragraph(past_emp, fontdesign3); document.add(Past_compPara); } document.add(Chunk.NEWLINE); if (key_responsibility.equals("") || key_responsibility.equals("-")) { } else { Paragraph KeyTitle = new Paragraph("KEY RESPONSIBILITIES: ", fontdesign4); document.add(KeyTitle); Paragraph Keypara = new Paragraph(key_responsibility, fontdesign3); document.add(Keypara); } document.add(Chunk.NEWLINE); if (accomplishments.equals("") || accomplishments.equals("-")) { } else { Paragraph AccTitle = new Paragraph("ACCOMPLISHMENTS AND ACHIEVEMENTS:", fontdesign4); document.add(AccTitle); Paragraph Accpara = new Paragraph(accomplishments, fontdesign3); document.add(Accpara); } document.add(Chunk.NEWLINE); if (training.equals("") || training.equals("-")) { } else { Paragraph TrainingTitle = new Paragraph("On-Job TRAININGS/SEMINARS/WORKSHOPS:", fontdesign4); document.add(TrainingTitle); Paragraph Trainingpara = new Paragraph(training, fontdesign3); document.add(Trainingpara); } document.add(Chunk.NEWLINE); Paragraph RefTitle = new Paragraph("REFERENCES:", fontdesign4); document.add(RefTitle); for (int i = 0; i < refno; i++) { Paragraph refpara = new Paragraph(i + 1 + "." + ref[i], fontdesign3); document.add(refpara); } document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); Paragraph contactpara = new Paragraph("PHONE: " + contactNo, fontdesign2); document.add(contactpara); if (fthername.equals("") || fthername.equals("-")) { } else { Paragraph fthrnamepara = new Paragraph("FATHER'S NAME: " + fthername, fontdesign2); document.add(fthrnamepara); } Paragraph dobpara = new Paragraph("DOB: " + dob, fontdesign2); document.add(dobpara); Paragraph addresspara = new Paragraph("PERMANENT ADDRESS: " + pa, fontdesign2); document.add(addresspara); document.close(); } catch (DocumentException ex) { Logger.getLogger(user_details.class.getName()).log(Level.SEVERE, null, ex); } references.dispose(); new user_details().setVisible(true); JOptionPane.showMessageDialog(null, "Congratulations! Your resume has been created. Kindly check the directory."); } else { JOptionPane.showMessageDialog(null, "Okay! You can edit your Information."); } }
From source file:airline.service.GeneratePDF.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Set content type to application / pdf //browser will open the document only if this is set response.setContentType("application/pdf"); //Get the output stream for writing PDF object OutputStream out = response.getOutputStream(); try {/*from w w w . j a v a 2 s . co m*/ RuntimeTypeAdapterFactory<Jsonable> rta = RuntimeTypeAdapterFactory.of(Jsonable.class, "_class") .registerSubtype(Reservacion.class, "Reservacion").registerSubtype(Tiquete.class, "Tiquete") .registerSubtype(Viaje.class, "Viaje"); Gson gson = new GsonBuilder().registerTypeAdapterFactory(rta).setDateFormat("dd/MM/yyyy").create(); String json; List<Viaje> viajes; String jsonReservacion = request.getParameter("reservacion"); Reservacion reservacion = gson.fromJson(jsonReservacion, Reservacion.class); String jsonViajes = request.getParameter("viajes"); viajes = gson.fromJson(jsonViajes, new TypeToken<ArrayList<Viaje>>() { }.getType()); Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter.getInstance(document, out); document.open(); document.add(new Paragraph(" FACTURA DE COMPRA")); document.add(Chunk.NEWLINE); document.add(new Paragraph("Viajes")); document.add(Chunk.NEWLINE); document.add(createViajesTable(viajes)); document.add(Chunk.NEWLINE); document.add(new Paragraph("Reservacion")); document.add(Chunk.NEWLINE); document.add(createReservacionTable(reservacion)); document.close(); } catch (DocumentException exc) { throw new IOException(exc.getMessage()); } finally { out.close(); } }
From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException { int numLines = 0; Paragraph p = new Paragraph(); if (sponsor.image != null) { Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image)); if (sponsor.imageWidth != 0) { image.scaleToFit(sponsor.imageWidth, 1000); } else if (sponsor.imageHeight != 0) { image.scaleToFit(1000, sponsor.imageHeight); }/*from ww w. ja va 2s .co m*/ Chunk imageChunk = new Chunk(image, 0, 0, true); p.add(imageChunk); } if (sponsor.twoColumns) { StringBuilder sb = new StringBuilder(); if (sponsor.name != null) { sb.append(sponsor.name); } if (sponsor.name2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.name2); } if (sponsor.address != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address); } if (sponsor.address2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address2); } p.add(Chunk.NEWLINE); p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))); numLines++; } else { if (sponsor.twoRows && sponsor.image != null) { p.add(Chunk.NEWLINE); } if (sponsor.name != null) { p.add(generateFittedChunk(sponsor.name, Font.BOLD)); numLines++; } if (sponsor.name2 != null) { p.add(Chunk.NEWLINE); p.add(generateFittedChunk(sponsor.name2, Font.BOLD)); numLines++; } if (sponsor.address != null) { p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL))); p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } if (sponsor.address2 != null) { p.add(Chunk.NEWLINE); p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } } p.setPaddingTop(0); p.setSpacingBefore(0); p.setAlignment(Element.ALIGN_CENTER); p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setFixedHeight(cellHeight); if (sponsor.twoColumns) { cell.setColspan(2); } if (sponsor.twoRows) { cell.setRowspan(2); if (sponsor.image == null) { p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f); } } cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(CELL_EVENT); cell.setPaddingBottom(4); cell.addElement(p); if (sponsor.isTodo()) { cell.setBackgroundColor(BaseColor.ORANGE); } return cell; }
From source file:bestdeal.util.genererPdf.java
public static void main(String[] args) { // - Paramtres de connexion la base de donnes Connection connection;/*ww w . ja v a 2s . com*/ String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " }, }; try { String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur"; connection = MyConnection.getInstance(); mypdf = new Document(PageSize.A4, 50, 50, 50, 50); File di = new File("C:/Voucher"); File fl[] = di.listFiles(); try { OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf")); PdfWriter.getInstance(mypdf, file); mypdf.open(); Statement stm; mypdf.addAuthor("Best Deal"); mypdf.addSubject("Voucher "); mypdf.add(new Paragraph("Socite BestDeal")); mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT ")); mypdf.add(new Paragraph("TEL : xx xxx xxx")); mypdf.add(new Paragraph("FAX : xx xxx xxx")); mypdf.add(new Paragraph( " " + new Date().toString())); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" " + "Voucher N'01", FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC))); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph("CLIENT :", FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC))); try { stm = connection.createStatement(); ResultSet rs = stm.executeQuery(requete); while (rs.next()) { // add a country to the document as a Chunk //mypdf.add(new Chunk(rs.getString("quantite"))); Phrase p = new Phrase("Nom: "); Phrase p2 = new Phrase(new Chunk(rs.getString("nom"))); Paragraph pa = new Paragraph(); pa.add(p); pa.add(p2); mypdf.add(pa); Phrase p3 = new Phrase("Prenom: "); Phrase p4 = new Phrase(new Chunk(rs.getString("prenom"))); Paragraph pa1 = new Paragraph(); pa1.add(p3); pa1.add(p4); mypdf.add(pa1); Phrase p5 = new Phrase("Adresse: "); Phrase p6 = new Phrase(new Chunk(rs.getString("adresse"))); Paragraph pa2 = new Paragraph(); pa2.add(p5); pa2.add(p6); mypdf.add(pa2); Phrase p7 = new Phrase("Tlphone: "); Phrase p8 = new Phrase(new Chunk(rs.getString("telephone"))); Paragraph pa3 = new Paragraph(); pa3.add(p7); pa3.add(p8); mypdf.add(pa3); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph("Vendeur :", FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC))); Phrase p9 = new Phrase("Nom: "); Phrase p10 = new Phrase(new Chunk(rs.getString("nom"))); Paragraph pa4 = new Paragraph(); pa4.add(p9); pa4.add(p10); mypdf.add(pa4); Phrase p11 = new Phrase("Prnom: "); Phrase p12 = new Phrase(new Chunk(rs.getString("prenom"))); Paragraph pa5 = new Paragraph(); pa5.add(p11); pa5.add(p12); mypdf.add(pa5); Phrase p13 = new Phrase("Tlphone: "); Phrase p14 = new Phrase(new Chunk(rs.getString("telephone"))); Paragraph pa6 = new Paragraph(); pa6.add(p13); pa6.add(p14); mypdf.add(pa6); Phrase p15 = new Phrase("Adresse: "); Phrase p16 = new Phrase(new Chunk(rs.getString("adresse"))); Paragraph pa7 = new Paragraph(); pa7.add(p15); pa7.add(p16); mypdf.add(pa7); Phrase p17 = new Phrase("Email: "); Phrase p18 = new Phrase(new Chunk(rs.getString("email"))); Paragraph pa8 = new Paragraph(); pa8.add(p17); pa8.add(p18); mypdf.add(pa8); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); for (int i = 0; i < rs.getRow(); i++) { for (int j = 0; j < data[i].length - 1; j++) { data[i][j] = rs.getString(j + 9); // if (j==3) // data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+""; } } for (int i = 0; i < rs.getRow(); i++) { float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim()); data[i][4] = s + ""; } //mypdf.add(new Phrase("nom")); //mypdf.add(new Chunk(rs.getString("nom"))); //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom")))); //mypdf.add(new Chunk(" ")); //Chunk id = new Chunk(rs.getString("id")); // with a background color //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f); // and a text rise //id.setTextRise(6); // mypdf.add(id); mypdf.add(Chunk.NEWLINE); } } catch (SQLException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } // mypdf.add(new Paragraph("Nom ")); // mypdf.add(new Paragraph("Prenom ")); // mypdf.add(new Paragraph("Adresse ")); //mypdf.add(new Paragraph("Tlphone ")); // mypdf.add(new Paragraph("Nom ")); // mypdf.add(new Paragraph("Nom de la socit ")); // mypdf.add(new Paragraph("Adresse ")); // mypdf.add(new Paragraph("Tlphone ")); // mypdf.add(new Paragraph(" ")); String[] headers = new String[] { " Id_deal", " Nom Deal", " Quantit", " Prix unitaire", " Prix total" }; PdfPTable table = new PdfPTable(headers.length); for (int i = 0; i < headers.length; i++) { String header = headers[i]; PdfPCell cell = new PdfPCell(); cell.setGrayFill(0.9f); cell.setPhrase(new Phrase(header.toUpperCase())); table.addCell(cell); } table.completeRow(); for (int i = 0; i < data.length; i++) { for (int j = 0; j < data[i].length; j++) { String datum = data[i][j]; PdfPCell cell = new PdfPCell(); cell.setPhrase(new Phrase(datum.toUpperCase())); table.addCell(cell); } table.completeRow(); } mypdf.add(table); } catch (FileNotFoundException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph( "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ", FontFactory.getFont(null, 9, Font.NORMAL))); mypdf.add(new Paragraph( " Merci pour votre confiance", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC))); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.close(); } catch (DocumentException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.ainfosec.macresponse.report.PdfGenerator.java
License:Open Source License
private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line preface.add(Chunk.NEWLINE); // Lets write a big header preface.add(new Paragraph("MAC Response", chapterTitleFont)); preface.add(Chunk.NEWLINE);//from w ww . j a va 2 s .c o m // 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$ contentFont)); // preface.add(Chunk.NEWLINE); // preface.add(Chunk.NEWLINE); // preface.add(Chunk.NEWLINE); // preface.add(new Paragraph( // "This document describes something which is very important ", // contentFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * /* w w w.j a v a 2 s . c o m*/ * PDF Title Page * * @param doc * @param writer */ public static void setTitleMainPage(Document doc, PdfWriter writer, PDFCommonEventHelper event, Upload upload) throws Exception { Font fnTitle = new Font(bfKorean, 20, Font.BOLD); Font fnLabel = new Font(bfKorean, 11, Font.BOLD); Font fnText = new Font(bfKorean, 11); LineSeparator UNDERLINE = new LineSeparator(1, 80, null, com.itextpdf.text.Element.ALIGN_CENTER, -5); doc.newPage(); doc.add(Chunk.NEWLINE); event.setTitleFlag(true); int toc = writer.getPageNumber(); Image img = Image.getInstance(PDFDocGenerator.class.getResource("/image/title.gif")); img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); img.scalePercent(80, 80); doc.add(img); Paragraph titlePh = new Paragraph(MessageUtil.getMessage("pdf.message.main.title"), fnTitle); titlePh.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); titlePh.setSpacingBefore(50); titlePh.setSpacingAfter(30); doc.add(titlePh); doc.add(UNDERLINE); PdfPTable t1 = new PdfPTable(2); t1.setSpacingBefore(20); t1.setWidths(new int[] { 110, 290 }); t1.getDefaultCell().setBorder(0); t1.getDefaultCell().setFixedHeight(32); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_name"), fnLabel)); t1.addCell(new Phrase(upload.getProjectNm(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.department"), fnLabel)); t1.addCell(new Phrase(upload.getDepartment(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.focus_name"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.focus_name"), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.product"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.product", upload.getBeforeWas(), upload.getAfterWas()), fnText)); doc.add(t1); doc.add(UNDERLINE); Paragraph executedPh = new Paragraph(MessageUtil.getMessage("pdf.message.main.label.executed"), fnLabel); executedPh.setSpacingBefore(30); executedPh.setSpacingAfter(15); executedPh.setIndentationLeft(50); doc.add(executedPh); PdfPTable t2 = new PdfPTable(2); t2.getDefaultCell().setFixedHeight(28); t2.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); t2.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.owner"), fnLabel)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_role"), fnLabel)); t2.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); t2.addCell(new Phrase(upload.getPerson(), fnText)); t2.addCell(new Phrase(upload.getOrgRole(), fnText)); doc.add(t2); doc.newPage(); int total = writer.reorderPages(null); int[] order = new int[total]; for (int i = 0; i < total; i++) { order[i] = i + toc; if (order[i] > total) order[i] -= total; } // apply the new order writer.reorderPages(order); }
From source file:com.chaschev.itext.ColumnTextBuilder.java
License:Apache License
public ColumnTextBuilder newLine() { columnText.addText(Chunk.NEWLINE); return this; }
From source file:com.dexter.fms.mbean.ReportsMBean.java
@SuppressWarnings("unchecked") public void createPDF(int type, String filename, int pageType) { try {/* ww w . j a v a2 s.c o m*/ 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 {//from w w w . j a v a2s . 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.gadroves.gsisinve.controller.FacturarController.java
void PrintToPDF(TbFacturaVenta facturaVenta, TbCLienteFactura cLienteFactura) throws DocumentException, IOException { Font header = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font normalBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font normal = new Font(Font.FontFamily.HELVETICA, 12); String fileName = "Factura_" + facturaVenta.getId() + ".pdf"; // step 1/* w w w . j av a 2 s. c o m*/ Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(fileName)); // step 3 document.open(); // step 4 document.add(new Paragraph("Gadroves S.A Factura De Venta", header)); document.add(new Paragraph(" ")); document.add(new Paragraph("Factura N" + facturaVenta.getId(), normalBold)); document.add(new Chunk("Cliente: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getName(), normal)); document.add(new Paragraph()); document.add(new Chunk("Direccin: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getAddress(), normal)); document.add(new Paragraph()); document.add(new Chunk("Identificacion: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getId(), normal)); document.add(new Paragraph()); document.add(new Chunk("Credito: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(Boolean.FALSE.toString(), normal)); document.add(new Paragraph()); for (int i = 0; i < 3; i++) document.add(new Paragraph(" ")); createItemsTable(document, facturaVenta); document.add(new Paragraph(" ")); Paragraph subs = new Paragraph(); subs.setAlignment(Element.ALIGN_RIGHT); subs.setIndentationRight(40); subs.add(new Chunk("Subtotal: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getSub())))); subs.add(Chunk.NEWLINE); subs.add(new Chunk( "Impuestos: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getImpuestos())))); subs.add(Chunk.NEWLINE); subs.add(new Chunk( "Total: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getTotal())))); subs.add(Chunk.NEWLINE); document.add(subs); // step 5 document.close(); Desktop.getDesktop().open(new File(fileName)); }