List of usage examples for com.itextpdf.text.pdf PdfWriter setBoxSize
public void setBoxSize(final String boxName, final Rectangle size)
From source file:fenix.planner.pdf.PDFGenerator.java
License:Open Source License
public void generate(OutputStream output) { final Rectangle pageSize = PageSize.A4; final ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream(); document = new Document(pageSize, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN); try {/*from w w w . jav a 2 s . c om*/ final PdfWriter writer = PdfWriter.getInstance(document, outputBuffer); writer.setBoxSize("art", new Rectangle(ART_BOX_LEFT_MARGIN, ART_BOX_BOTTOM_MARGIN, pageSize.getRight() - ART_BOX_RIGHT_MARGIN, pageSize.getTop() - ART_BOX_TOP_MARGIN)); writer.setPageEvent(new HeaderFooter()); document.open(); createAndAddForeword(); createAndAddEventTable(); createAndAddAfterword(); createAndAddOrganizerTable(); document.close(); writer.close(); // Loop through the document again to add the missing page numbers document = new Document(); final PdfCopy copy = new PdfCopy(document, output); document.open(); final PdfReader reader = new PdfReader(outputBuffer.toByteArray()); addPageNumbers(reader, copy); document.close(); reader.close(); } catch (DocumentException | IOException ex) { throw new PDFGenerationException("Error generating PDF", ex); } }
From source file:hsa.awp.admingui.report.printer.PdfPrinter.java
License:Open Source License
private Document setUpDocument(PdfPrintable pdfPrintable) { Document document = new Document(PageSize.A4, 20, 20, 60, 50); // left,right,top,bottom PdfWriter writer = null; try {/*from ww w. j a va 2 s. c om*/ writer = PdfWriter.getInstance(document, outputStream); writer.setBoxSize("art", new Rectangle(36, 54, 559, 788)); HeaderFooter event = pdfPrintable.getPdfProperties().getHeaderFooter(); writer.setPageEvent(event); } catch (DocumentException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return document; }
From source file:ihm.panneaux.GenererPdf.java
private void initComponement() throws FileNotFoundException, DocumentException, IOException { String DEST = "devis/devis-" + devis.getNumero() + ".pdf"; OutputStream file = new FileOutputStream(new File(DEST)); com.itextpdf.text.Document document = new com.itextpdf.text.Document(); PdfWriter.getInstance((com.itextpdf.text.Document) document, file); // PAS TOUCHE PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST)); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent(); writer.setPageEvent(event);//from w w w .j av a2s . co m document.open(); PdfContentByte canvas = writer.getDirectContent(); Image logo = Image.getInstance("images/logo.png"); logo.scaleAbsolute(200, 57); // INFO DEVIS Image devisImg = Image.getInstance("images/imgDevis.png"); devisImg.scaleAbsolute(110, 34); devisImg.setAbsolutePosition((PageSize.POSTCARD.getWidth() + 150), (PageSize.POSTCARD.getHeight() - devisImg.getScaledHeight()) * 2); Font fontImgDevis = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); Phrase numeroInfo = new Phrase("Numro " + devis.getNumero(), fontImgDevis); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, numeroInfo, devisImg.getScaledWidth() + 413, devisImg.getScaledHeight() + 710, 0); Phrase dateInfo = new Phrase("Le " + devis.getDate(), fontImgDevis); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, dateInfo, devisImg.getScaledWidth() + 420, devisImg.getScaledHeight() + 695, 0); Image devisImgBordure = Image.getInstance("images/bordureDevis.png"); devisImgBordure.setAbsolutePosition((devisImg.getScaledWidth() + 318), devisImg.getScaledHeight() + 660); devisImgBordure.scaleAbsolute(120, 122); // INFO ENTREPRISE Font fontEntreprise = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD); Phrase coGerants = new Phrase("Co-grants : " + devis.getEntreprise().getCoGerant(), fontEntreprise); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, coGerants, devisImg.getScaledWidth() + 210, devisImg.getScaledHeight() + 660, 0); Phrase siege = new Phrase("Sige : " + devis.getEntreprise().getSiege(), fontEntreprise); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, siege, devisImg.getScaledWidth() + 149, devisImg.getScaledHeight() + 640, 0); Phrase tel = new Phrase("TEL : " + devis.getEntreprise().getTel(), fontEntreprise); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, tel, devisImg.getScaledWidth() + 113, devisImg.getScaledHeight() + 625, 0); Image bordureEntreprise = Image.getInstance("images/bordureEntreprise.png"); bordureEntreprise.setAbsolutePosition(devisImg.getScaledWidth() - 80, devisImg.getScaledHeight() + 610); // INFO CLIENT Font fontClient = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL); Phrase nomPrenom = new Phrase(devis.getClient().getNom() + " " + devis.getClient().getPrenom(), fontClient); Phrase commune = new Phrase(devis.getClient().getAdresse(), fontClient); Phrase adresse = new Phrase(devis.getClient().getCodePostale() + " " + devis.getClient().getCommune(), fontClient); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, nomPrenom, PageSize.A4.getWidth() - 280, devisImg.getScaledHeight() + 595, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, commune, PageSize.A4.getWidth() - 280, devisImg.getScaledHeight() + 580, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, adresse, PageSize.A4.getWidth() - 280, devisImg.getScaledHeight() + 565, 0); document.add(logo); document.add(devisImg); document.add(devisImgBordure); document.add(bordureEntreprise); // AJOUT DES DONNEES DU TABLEAUX float[] columnWidths = { 14, 3, 4, 3, 4 }; Font fontCategorie = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); fontCategorie.setColor(BaseColor.GREEN); PdfPTable table = new PdfPTable(columnWidths); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.setTotalWidth(PageSize.A4.getWidth() - 15); table.setSpacingBefore(150); table.setLockedWidth(true); Font Categorie = new Font(FontFamily.HELVETICA, 13, Font.BOLD); Font Chantier = new Font(FontFamily.HELVETICA, 11, Font.UNDERLINE); PdfPCell cellChantier = new PdfPCell(new Phrase("CHANTIER : " + chantier, Chantier)); cellChantier.setColspan(3); cellChantier.setBorder(Rectangle.NO_BORDER); table.addCell(cellChantier); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(new Phrase("Dsignation", Categorie)); PdfPCell unite = new PdfPCell(new Phrase("Unite", Categorie)); PdfPCell quantite = new PdfPCell(new Phrase("Quantite", Categorie)); PdfPCell prixht = new PdfPCell(new Phrase("Prix HT", Categorie)); PdfPCell pvtht = new PdfPCell(new Phrase("Pvt HT", Categorie)); unite.setHorizontalAlignment(Element.ALIGN_CENTER); quantite.setHorizontalAlignment(Element.ALIGN_CENTER); prixht.setHorizontalAlignment(Element.ALIGN_CENTER); pvtht.setHorizontalAlignment(Element.ALIGN_CENTER); unite.setBorder(Rectangle.NO_BORDER); quantite.setBorder(Rectangle.NO_BORDER); prixht.setBorder(Rectangle.NO_BORDER); pvtht.setBorder(Rectangle.NO_BORDER); table.addCell(unite); table.addCell(quantite); table.addCell(prixht); table.addCell(pvtht); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); double htTotalParcour = 0; double ttcTotalParcour = 0; if (this.EquipementDeChantier.isEmpty() == false) { table.addCell(new Phrase("Equipement De Chantier", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : EquipementDeChantier) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); /* BACKUP table.addCell(listeMaterielDevi.getMateriel().getNom()); table.addCell(listeMaterielDevi.getMateriel().getUnite()); table.addCell(Double.toString(listeMaterielDevi.getQuantite())); table.addCell(Double.toString(listeMaterielDevi.getMateriel().getPrix())+""); table.addCell(Double.toString(listeMaterielDevi.getPvtHT())+""); */ ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (Couverture.isEmpty() == false) { table.addCell(new Phrase("Couverture", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Couverture) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (CouvertureArdoise.isEmpty() == false) { table.addCell(new Phrase("Couverture Ardoise", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : CouvertureArdoise) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (CouvertureTuile.isEmpty() == false) { table.addCell(new Phrase("Couverture Tuile", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : CouvertureTuile) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (this.Demoussage.isEmpty() == false) { table.addCell(new Phrase("Demoussage", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Demoussage) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (this.Velux.isEmpty() == false) { table.addCell(new Phrase("Velux", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Velux) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (this.Zinguerie.isEmpty() == false) { table.addCell(new Phrase("Zinguerie", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Zinguerie) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (Plancher.isEmpty() == false) { table.addCell(new Phrase("Plancher", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Plancher) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } ttcTotalParcour = (ttcTotalParcour * devis.getTva() / 100) + ttcTotalParcour; LineDash solid = new SolidLine(); PdfPCell cell, cell2, cellSOUSTOTAL, cellhttotal, tva, getTva, totalttc, gettotalttc; table.addCell(new Phrase(" ")); table.addCell(new Phrase(" ")); table.addCell(new Phrase(" ")); table.addCell(new Phrase(" ")); cell = new PdfPCell(new Phrase("")); cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(new CustomBorder(null, null, null, solid)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.addCell(new Phrase("")); table.addCell(new Phrase("")); cellSOUSTOTAL = new PdfPCell(new Phrase("SOUS-TOTAL")); cellSOUSTOTAL.setHorizontalAlignment(Element.ALIGN_MIDDLE); cellSOUSTOTAL.setBorder(Rectangle.NO_BORDER); table.addCell(cellSOUSTOTAL); table.addCell(new Phrase("")); double prixHT_2Chiffre = Math.round((htTotalParcour) * Math.pow(10, 2)) / Math.pow(10, 2); String httotal = String.valueOf(prixHT_2Chiffre); cellhttotal = new PdfPCell(new Phrase(httotal + "")); cellhttotal.setBorder(Rectangle.NO_BORDER); cellhttotal.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(cellhttotal); table.addCell(new Phrase("")); table.addCell(new Phrase("")); tva = new PdfPCell(new Phrase("TVA")); tva.setBorder(Rectangle.NO_BORDER); tva.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(tva); getTva = new PdfPCell(new Phrase(devis.getTva() + "%")); getTva.setBorder(Rectangle.NO_BORDER); getTva.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(getTva); String tvaprix = String.valueOf(htTotalParcour * devis.getTva() / 100); double prixTVA_2Chiffre = Math.round(Double.parseDouble(tvaprix) * Math.pow(10, 2)) / Math.pow(10, 2); cell2 = new PdfPCell(new Phrase(Double.toString(prixTVA_2Chiffre) + "")); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setCellEvent(new CustomBorder(null, null, null, solid)); cell2.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell2); table.addCell(""); table.addCell(""); totalttc = new PdfPCell(new Phrase("Total TTC")); totalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE); totalttc.setBorder(PdfPCell.NO_BORDER); table.addCell(totalttc); table.addCell(""); double prixTTC_2Chiffre = Math.round(ttcTotalParcour * Math.pow(10, 2)) / Math.pow(10, 2); String ttctotal = String.valueOf(Double.toString(prixTTC_2Chiffre)); gettotalttc = new PdfPCell(new Phrase(ttctotal + "")); gettotalttc.setBorder(PdfPCell.NO_BORDER); gettotalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(gettotalttc); table.setSpacingAfter(10); document.add(table); Pattern p = Pattern.compile("[.^\\.]+"); String texte = devis.getInformationComplementaire(); Font infoComptBlue = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL); infoComptBlue.setColor(BaseColor.BLUE); Font infoComptRed = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL); infoComptRed.setColor(BaseColor.RED); Font infoComptBlack = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL); infoComptBlack.setColor(BaseColor.BLACK); Paragraph infoComp = new Paragraph(); Image BonPourAccord = null; BonPourAccord = Image.getInstance("images/BonPourAccord.png"); infoComp.setAlignment(Element.ALIGN_LEFT); BonPourAccord.setAlignment(Image.TEXTWRAP | Image.ALIGN_RIGHT); String[] phrase = p.split(texte); for (int i = 0; i < phrase.length; i++) { if (i == 0 || i == 1) { infoComp.add(new Paragraph(phrase[i], infoComptBlue)); } if (i == 2 || i == 3 || i == 4 || i == 5) { infoComp.add(new Paragraph(phrase[i], infoComptRed)); } if (i > 5 && i <= 11) infoComp.add(new Paragraph(phrase[i], infoComptBlack)); if (i > 11) infoComp.add(new Paragraph(phrase[i], infoComptRed)); } /* A OPTIMISER */ float taille_tableau = table.calculateHeights() + table.getRowHeight(table.getLastCompletedRowIndex()); if (taille_tableau > 386) { document.newPage(); } document.add(BonPourAccord); document.add(infoComp); document.close(); EnvoieDevis envoie = new EnvoieDevis(null, true, session, devis); this.CouvertureArdoise.clear(); this.CouvertureTuile.clear(); this.Demoussage.clear(); this.EquipementDeChantier.clear(); this.Velux.clear(); this.Zinguerie.clear(); this.Couverture.clear(); this.Plancher.clear(); }
From source file:Inventario.Inventario2.java
public void createDocument(String filename, String extension) throws DocumentException, FileNotFoundException { try {/*from w w w.ja v a 2s .c om*/ Document document = new Document(PageSize.LETTER, 50, 50, 85, 50); document.addAuthor("Inventario"); document.addTitle("Reporte de Inventario Compra-Venta"); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setInitialLeading(16); Rectangle rct = new Rectangle(80, 104, 500, 688); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); Paragraph parrafo2 = new Paragraph("Reportes de Inventario", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.GRAY)); parrafo2.setAlignment(0); document.add(parrafo2); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } }
From source file:memoire.Exercises.java
public void CreatePdf44(ArrayList<String> list, String nameFile) { try {//from w w w . ja va2 s . c o m com.itextpdf.text.Document document = new com.itextpdf.text.Document(com.itextpdf.text.PageSize.A4); String fileNameWithPath = "Examen00" + nameFile + ".pdf"; FileOutputStream fos = new FileOutputStream(fileNameWithPath); com.itextpdf.text.pdf.PdfWriter pdfWriter = com.itextpdf.text.pdf.PdfWriter.getInstance(document, fos); Rectangle rectangle = new Rectangle(30, 30, 550, 800); pdfWriter.setBoxSize("rectangle", rectangle); HeaderAndFooterPdfPageEventHelper headerAndFooter = new HeaderAndFooterPdfPageEventHelper(); //pdfWriter.setPageEvent(headerAndFooter); document.open(); com.itextpdf.text.html.simpleparser.HTMLWorker htmlWorker = new com.itextpdf.text.html.simpleparser.HTMLWorker( document); try { document.newPage(); //Rectangle page = document.getPageSize(); //PdfPTable head = new PdfPTable(1); //head.setHorizontalAlignment(10); // document.add(new Paragraph(Jsoup.parse(list.get(0)).text())); // headerAndFooter.onStartPage(pdfWriter, document,Jsoup.parse(list.get(0)).text()); //System.out.println(list.get(0)); for (int j = 0; j < NbrPartie + 1; j++) { // System.out.println(Jsoup.parse(list.get(j)).text()); // htmlWorker.parse(new StringReader(list.get(j))); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, new FileInputStream(list.get(j))); } //head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); //float number=page.getHeight() - document.topMargin()+ head.getTotalHeight(); //head.writeSelectedRows(0,(int)page.getWidth(), document.leftMargin(),page.getHeight() - document.topMargin()+ head.getTotalHeight(),pdfWriter.getDirectContent()); //pdfWriter.getPageNumber(); pdfWriter.flush(); document.close(); fos.close(); } catch (Exception e) { System.out.println("nnn"); JOptionPane.showMessageDialog(null, e.getMessage()); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString()); } }
From source file:modelo.plantillaPDF.java
public void pdf(int tiquet, int idOrden, String codOrden) { try {/*from ww w . ja va 2 s . co m*/ String sql = "Select * from tiquet where idorden = '" + idOrden + "' and tiquet='" + tiquet + "'"; rs = Consultar(sql); int id = 0; int numTiquet = 0; String ob = ""; tiquet verTiquet = new tiquet(); colores verColor = new colores(); String colorUno = ""; String colorDos = ""; System.out.print("id de la orden en el tiquet:" + idOrden); ArrayList<String> lista = new ArrayList<String>(); int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0, c10 = 0, c11 = 0, c12 = 0, c13 = 0, c14 = 0, c15 = 0; int c16 = 0, c17 = 0, c18 = 0, c19 = 0, c20 = 0, c21 = 0, c22 = 0, c23 = 0, c24 = 0, c25 = 0, c26 = 0, c27 = 0, c28 = 0, c29 = 0; int c30 = 0, c31 = 0, c32 = 0; //rs.last(); int cuantos = rs.getRow(); //System.out.print("puestos:" + cuantos+ "orden: " + codOrden + "tiquet: " + tiquet); //Fecha actual en formato completo: //Tue Sep 23 01:18:48 CEST 2014 Date fechaActual = new Date(); // System.out.println(fechaActual); // System.out.println("---------------------------------------------"); //Formateando la fecha: DateFormat formatoHora = new SimpleDateFormat("HH-mm-ss"); DateFormat formatoFecha = new SimpleDateFormat("yyyy-MM-dd"); DateFormat Fecha = new SimpleDateFormat("dd/MM/yyyy"); // System.out.println("Fecha: "+formatoFecha.format(fechaActual)+" Son las: "+formatoHora.format(fechaActual)); //Directorio destino para las descargas File folder = new File("c:\\seiya\\tiquets"); //Crea el directorio de destino en caso de que no exista folder.mkdirs(); String fe = Fecha.format(fechaActual); int numeroAleatorio = (int) (Math.random() * 2500 + 1); //Nombre del fichero <strong>PDF</strong> Resultante de la ejecucion String dir = "C:\\seiya\\tiquets\\Tiquet_" + tiquet + ".pdf"; ; // El archivo pdf que vamos a generar FileOutputStream fileOutputStream = new FileOutputStream(dir); //Creacion del documento con un tamao y unos margenes predeterminados Document document = new Document(PageSize.LETTER, 10, 10, 10, 1); //A DocWriter class for PDF con Java. //When this PdfWriter is added to a certain PdfDocument, //the <strong>PDF</strong> representation of every Element added to this Document will be written to the outputstream. //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // Obtener la instancia del PdfWriter PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream); //LEADING = separacion entre lineas del documento writer.setInitialLeading(16); Rectangle rct = new Rectangle(36, 54, 559, 788); //Definimos un nombre y un tamao para el PageBox los nombres posibles son: crop?, trim?, art? and bleed?. writer.setBoxSize("art", rct); //Opens the document. //You have to open the document before you can begin to add content to the body of the document. document.open(); //************************************************************** //Ejemplos de TABLE //Aadir tabla 15 columnas PdfPTable table = new PdfPTable(15); // PdfPTable tabla = new PdfPTable(15); PdfPCell celda; //Aadir CABECERA PdfPCell cell; Image image = Image.getInstance("logo/logo.png"); // String col = "jhon"; cell = new PdfPCell(image); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); cell.setRowspan(7); table.addCell(cell); cell = new PdfPCell(new Phrase("Calle 12 # 6-68 Nia Ceci")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(6); cell.setRowspan(2); table.addCell(cell); while (rs.next()) { c1 = rs.getInt(1); c2 = rs.getInt(2); c3 = rs.getInt(3); c4 = rs.getInt(4); c5 = rs.getInt(5); c6 = rs.getInt(8); c7 = rs.getInt(9); c8 = rs.getInt(10); c9 = rs.getInt(11); c10 = rs.getInt(12); c11 = rs.getInt(13); c12 = rs.getInt(14); c13 = rs.getInt(15); c14 = rs.getInt(16); c15 = rs.getInt(17); c16 = rs.getInt(18); c17 = rs.getInt(19); c18 = rs.getInt(21); c19 = rs.getInt(22); c20 = rs.getInt(23); c21 = rs.getInt(24); c22 = rs.getInt(25); c23 = rs.getInt(26); c24 = rs.getInt(28); c25 = rs.getInt(29); c26 = rs.getInt(30); c27 = rs.getInt(31); c28 = rs.getInt(32); colorUno = verColor.consultarNombreColorUno(c4); colorDos = verColor.consultarNombreColorDos(c5); ob = verTiquet.ConsultaObservacion(tiquet); System.out.print("Color Uno: " + colorUno); //cell.setBackgroundColor(BaseColor.BLUE); table.addCell(cell); cell = new PdfPCell(new Phrase("TIKET #:")); cell.setColspan(2); cell.setRowspan(2); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase("" + tiquet)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); //cell.setBackgroundColor(BaseColor.ORANGE); cell.setColspan(3); cell.setRowspan(2); table.addCell(cell); //Aadir dos filas de celdas sin formato cell = new PdfPCell(new Phrase("Tel: 5783364")); cell.setColspan(6); cell.setRowspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); //cell.setBackgroundColor(BaseColor.CYAN); table.addCell(cell); cell = new PdfPCell(new Phrase("REF:")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); //cell.setBackgroundColor(BaseColor.ORANGE); cell.setColspan(2); cell.setRowspan(2); table.addCell(cell); cell = new PdfPCell(new Phrase("" + c6)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); //cell.setBackgroundColor(BaseColor.ORANGE); cell.setColspan(3); cell.setRowspan(2); table.addCell(cell); cell = new PdfPCell(new Phrase("calzadoseiya@gmail.com")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(6); cell.setRowspan(2);//para eliminar espacio cabecera reemplazo el 2 por 3 table.addCell(cell); cell = new PdfPCell(new Phrase("PARES:")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); //cell.setBackgroundColor(BaseColor.ORANGE); cell.setColspan(2); cell.setRowspan(2); table.addCell(cell); cell = new PdfPCell(new Phrase("" + c7)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); //cell.setBackgroundColor(BaseColor.ORANGE); cell.setColspan(3); cell.setRowspan(2); table.addCell(cell); cell = new PdfPCell(new Phrase("FECHA"));//espacio intermedio cabecera cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); table.addCell(cell); cell = new PdfPCell(new Phrase(fe));//espacio intermedio cabecera cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); table.addCell(cell); cell = new PdfPCell(new Phrase("ORDEN:")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); //cell.setBackgroundColor(BaseColor.ORANGE); cell.setColspan(2); cell.setRowspan(1); table.addCell(cell); cell = new PdfPCell(new Phrase("" + codOrden)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); //cell.setBackgroundColor(BaseColor.ORANGE); cell.setColspan(3); cell.setRowspan(1); table.addCell(cell); cell = new PdfPCell(new Phrase("CORTADA")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); table.addCell(cell); cell = new PdfPCell(new Phrase("")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(11); cell.setRowspan(1); table.addCell(cell); cell = new PdfPCell(new Phrase("GUARNICION")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); table.addCell(cell); cell = new PdfPCell(new Phrase("")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(11); table.addCell(cell); cell = new PdfPCell(new Phrase("MONTADA")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); table.addCell(cell); cell = new PdfPCell(new Phrase("")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(11); table.addCell(cell); cell = new PdfPCell(new Phrase("EMPLANTILLADA")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); table.addCell(cell); cell = new PdfPCell(new Phrase("")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(11); table.addCell(cell); cell = new PdfPCell(new Phrase("COLOR 1:")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase(colorUno)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); table.addCell(cell); cell = new PdfPCell(new Phrase("COLOR 2:")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase(colorDos)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(5); table.addCell(cell); cell = new PdfPCell(new Phrase("OBSERVACION")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); cell.setRowspan(2); table.addCell(cell); cell = new PdfPCell(new Phrase(ob)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(11); cell.setRowspan(2); table.addCell(cell); table.addCell("21"); table.addCell("22"); table.addCell("23"); table.addCell("24"); table.addCell("25"); table.addCell("26"); table.addCell("27"); table.addCell("28"); table.addCell("29"); table.addCell("30"); table.addCell("31"); table.addCell("32"); table.addCell("33"); table.addCell("34"); table.addCell("35"); table.addCell(" " + c8); table.addCell(" " + c9); table.addCell(" " + c10); table.addCell(" " + c11); table.addCell(" " + c12); table.addCell(" " + c13); table.addCell(" " + c14); table.addCell(" " + c15); table.addCell(" " + c16); table.addCell(" " + c17); table.addCell(" " + c18); table.addCell(" " + c19); table.addCell(" " + c20); table.addCell(" " + c21); table.addCell(" " + c22); table.addCell("36"); table.addCell("37"); table.addCell("38"); table.addCell("39"); table.addCell("40"); table.addCell("41"); table.addCell("42"); table.addCell("43"); table.addCell("44"); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" " + c23); table.addCell(" " + c24); table.addCell(" " + c25); table.addCell(" " + c26); table.addCell(" " + c27); table.addCell(" " + c28); table.addCell(" " + c29); table.addCell(" " + c30); table.addCell(" " + c31); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); document.add(table); String cadena = ""; for (int i = 1; i <= 4; i++) { //Chunk chunkSeparador = new Chunk(SEPARADOR); // document.add(chunkSeparador); // document.add(Chunk.NEWLINE); PdfPTable tabla = new PdfPTable(15); if (i == 1) cadena = "EMPLANTILLADA"; if (i == 2) cadena = "MONTADA"; if (i == 3) { cadena = "GUARNICION"; } if (i == 4) cadena = "CORTADA"; cell = new PdfPCell( new Phrase("------------------------------------------------------------------------")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(15); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase("CALZADO SEIYA")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(5); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase(cadena)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase("TIQUET #")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase("" + tiquet)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase("PARES:")); cell.setHorizontalAlignment(Font.BOLD); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase("" + c7)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase("")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase("REF:")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase("" + c6)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setRowspan(1); tabla.addCell(cell); cell = new PdfPCell(new Phrase("COLOR 1:")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); tabla.addCell(cell); cell = new PdfPCell(new Phrase(colorUno)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); tabla.addCell(cell); cell = new PdfPCell(new Phrase("COLOR 2:")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); tabla.addCell(cell); cell = new PdfPCell(new Phrase(colorDos)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(5); tabla.addCell(cell); tabla.addCell("21"); tabla.addCell("22"); tabla.addCell("23"); tabla.addCell("24"); tabla.addCell("25"); tabla.addCell("26"); tabla.addCell("27"); tabla.addCell("28"); tabla.addCell("29"); tabla.addCell("30"); tabla.addCell("31"); tabla.addCell("32"); tabla.addCell("33"); tabla.addCell("34"); tabla.addCell("35"); tabla.addCell(" " + c8); tabla.addCell(" " + c9); tabla.addCell(" " + c10); tabla.addCell(" " + c11); tabla.addCell(" " + c12); tabla.addCell(" " + c13); tabla.addCell(" " + c14); tabla.addCell(" " + c15); tabla.addCell(" " + c16); tabla.addCell(" " + c17); tabla.addCell(" "); tabla.addCell(" " + c20); tabla.addCell(" " + c21); tabla.addCell(" " + c22); tabla.addCell(" " + c23); tabla.addCell("36"); tabla.addCell("37"); tabla.addCell("38"); tabla.addCell("39"); tabla.addCell("40"); tabla.addCell("41"); tabla.addCell("42"); tabla.addCell("43"); tabla.addCell("44"); tabla.addCell(" "); tabla.addCell(" "); tabla.addCell(" "); tabla.addCell(" "); tabla.addCell(" "); tabla.addCell(" "); tabla.addCell(" " + c24); tabla.addCell(" " + c25); tabla.addCell(" " + c26); tabla.addCell(" " + c27); tabla.addCell(" " + c28); tabla.addCell(" " + c29); tabla.addCell(" " + c30); tabla.addCell(" " + c31); tabla.addCell(" " + c32); tabla.addCell(" "); tabla.addCell(" "); tabla.addCell(" "); tabla.addCell(" "); tabla.addCell(" "); tabla.addCell(" "); document.add(tabla); } //document.add(new Paragraph(new Date().toString())); //FIN Ejemplos de TABLE //************************************************************** //************************************************************** // Cierre del documento document.close(); } } catch (Exception ex) { System.out.println(ex.getMessage()); } }
From source file:org.me.modelos.PDFHelper.java
public void tablaToPdf(JTable jTable, File pdfNewFile, String title) { try {// www . j a v a2 s. co m Font subCategoryFont = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); Document document = new Document(PageSize.LETTER.rotate()); PdfWriter writer = null; try { writer = PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile)); } catch (FileNotFoundException fileNotFoundException) { Message.showErrorMessage(fileNotFoundException.getMessage()); } writer.setBoxSize("art", new Rectangle(150, 10, 700, 580)); writer.setPageEvent(new HeaderFooterPageEvent()); document.open(); document.addTitle(title); document.addSubject("Reporte"); document.addKeywords("reportes, gestion, pdf"); document.addAuthor("Gestion de Proyectos de software"); document.addCreator("gestion de proyectos"); Paragraph parrafo = new Paragraph(title, subCategoryFont); PdfPTable table = new PdfPTable(jTable.getColumnCount()); table.setWidthPercentage(100); PdfPCell columnHeader; for (int column = 0; column < jTable.getColumnCount(); column++) { Font font = new Font(Font.FontFamily.HELVETICA); font.setColor(255, 255, 255); columnHeader = new PdfPCell(new Phrase(jTable.getColumnName(column), font)); columnHeader.setHorizontalAlignment(Element.ALIGN_LEFT); columnHeader.setBackgroundColor(new BaseColor(96, 125, 139)); table.addCell(columnHeader); } table.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); table.setHeaderRows(1); BaseColor verdad = new BaseColor(255, 255, 255); BaseColor falso = new BaseColor(214, 230, 244); boolean bandera = false; for (int row = 0; row < jTable.getRowCount(); row++) { for (int column = 0; column < jTable.getColumnCount(); column++) { if (bandera) { table.getDefaultCell().setBackgroundColor(verdad); } else { table.getDefaultCell().setBackgroundColor(falso); } table.addCell(jTable.getValueAt(row, column).toString()); bandera = !bandera; } } parrafo.add(table); document.add(parrafo); document.close(); //JOptionPane.showMessageDialog(null, "Se ha creado el pdf en " + pdfNewFile.getPath(), // "RESULTADO", JOptionPane.INFORMATION_MESSAGE); } catch (DocumentException documentException) { System.out.println("Se ha producido un error " + documentException); JOptionPane.showMessageDialog(null, "Se ha producido un error" + documentException, "ERROR", JOptionPane.ERROR_MESSAGE); } }
From source file:org.openmrs.module.laboratorymanagement.db.hibernate.LaboratoryDAOimpl.java
License:Open Source License
public void exportToPDF(HttpServletRequest request, HttpServletResponse response, List<Object[]> listOflabtest, String filename, String title, int conceptId) throws DocumentException, IOException { // TODO Auto-generated method stub Concept cpt = Context.getConceptService().getConcept(conceptId); System.out.println(">>>>>>list to export" + listOflabtest); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); response.setContentType("application/pdf"); Document document = new Document(); try {// w w w .jav a 2 s. c o m response.setHeader("Content-Disposition", "attachment; filename=\"laboratory.pdf\""); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); document.open(); writer.setBoxSize("art", PageSize.A4); float[] colsWidth = { 5f, 20f, 17f, 17f, 17f, 16f, 20f }; PdfPTable table = new PdfPTable(colsWidth); // add a title PdfPCell cell = new PdfPCell(new Paragraph("CD4 lab tests")); cell.setColspan(2); document.add(new Paragraph(" Laboratory tests:" + cpt.getName())); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); table.addCell("#"); table.addCell("GIVEN NAME"); table.addCell("FAMILY NAME"); table.addCell("TEST NAME"); table.addCell("TESTED ON"); table.addCell("LOCATION"); table.addCell("TEST RESULT"); for (int i = 0; i < listOflabtest.size(); i++) { Object[] labtest = listOflabtest.get(i); Person p = (Person) labtest[0]; Obs ob = (Obs) labtest[1]; table.addCell(i + 1 + ""); table.addCell(p.getGivenName() + ""); table.addCell(p.getFamilyName() + ""); table.addCell(ob.getConcept().getName() + ""); table.addCell(df.format(ob.getObsDatetime()) + ""); table.addCell(ob.getLocation() + ""); if (cpt.getDatatype().isNumeric()) { table.addCell(ob.getValueNumeric() + ""); } if (cpt.getDatatype().isCoded()) { table.addCell(ob.getValueCoded().getName() + ""); } if (cpt.getDatatype().isText()) { table.addCell(ob.getValueText() + ""); } if (cpt.getDatatype().isDate()) { table.addCell(df.format((ob.getValueDatetime())) + ""); } } document.add(table); document.getJavaScript_onLoad(); document.close(); // document.add(new Paragraph("Hello world")); // document.close(); } catch (DocumentException e) { } }
From source file:org.openmrs.module.laboratorymanagement.db.hibernate.LaboratoryDAOimpl.java
License:Open Source License
public void exportPatientReportToPDF(HttpServletRequest request, HttpServletResponse response, Map<ConceptName, List<Object[]>> mappedLabExam, String filename, String title, int patientId) throws DocumentException, IOException { Document document = new Document(); Patient patient = Context.getPatientService().getPatient(patientId); // List<PatientBill> patientBills = // (List<PatientBill>)request.getAttribute("reportedPatientBillsPrint"); /*/*from w w w. j a v a 2 s . c o m*/ * PatientBill pb = null; * * pb = Context.getService(BillingService.class).getPatientBill( * Integer.parseInt(request.getParameter("patientBills"))); */ /* * String filename = pb.getBeneficiary().getPatient().getPersonName() * .toString().replace(" ", "_"); filename = * pb.getBeneficiary().getPolicyIdNumber().replace(" ", "_") + "_" + * filename + ".pdf"; */ response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "report"); // file name PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); writer.setBoxSize("art", new Rectangle(0, 0, 2382, 3369)); writer.setBoxSize("art", PageSize.A4); HeaderFooterMgt event = new HeaderFooterMgt(); writer.setPageEvent(event); document.open(); document.setPageSize(PageSize.A4); // document.setPageSize(new Rectangle(0, 0, 2382, 3369)); document.addAuthor(Context.getAuthenticatedUser().getPersonName().toString());// the name of the author FontSelector fontTitle = new FontSelector(); fontTitle.addFont(new Font(FontFamily.COURIER, 10.0f, Font.ITALIC)); // Report title Chunk chk = new Chunk("Printed on : " + (new SimpleDateFormat("dd-MMM-yyyy").format(new Date()))); chk.setFont(new Font(FontFamily.COURIER, 10.0f, Font.BOLD)); Paragraph todayDate = new Paragraph(); todayDate.setAlignment(Element.ALIGN_RIGHT); todayDate.add(chk); document.add(todayDate); document.add(fontTitle.process("REPUBLIQUE DU RWANDA\n")); document.add(fontTitle.process("POLICE NATIONALE\n")); document.add(fontTitle.process("KACYIRU POLICE HOSPITAL\n")); document.add(fontTitle.process("B.P. 6183 KIGALI\n")); document.add(fontTitle.process("Tl : 584897\n")); document.add(fontTitle.process("E-mail : medical@police.gov.rw")); // End Report title document.add(new Paragraph("\n")); chk = new Chunk("Laboratory results"); chk.setFont(new Font(FontFamily.COURIER, 10.0f, Font.BOLD)); chk.setUnderline(0.2f, -2f); Paragraph pa = new Paragraph(); pa.add(chk); pa.setAlignment(Element.ALIGN_CENTER); document.add(pa); document.add(new Paragraph("\n")); document.add(fontTitle.process("Family Name: " + patient.getFamilyName() + "\n")); document.add(fontTitle.process("Given name: " + patient.getGivenName() + "\n")); document.add(fontTitle.process("Age: " + patient.getAge() + "\n")); // title row FontSelector fontTitleSelector = new FontSelector(); fontTitleSelector.addFont(new Font(FontFamily.COURIER, 9, Font.ITALIC)); // Table of identification; PdfPTable table = null; table = new PdfPTable(2); table.setWidthPercentage(100f); // tableHeader.addCell(table); // document.add(tableHeader); document.add(new Paragraph("\n")); // Table of lab report items; float[] colsWidth = { 6f, 3f, 6f }; table = new PdfPTable(colsWidth); table.setWidthPercentage(100f); BaseColor bckGroundTitle = new BaseColor(170, 170, 170); BaseColor bckGroundTitl = new BaseColor(Color.yellow); // table Header PdfPCell cell = new PdfPCell(fontTitleSelector.process("Exam")); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process("Result")); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process("Normal Range")); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); /* * cell = new PdfPCell(fontTitleSelector.process("Date ")); * cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); */ // normal row FontSelector fontselector = new FontSelector(); fontselector.addFont(new Font(FontFamily.COURIER, 8, Font.NORMAL)); // empty row FontSelector fontTotals = new FontSelector(); fontTotals.addFont(new Font(FontFamily.COURIER, 9, Font.BOLD)); // =========================================================== for (ConceptName cptName : mappedLabExam.keySet()) { cell = new PdfPCell(fontTitleSelector.process("" + cptName)); cell.setBackgroundColor(bckGroundTitl); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process("")); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process("")); table.addCell(cell); List<Object[]> labExamHistory = mappedLabExam.get(cptName); for (Object[] labExam : labExamHistory) { // table Header // Object[] labe = listOflabtest.get(i); Obs ob = (Obs) labExam[0]; cell = new PdfPCell(fontTitleSelector.process("" + ob.getConcept().getName())); table.addCell(cell); if (ob.getConcept().getDatatype().isNumeric()) { cell = new PdfPCell(fontTitleSelector.process("" + ob.getValueNumeric())); table.addCell(cell); } if (ob.getConcept().getDatatype().isCoded()) { cell = new PdfPCell(fontTitleSelector.process("" + ob.getValueCoded().getName())); table.addCell(cell); } if (ob.getConcept().getDatatype().isText()) { cell = new PdfPCell(fontTitleSelector.process("" + ob.getValueText())); table.addCell(cell); } cell = new PdfPCell(fontTitleSelector.process("" + (labExam[1] != null ? labExam[1] : "-"))); table.addCell(cell); fontselector.addFont(new Font(FontFamily.COURIER, 8, Font.NORMAL)); // empty row // FontSelector fontTotals = new FontSelector(); fontTotals.addFont(new Font(FontFamily.COURIER, 9, Font.BOLD)); } } cell = new PdfPCell(fontTitleSelector.process("Names, Signature et Stamp of Lab Chief\n" //+ Context.getAuthenticatedUser().getPersonName())); + Context.getUserService().getUser(140).getPersonName())); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // ================================================================ table.addCell(cell); document.add(table); // Table of signatures; table = new PdfPTable(2); table.setWidthPercentage(100f); cell = new PdfPCell(fontTitleSelector.process(" ")); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process( "Names, Signature and Stamp of Provider\n" + Context.getAuthenticatedUser().getPersonName())); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); document.add(table); document.close(); document.close(); }
From source file:org.openmrs.module.mohtracportal.util.FileExporter.java
License:Open Source License
/** * @param request/* w ww. j a v a2 s . c om*/ * @param response * @param res * @param filename * @param title * @param from * @param to * @param selectedUsers * @throws Exception */ public void exportToPDF(HttpServletRequest request, HttpServletResponse response, List<Object> res, String filename, String title, String from, String to, List<Integer> selectedUsers) throws Exception { SimpleDateFormat sdf = Context.getDateFormat(); Document document = new Document(); response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); // file name PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); writer.setBoxSize("art", new Rectangle(36, 54, 559, 788)); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); document.setPageSize(PageSize.A4); document.addAuthor(Context.getAuthenticatedUser().getPersonName().getFamilyName() + " " + Context.getAuthenticatedUser().getPersonName().getGivenName());// the name of the author PersonService ps = Context.getPersonService(); String users = ""; for (Integer usrId : selectedUsers) { users += ps.getPerson(usrId).getPersonName() + "; "; } FontSelector fontTitle = new FontSelector(); fontTitle.addFont(new Font(FontFamily.COURIER, 10.0f, Font.BOLD)); title = MohTracUtil.getMessage("mohtracportal.report.title", null) + " : " + title; String underLine = ""; int count = 0; while (count < title.length()) { count += 1; underLine += "_"; } document.add(fontTitle.process(title));// Report title if (from.trim().compareTo("") != 0) document.add(fontTitle .process("\n" + MohTracUtil.getMessage("mohtracportal.from", null) + " : " + from));// from if (to.trim().compareTo("") != 0) document.add( fontTitle.process("\n" + MohTracUtil.getMessage("mohtracportal.to", null) + " : " + to));// to document.add(fontTitle.process("\n" + MohTracUtil.getMessage("mohtracportal.report.created.on", null) + " : " + sdf.format(new Date())));// Report date document.add(fontTitle.process("\n" + MohTracUtil.getMessage("mohtracportal.report.created.by", null) + " : " + Context.getAuthenticatedUser().getPersonName()));// Report // author Integer numberOfPatients = res.size(); document.add(fontTitle.process("\n" + MohTracUtil.getMessage("mohtracportal.numberOfPatients", null) + " : " + numberOfPatients.toString()));// Number of patients if (users.trim().compareTo("") != 0) document.add(fontTitle.process( "\n" + MohTracUtil.getMessage("mohtracportal.patient.enterers", null) + " : " + users));// enterer(s) document.add(fontTitle.process("\n" + underLine));// Report title document.add(new Paragraph("\n\n")); boolean hasPrivToViewPatientNames = Context.getAuthenticatedUser().hasPrivilege("View Patient Names"); // PdfLine line; PdfPTable table = null; if (hasPrivToViewPatientNames == true) { float[] colsWidth = { 1.2f, 5f, 2.7f, 2.7f, 4.2f, 2.7f }; table = new PdfPTable(colsWidth); } else { float[] colsWidth = { 1.2f, 2.7f, 2.7f, 4.2f, 2.7f }; table = new PdfPTable(colsWidth); } // column number table.setTotalWidth(540f); // title row FontSelector fontTitleSelector = new FontSelector(); fontTitleSelector.addFont(new Font(FontFamily.COURIER, 9, Font.BOLD)); BaseColor bckGroundTitle = new BaseColor(170, 170, 170); // table Header PdfPCell cell = new PdfPCell( fontTitleSelector.process(MohTracUtil.getMessage("mohtracportal.report.list.no", null))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); if (hasPrivToViewPatientNames) { cell = new PdfPCell( fontTitleSelector.process(MohTracUtil.getMessage("mohtracportal.patient.names", null))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); } cell = new PdfPCell(fontTitleSelector.process(MohTracPortalTag .getIdentifierTypeNameByIdAsString("" + MohTracConfigurationUtil.getTracNetIdentifierTypeId()))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process(MohTracPortalTag.getIdentifierTypeNameByIdAsString( "" + MohTracConfigurationUtil.getLocalHealthCenterIdentifierTypeId()))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell( fontTitleSelector.process(MohTracUtil.getMessage("mohtracportal.patient.date.created", null) + "(" + Context.getDateFormat().toPattern() + ")")); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell( fontTitleSelector.process(MohTracUtil.getMessage("mohtracportal.numberOfEncounters", null))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); // normal row FontSelector fontselector = new FontSelector(); fontselector.addFont(new Font(FontFamily.COURIER, 8, Font.NORMAL)); // empty row FontSelector fontEmptyCell = new FontSelector(); fontEmptyCell.addFont(new Font(FontFamily.COURIER, 8, Font.NORMAL)); int ids = 0; for (Object patient : res) { Object[] o = (Object[]) patient; ids += 1; cell = new PdfPCell(fontselector.process(ids + "")); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); if (hasPrivToViewPatientNames) { String names = MohTracPortalTag.getPersonNames(Integer.valueOf(o[0].toString())); cell = new PdfPCell(fontselector.process(names + "")); if (names.compareTo("-") == 0) cell.setBackgroundColor(new BaseColor(224, 224, 240)); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); } String tracnetId = MohTracPortalTag.personIdentifierByPatientIdAndIdentifierTypeId( Integer.valueOf(o[0].toString()), MohTracConfigurationUtil.getTracNetIdentifierTypeId()); cell = new PdfPCell(fontselector.process(tracnetId + "")); if (tracnetId.compareTo("-") == 0) cell.setBackgroundColor(new BaseColor(224, 224, 240)); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); String cohortId = MohTracPortalTag.personIdentifierByPatientIdAndIdentifierTypeId( Integer.valueOf(o[0].toString()), MohTracConfigurationUtil.getLocalHealthCenterIdentifierTypeId()); cell = new PdfPCell(fontselector.process(cohortId + "")); if (cohortId.compareTo("-") == 0) cell.setBackgroundColor(new BaseColor(224, 224, 240)); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); cell = new PdfPCell(fontselector.process(sdf.format(o[1]) + "")); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); String numberOfEncounters = MohTracPortalTag .getNumberOfEncounterByPatient(Integer.valueOf(o[0].toString())); cell = new PdfPCell(fontselector.process(numberOfEncounters + "")); if (numberOfEncounters.compareTo("-") == 0) cell.setBackgroundColor(new BaseColor(224, 224, 240)); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); } document.add(table); document.close(); log.info("pdf file created"); }