List of usage examples for com.itextpdf.text BaseColor BLUE
BaseColor BLUE
To view the source code for com.itextpdf.text BaseColor BLUE.
Click Source Link
From source file:GUI.GestionProjects.java
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed String IMAGE1 = lblPathImage.getText(); Font red = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.RED); Chunk redText = new Chunk("Les information relatif au Projet : ", red); Font blue = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.BLUE); Document document = new Document(); java.util.Date utilStartDate = jdateDeadLine.getDate(); java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime()); try {//from w w w.ja va 2 s . c o m PdfWriter.getInstance(document, new FileOutputStream("Report.pdf")); document.open(); Paragraph p1 = new Paragraph(); p1.add(redText); p1.add(txtTitreProjet.getText()); Chunk txtdesc = new Chunk("Decription du Projet: ", red); Paragraph p2 = new Paragraph(); p2.add(txtdesc); p2.add(txtDescriptionProjet.getText()); Chunk txtcat = new Chunk("Catgorie du Projet: ", red); Paragraph p3 = new Paragraph(); p3.add(txtcat); p3.add(combo_Cat.getSelectedItem().toString()); Chunk txtfin = new Chunk("Mode de finnancement du Projet: ", red); Paragraph p4 = new Paragraph(); p4.add(txtfin); p4.add(ComboFinnancementProjet.getSelectedItem().toString()); Chunk txtdate = new Chunk("Date DeadLine Projet: ", red); Paragraph p5 = new Paragraph(); p5.add(txtdate); p5.add(sqlStartDate.toString()); p1.setSpacingAfter(25); p1.setSpacingBefore(25); p1.setAlignment(Element.ALIGN_CENTER); p1.setIndentationLeft(50); p1.setIndentationRight(50); document.add(p1); document.add(p2); document.add(p3); document.add(p4); document.add(p5); if (Desktop.isDesktopSupported()) { try { File myFile = new File("Report.pdf"); Desktop.getDesktop().open(myFile); } catch (IOException ex) { // no application registered for PDFs } } } catch (Exception e) { System.out.println(e); } document.close(); // TODO add your handling code here: }
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);//w w w. ja v a 2 s.c om 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:info.longnetpro.examples.PdfLibExamples.java
public static void generatePdf() throws DocumentException, URISyntaxException, MalformedURLException, IOException { String licFile = getLicenseFilePath(); loadLicenseFile(licFile);// ww w . ja va2 s . c om String dest = getTargetFilePath(); Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(dest)); Rectangle pageSize = PageSize.LETTER; Rectangle rect = new Rectangle(0f, 0f, 50f, 100f); rect.setBorder(15); rect.setBorderColor(BaseColor.RED); rect.setBorderWidth(.5f); rect.setBackgroundColor(BaseColor.BLUE); doc.setPageSize(pageSize); doc.open(); Page page = new Page(pageSize.getWidth(), pageSize.getHeight()); ContentBox rpage = page.margin(new Float[] { 10f, 50f, 10f, 50f }); for (Anchor anchor : Anchor.values()) { ContentBox box = new ContentBox(50f, 100f); float offx = anchor.equals(Anchor.CENTER) ? -50f : 0f; float offy = anchor.equals(Anchor.CENTER) ? -50f : 0f; ContentBox rr = anchor.anchorElement(rpage, box, offx, offy); if (anchor.equals(Anchor.BOTTOM_LEFT)) { float[] dim = box.scaleByPercentage(0.5f); //rr = rr.reposition(dim[0], dim[1], Anchor.TOP_RIGHT); } rect.setLeft(rr.getLeft()); rect.setBottom(rr.getBottom()); rect.setRight(rr.getRight()); rect.setTop(rr.getTop()); doc.add(rect); } String imageFile = getImageFilePath(); Image image = Image.getInstance(imageFile); float width = Measurement.dotsToUserUnits(image.getWidth(), 1200); float height = Measurement.dotsToUserUnits(image.getHeight(), 1200); System.out.println(width + " " + height); ContentBox img = Anchor.BOTTOM_LEFT.anchorElement(rpage, width, height); image.scaleToFit(width, height); image.setAbsolutePosition(img.getLeft(), img.getBottom()); System.out.println(image.getWidth() + " " + image.getHeight()); System.out.println(image.getAbsoluteX() + " " + image.getAbsoluteY()); doc.add(image); doc.close(); }
From source file:informes.InformeActividad.java
public void generarInforme() { try {/*from w w w. j av a 2s . c o m*/ Document document = new Document(); Paragraph ParrafoHoja = new Paragraph(); String parrafo = this.getDescripsion(); String ruta = ec.getRealPath("img"); PdfWriter.getInstance(document, new FileOutputStream(ruta + "\\" + "actividades.pdf")); Font fuente = new Font(); fuente.setColor(255, 0, 0); fuente.setSize(30); Font fuente3 = new Font(); fuente3.setColor(255, 255, 255); fuente3.setSize(30); PdfPTable tabla2 = new PdfPTable(1); tabla2.getDefaultCell().setBackgroundColor(BaseColor.BLUE); tabla2.setWidthPercentage(110f); tabla2.addCell(new Paragraph("UNIDAD EDUCATIVA", fuente3)); tabla2.addCell(new Paragraph("'MISIONEROS OBLATOS'", fuente3)); Paragraph p = new Paragraph(parrafo, fuente); agregarLineasEnBlanco(ParrafoHoja, 3); document.open(); document.add(tabla2); document.add(p); document.add(ParrafoHoja); Font fuente1 = new Font(); fuente1.setColor(0, 0, 0); fuente1.setSize(5); Font fuente2 = new Font(); fuente2.setColor(255, 0, 0); fuente2.setSize(5); PdfPTable tabla = new PdfPTable(5); tabla.setWidthPercentage(107f); Font fuente4 = new Font(); fuente4.setColor(0, 0, 0); fuente4.setSize(8); // Paragraph p4 = new Paragraph(parrafo, fuente4); //tabla.addCell(new Paragraph("OBJESTRATEGICO",fuente2)); tabla.addCell(new Paragraph("RESPONSABLE", fuente2)); tabla.addCell(new Paragraph("CONTROL", fuente2)); tabla.addCell(new Paragraph("FECHA INICIO", fuente2)); tabla.addCell(new Paragraph("FECHA FIN", fuente2)); tabla.addCell(new Paragraph("AVANCE", fuente2)); int cont = 0; tabla.getDefaultCell().setBackgroundColor(BaseColor.WHITE); for (int i = 0; i < this.getItems().size(); i++) { // Paragraph p1 =new Paragraph(parrafo,fuente); String num = String.valueOf(i); Paragraph p4 = new Paragraph("Objetivo: " + num + " --> " + this.getItems().get(i).getNombre(), fuente4); document.add(p4); Paragraph p8 = new Paragraph(); agregarLineasEnBlanco(p8, 1); document.add(p8); for (Actividad a : this.getItems().get(i).getActividadCollection()) { System.out.println(""); if (a.getIdObjetivoEstrategico() .getIdObjetivoEstrategico() == (this.getItems().get(i).getIdObjetivoEstrategico())) { cont = 1; tabla.addCell(new Paragraph(a.getIdObjetivoEstrategico().getNombre(), fuente1)); tabla.addCell(new Paragraph(a.getIdPersonaResponsable().getNombre(), fuente1)); tabla.addCell(new Paragraph(a.getControl(), fuente1)); tabla.addCell(new Paragraph(a.getFechaInicio().toString(), fuente1)); tabla.addCell(new Paragraph(a.getFechaFin().toString(), fuente1)); tabla.addCell(new Paragraph(a.getAvance().toString(), fuente1)); } } Paragraph p7 = new Paragraph(); if (cont == 1) { document.add(tabla); cont = 0; agregarLineasEnBlanco(p7, 2); document.add(p7); } else { Font fuente5 = new Font(); fuente5.setColor(0, 0, 255); fuente5.setSize(10); document.add(new Paragraph("No contiene actividades registradas", fuente5)); agregarLineasEnBlanco(p7, 2); document.add(p7); } } document.add(new Paragraph(new Date().toString())); document.close(); System.out.println("aquiiiiii"); } catch (FileNotFoundException ex) { Logger.getLogger(InformeActividad.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(InformeActividad.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(InformeActividad.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:informes.InformeObjEs.java
public void generarInforme() { try {//from w w w . j ava 2 s .c om Document document = new Document(); Paragraph ParrafoHoja = new Paragraph(); String parrafo = this.getDescripsion(); String ruta = ec.getRealPath("img"); PdfWriter.getInstance(document, new FileOutputStream(ruta + "\\" + "objEstra.pdf")); Font fuente = new Font(); fuente.setColor(255, 0, 0); fuente.setSize(30); Font fuente3 = new Font(); fuente3.setColor(255, 255, 255); fuente3.setSize(30); PdfPTable tabla2 = new PdfPTable(1); tabla2.getDefaultCell().setBackgroundColor(BaseColor.BLUE); tabla2.setWidthPercentage(110f); tabla2.addCell(new Paragraph("UNIDAD EDUCATIVA", fuente3)); tabla2.addCell(new Paragraph("'MISIONEROS OBLATOS'", fuente3)); Paragraph p = new Paragraph(parrafo, fuente); agregarLineasEnBlanco(ParrafoHoja, 3); document.open(); document.add(tabla2); document.add(p); document.add(ParrafoHoja); Font fuente1 = new Font(); fuente1.setColor(0, 0, 0); fuente1.setSize(5); Font fuente2 = new Font(); fuente2.setColor(255, 0, 0); fuente2.setSize(5); PdfPTable tabla = new PdfPTable(8); tabla.setWidthPercentage(107f); tabla.addCell(new Paragraph("OBJETIVO", fuente2)); tabla.addCell(new Paragraph("META", fuente2)); tabla.addCell(new Paragraph("DEFINICION", fuente2)); tabla.addCell(new Paragraph("ACLARACION", fuente2)); tabla.addCell(new Paragraph("CONCEPTUALIZACION", fuente2)); tabla.addCell(new Paragraph("INDICADOR", fuente2)); tabla.addCell(new Paragraph("FORMULA", fuente2)); tabla.addCell(new Paragraph("UNIDADES", fuente2)); tabla.getDefaultCell().setBackgroundColor(BaseColor.WHITE); for (int i = 0; i < this.getItems().size(); i++) { // Paragraph p1 =new Paragraph(parrafo,fuente); System.out.println("aquiiiiiiiiiiii" + this.getItems().get(i).getSemaforo()); tabla.addCell(new Paragraph(this.getItems().get(i).getObjetivoestrategico().getNombre(), fuente1)); tabla.addCell(new Paragraph(this.getItems().get(i).getMeta(), fuente1)); tabla.addCell(new Paragraph(this.getItems().get(i).getDefinicion(), fuente1)); tabla.addCell(new Paragraph(this.getItems().get(i).getAclaracion(), fuente1)); tabla.addCell(new Paragraph(this.getItems().get(i).getConceptualizacion(), fuente1)); tabla.addCell(new Paragraph(this.getItems().get(i).getIndicador().getNombre(), fuente1)); tabla.addCell(new Paragraph(this.getItems().get(i).getIndicador().getFormula(), fuente1)); tabla.addCell(new Paragraph(String.valueOf(this.getItems().get(i).getIndicador().getUnidades()), fuente1)); } document.add(tabla); document.add(new Paragraph(new Date().toString())); document.close(); System.out.println("aquiiiiii"); } catch (FileNotFoundException ex) { Logger.getLogger(InformeObjEs.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(InformeObjEs.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(InformeObjEs.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Measurment_Result_Record.MeasurmentSetup.java
private void jMenuItem_exportpdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_exportpdfActionPerformed // TODO add your handling code here: // TODO add your handling code here: try {/*from ww w. ja v a 2s.co m*/ // TODO add your handling code here: JFileChooser fchooser = new JFileChooser(); int status = fchooser.showSaveDialog(null); if (status != JFileChooser.APPROVE_OPTION) return; fchooser.setDialogTitle("Save the Measurment result to pdf."); File selectedF = fchooser.getSelectedFile(); String filename = selectedF.getAbsolutePath(); //get the file path to save the pdf Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf")); document.open(); //add the IPELS logo and title int size = 30; com.itextpdf.text.Font titleFont; titleFont = FontFactory.getFont(FontFactory.TIMES_BOLD, size, com.itextpdf.text.Font.BOLD, BaseColor.BLUE); Paragraph ipels = new Paragraph("IPELS", titleFont); ipels.setAlignment(Element.ALIGN_CENTER); document.add(ipels); titleFont.setSize(25); Paragraph para = new Paragraph("Measurment result \n ", titleFont); para.setAlignment(Element.ALIGN_CENTER); document.add(para); //loop through all the measurmentsetups tables and add each of them to the document for (MeasurmentSetup mesSetup : this.presenter.allMeasurmentSetups) { addResultTablesTotheDocument(document, mesSetup.recordTablePreview, mesSetup.getMeasurmentTitle()); } //close the document document.close(); //preview the document Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filename + ".pdf"); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Save to pdf", JOptionPane.ERROR_MESSAGE); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Save to pdf", JOptionPane.ERROR_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "opening pdf", JOptionPane.ERROR_MESSAGE); } }
From source file:Model.MyFontSelector.java
License:Open Source License
/** * Inicializa as fontes/* w ww . j a v a 2 s.c o m*/ * Initialize the fonts * @param baseFontList A List with the BaseFonts */ private void initFonts(ArrayList<BaseFont> baseFontList) { FontSelector fontSelectorTitle = new FontSelector(); FontSelector fontSelectorBlue = new FontSelector(); FontSelector fontSelectorGreen = new FontSelector(); FontSelector fontSelectorRed = new FontSelector(); FontSelector fontSelectorBlack = new FontSelector(); for (BaseFont bf : baseFontList) { Font TITLE = new Font(bf, 16, Font.BOLD, BaseColor.BLACK); Font BLUE = new Font(bf, 14, Font.NORMAL, BaseColor.BLUE); Font GREEN = new Font(bf, 14, Font.NORMAL, new BaseColor(8, 138, 75)); Font RED = new Font(bf, 14, Font.NORMAL, BaseColor.RED); Font BLACK = new Font(bf, 14, Font.NORMAL, BaseColor.BLACK); fontSelectorTitle.addFont(TITLE); fontSelectorBlue.addFont(BLUE); fontSelectorGreen.addFont(GREEN); fontSelectorRed.addFont(RED); fontSelectorBlack.addFont(BLACK); } fontSelectors.put("TITLE", fontSelectorTitle); fontSelectors.put("BLUE", fontSelectorBlue); fontSelectors.put("GREEN", fontSelectorGreen); fontSelectors.put("RED", fontSelectorRed); fontSelectors.put("BLACK", fontSelectorBlack); }
From source file:org.primaresearch.pdf.PageToPdfConverter.java
License:Apache License
/** * Returns the correct stroke colour for the given layout object type (e.g. blue for text region). *//*from w ww . j a v a2 s . c o m*/ private BaseColor getOutlineColor(ContentType type) { if (type == LowLevelTextType.TextLine) return new BaseColor(50, 205, 50); else if (type == LowLevelTextType.Word) return new BaseColor(178, 34, 34); else if (type == LowLevelTextType.Glyph) return new BaseColor(46, 139, 8); else if (type == RegionType.TextRegion) return new BaseColor(0, 0, 255); else if (type == RegionType.ChartRegion) return new BaseColor(128, 0, 128); else if (type == RegionType.GraphicRegion) return new BaseColor(0, 128, 0); else if (type == RegionType.ImageRegion) return new BaseColor(0, 206, 209); else if (type == RegionType.LineDrawingRegion) return new BaseColor(184, 134, 11); else if (type == RegionType.MathsRegion) return new BaseColor(0, 191, 255); else if (type == RegionType.NoiseRegion) return new BaseColor(255, 0, 0); else if (type == RegionType.SeparatorRegion) return new BaseColor(255, 0, 255); else if (type == RegionType.TableRegion) return new BaseColor(139, 69, 19); else if (type == RegionType.AdvertRegion) return new BaseColor(70, 130, 180); else if (type == RegionType.ChemRegion) return new BaseColor(255, 140, 0); else if (type == RegionType.MusicRegion) return new BaseColor(148, 0, 211); return BaseColor.BLUE; }
From source file:org.smap.sdal.managers.PDFSurveyManager.java
License:Open Source License
public String createPdf(OutputStream outputStream, String basePath, String serverRoot, String remoteUser, String language, boolean generateBlank, String filename, boolean landscape, // Set true if landscape HttpServletResponse response) throws Exception { if (language != null) { language = language.replace("'", "''"); // Escape apostrophes } else {/*from w w w. j av a 2s. c o m*/ language = "none"; } mExcludeEmpty = survey.exclude_empty; User user = null; ServerManager serverManager = new ServerManager(); ServerData serverData = serverManager.getServer(sd, localisation); UserManager um = new UserManager(localisation); int[] repIndexes = new int[20]; // Assume repeats don't go deeper than 20 levels Document document = null; PdfWriter writer = null; PdfReader reader = null; PdfStamper stamper = null; try { // Get fonts and embed them String os = System.getProperty("os.name"); log.info("Operating System:" + os); if (os.startsWith("Mac")) { FontFactory.register("/Library/Fonts/fontawesome-webfont.ttf", "Symbols"); //FontFactory.register("/Library/Fonts/Arial Unicode.ttf", "default"); FontFactory.register("/Library/Fonts/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/Library/Fonts/NotoSans-Regular.ttf", "notosans"); FontFactory.register("/Library/Fonts/NotoSans-Bold.ttf", "notosansbold"); FontFactory.register("/Library/Fonts/NotoSansBengali-Regular.ttf", "bengali"); FontFactory.register("/Library/Fonts/NotoSansBengali-Bold.ttf", "bengalibold"); } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0) { // Linux / Unix FontFactory.register("/usr/share/fonts/truetype/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/usr/share/fonts/truetype/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Regular.ttf", "notosans"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Bold.ttf", "notosansbold"); FontFactory.register("/usr/share/fonts/truetype/NotoSansBengali-Regular.ttf", "bengali"); FontFactory.register("/usr/share/fonts/truetype/NotoSansBengali-Bold.ttf", "bengalibold"); } Symbols = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFontLink = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFont = FontFactory.getFont("notosans", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); defaultFontBold = FontFactory.getFont("notosansbold", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); arabicFont = FontFactory.getFont("arabic", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); bengaliFont = FontFactory.getFont("bengali", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); bengaliFontBold = FontFactory.getFont("bengalibold", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); defaultFontLink.setColor(BaseColor.BLUE); /* * Get the results and details of the user that submitted the survey */ log.info("User Ident who submitted the survey: " + survey.instance.user); String userName = survey.instance.user; if (userName == null) { userName = remoteUser; } if (userName != null) { user = um.getByIdent(sd, userName); } // If a filename was not specified then get one from the survey data // This filename is returned to the calling program so that it can be used as a permanent name for the temporary file created here // If the PDF is to be returned in an http response then the header is set now before writing to the output stream log.info("Filename passed to createPDF is: " + filename); if (filename == null) { filename = survey.getInstanceName() + ".pdf"; } else { if (!filename.endsWith(".pdf")) { filename += ".pdf"; } } // If the PDF is to be returned in an http response then set the file name now if (response != null) { log.info("Setting filename to: " + filename); GeneralUtilityMethods.setFilenameInResponse(filename, response); } /* * Get a template for the PDF report if it exists * The template name will be the same as the XLS form name but with an extension of pdf */ File templateFile = GeneralUtilityMethods.getPdfTemplate(basePath, survey.displayName, survey.p_id); /* * Get dependencies between Display Items, for example if a question result should be added to another * question's results */ GlobalVariables gv = new GlobalVariables(); if (!generateBlank) { for (int i = 0; i < survey.instance.results.size(); i++) { getDependencies(gv, survey.instance.results.get(i), survey, i); } } gv.mapbox_key = serverData.mapbox_default; int oId = GeneralUtilityMethods.getOrganisationId(sd, remoteUser); languageIdx = GeneralUtilityMethods.getLanguageIdx(survey, language); if (templateFile.exists()) { log.info("PDF Template Exists"); String templateName = templateFile.getAbsolutePath(); reader = new PdfReader(templateName); stamper = new PdfStamper(reader, outputStream); for (int i = 0; i < survey.instance.results.size(); i++) { fillTemplate(gv, stamper.getAcroFields(), survey.instance.results.get(i), basePath, null, i, serverRoot, stamper, oId); } if (user != null) { fillTemplateUserDetails(stamper.getAcroFields(), user, basePath); } stamper.setFormFlattening(true); } else { log.info("++++No template exists creating a pdf file programmatically"); /* * Create a PDF without the stationary * If we need to add a letter head then create document in two passes, the second pass adds the letter head * Else just create the document directly in a single pass */ Parser parser = getXMLParser(); // Step 1 - Create the underlying document as a byte array if (landscape) { document = new Document(PageSize.A4.rotate()); } else { document = new Document(PageSize.A4); } document.setMargins(marginLeft, marginRight, marginTop_1, marginBottom_1); writer = PdfWriter.getInstance(document, outputStream); writer.setInitialLeading(12); writer.setPageEvent(new PdfPageSizer(survey.displayName, survey.projectName, user, basePath, null, marginLeft, marginRight, marginTop_2, marginBottom_2)); document.open(); // If this form has data maintain a list of parent records to lookup ${values} ArrayList<ArrayList<Result>> parentRecords = null; if (!generateBlank) { parentRecords = new ArrayList<ArrayList<Result>>(); } for (int i = 0; i < survey.instance.results.size(); i++) { processForm(parser, document, survey.instance.results.get(i), basePath, serverRoot, generateBlank, 0, i, repIndexes, gv, false, parentRecords, remoteUser, oId); } fillNonTemplateUserDetails(document, user, basePath); // Add appendix if (gv.hasAppendix) { document.newPage(); document.add(new Paragraph("Appendix", defaultFontBold)); for (int i = 0; i < survey.instance.results.size(); i++) { processForm(parser, document, survey.instance.results.get(i), basePath, serverRoot, generateBlank, 0, i, repIndexes, gv, true, parentRecords, remoteUser, oId); } } } } finally { if (document != null) try { document.close(); } catch (Exception e) { } ; if (writer != null) try { writer.close(); } catch (Exception e) { } ; if (stamper != null) try { stamper.close(); } catch (Exception e) { } ; if (reader != null) try { reader.close(); } catch (Exception e) { } ; } return filename; }
From source file:org.unesco.jisis.printsort.BarCodeGenerator.java
public Image createBARCodeEANSUPP(String myTextPrimary, String myTextSupplementary5) { PdfTemplate pdfTemplate = contentByte.createTemplate(0, 0); BarcodeEAN myBarcodeEAN = new BarcodeEAN(); myBarcodeEAN.setCodeType(Barcode.EAN13); myBarcodeEAN.setCode(myTextPrimary); PdfTemplate ean = myBarcodeEAN.createTemplateWithBarcode(contentByte, null, BaseColor.BLUE); BarcodeEAN codeSUPP = new BarcodeEAN(); codeSUPP.setCodeType(Barcode.SUPP5); codeSUPP.setCode(myTextSupplementary5); codeSUPP.setBaseline(-2);//from www . ja v a 2 s .c o m BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(myBarcodeEAN, codeSUPP); Image imageEANSUPP = eanSupp.createImageWithBarcode(contentByte, null, BaseColor.BLUE); return imageEANSUPP; }