List of usage examples for com.itextpdf.text Image setAbsolutePosition
public void setAbsolutePosition(final float absoluteX, final float absoluteY)
Image
. From source file:GestoSAT.Presupuesto.java
License:Open Source License
public String presupuesto2PDF() { try {//from w w w. ja v a 2s. co m String arch = "Presupeusto" + (new Date()).getTime() + ".pdf"; Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream("/TomEE/webapps/ROOT/descargables/" + arch)); DecimalFormat df = new DecimalFormat("0.00"); doc.open(); File f = new File("logo"); if (f.exists()) { Image img = Image.getInstance("logo"); img.setAbsolutePosition(50, 735); img.scaleAbsolute(50, 50); doc.add(img); Paragraph p = new Paragraph(" "); p.setLeading((float) 75); doc.add(p); } doc.add(new Paragraph("PRESUPUESTO")); doc.add(new Paragraph(" ")); doc.add(new Paragraph("Datos empresa")); Oficina ofi = this.getGestoSAT().getEmpleado().getOficina(); doc.add(new Paragraph( ofi.getProvincia() + " " + ofi.getPoblacion() + " " + ofi.getCalle() + " " + ofi.getNumero())); doc.add(new Paragraph(ofi.getNombre())); doc.add(new Paragraph("NIF: " + ofi.getNif())); doc.add(new Paragraph("Tlf: " + ofi.getTlfFijo() + " " + ofi.getTlfMovil())); doc.add(new Paragraph("Fax: " + ofi.getFax())); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph("Datos de inters")); doc.add(new Paragraph( "Cliente: " + this.getCliente().getNombre() + " " + this.getCliente().getApellidos())); doc.add(new Paragraph("Concepto: " + this.concepto)); doc.add(new Paragraph("Fecha validez: " + this.validez)); if (this.aceptado) doc.add(new Paragraph("Aceptado: SI")); else doc.add(new Paragraph("Aceptado: NO")); doc.add(new Paragraph("Adelanto: " + this.adelanto)); doc.add(new Paragraph("Forma pago: " + this.formaPago)); doc.add(new Paragraph("Tiempo estimado: " + this.plazo)); doc.add(new Paragraph("Condiciones: " + this.condiciones)); doc.add(new Paragraph("Seguro: " + this.seguro)); doc.add(new Paragraph("Garantia: " + this.garantia)); doc.add(new Paragraph(" ")); float auxPrecio = 0; PdfPTable table = new PdfPTable(5); table.addCell("#"); table.addCell("Nombre"); table.addCell("Precio Ud / H"); table.addCell("Uds / H"); table.addCell("Total"); Iterator itTabla = this.materialPresupuestado.entrySet().iterator(); while (itTabla.hasNext()) { Map.Entry aux = (Map.Entry) itTabla.next(); table.addCell(aux.getKey().toString()); table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getNombre()); table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad() + ""); table.addCell(((MaterialTrabajos) aux.getValue()).getCantidad() + ""); auxPrecio += ((MaterialTrabajos) aux.getValue()).getCantidad() * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad(); table.addCell((((MaterialTrabajos) aux.getValue()).getCantidad() * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad()) + ""); } itTabla = this.trabajoPresupuestado.entrySet().iterator(); while (itTabla.hasNext()) { Map.Entry aux = (Map.Entry) itTabla.next(); table.addCell("*"); Trabajo tra = (Trabajo) aux.getValue(); table.addCell(tra.getEmpleado().getNombre() + " " + tra.getEmpleado().getApellidos()); table.addCell(tra.getEmpleado().getPrecioHora() + ""); table.addCell(tra.getHoras() + ""); auxPrecio += tra.getEmpleado().getPrecioHora() * tra.getHoras(); table.addCell((tra.getEmpleado().getPrecioHora() * tra.getHoras()) + ""); } doc.add(table); doc.add(new Paragraph("I.V.A: " + this.getGestoSAT().getIva() + "%")); doc.add(new Paragraph( "Total I.V.A: " + df.format((this.getGestoSAT().getIva() / (float) 100) * auxPrecio))); doc.add(new Paragraph( "Total: " + df.format((this.getGestoSAT().getIva() / (float) 100 + 1) * auxPrecio))); doc.close(); return "descargables/" + arch; } catch (IOException ex) { Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex); return ""; } catch (BadElementException ex) { Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex); return ""; } catch (DocumentException ex) { Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex); return ""; } }
From source file:GestoSAT.Recibo.java
License:Open Source License
public String recibo2PDF() { try {/*from www . j a va2s . c om*/ String arch = "Recibo" + (new Date()).getTime() + ".pdf"; Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream("/TomEE/webapps/ROOT/descargables/" + arch)); DecimalFormat df = new DecimalFormat("0.00"); doc.open(); File f = new File("logo"); if (f.exists()) { Image img = Image.getInstance("logo"); img.setAbsolutePosition(50, 735); img.scaleAbsolute(50, 50); doc.add(img); Paragraph p = new Paragraph(" "); p.setLeading((float) 75); doc.add(p); } doc.add(new Paragraph("Recibo")); doc.add(new Paragraph(" ")); doc.add(new Paragraph("Datos empresa")); Oficina ofi = this.getGestoSAT().getEmpleado().getOficina(); doc.add(new Paragraph( ofi.getProvincia() + " " + ofi.getPoblacion() + " " + ofi.getCalle() + " " + ofi.getNumero())); doc.add(new Paragraph("NIF: " + ofi.getNif())); doc.add(new Paragraph("Tlf: " + ofi.getTlfFijo() + " " + ofi.getTlfMovil())); doc.add(new Paragraph("Fax: " + ofi.getFax())); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph("Datos de inters")); doc.add(new Paragraph( "Cliente: " + this.getCliente().getNombre() + " " + this.getCliente().getApellidos())); doc.add(new Paragraph("Concepto: " + this.factura.getConcepto())); doc.add(new Paragraph("Lugar de entrga: " + this.provincia + " " + this.poblacion + " " + this.calle + " " + this.escalera + " " + this.piso + " " + this.puerta)); doc.add(new Paragraph("Albaranes ")); doc.add(new Paragraph(" ")); Iterator itAlbaranes = this.factura.getAlbaranes().entrySet().iterator(); while (itAlbaranes.hasNext()) { Map.Entry auxAlbaranes = (Map.Entry) itAlbaranes.next(); // Leer albaranes float auxPrecio = 0; PdfPTable table = new PdfPTable(5); table.addCell("#"); table.addCell("Nombre"); table.addCell("Precio Ud / H"); table.addCell("Uds / H"); table.addCell("Total"); Iterator itTabla = ((Albaran) auxAlbaranes.getValue()).getMaterialUtilizado().entrySet().iterator(); while (itTabla.hasNext()) { Map.Entry aux = (Map.Entry) itTabla.next(); table.addCell(aux.getKey().toString()); table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getNombre()); table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad() + ""); table.addCell(((MaterialTrabajos) aux.getValue()).getCantidad() + ""); auxPrecio += ((MaterialTrabajos) aux.getValue()).getCantidad() * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad(); table.addCell((((MaterialTrabajos) aux.getValue()).getCantidad() * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad()) + ""); } itTabla = ((Albaran) auxAlbaranes.getValue()).getTrabajoRealizado().entrySet().iterator(); while (itTabla.hasNext()) { Map.Entry aux = (Map.Entry) itTabla.next(); table.addCell("*"); Trabajo tra = (Trabajo) aux.getValue(); table.addCell(tra.getEmpleado().getNombre() + " " + tra.getEmpleado().getApellidos()); table.addCell(tra.getEmpleado().getPrecioHora() + ""); table.addCell(tra.getHoras() + ""); auxPrecio += tra.getEmpleado().getPrecioHora() * tra.getHoras(); table.addCell((tra.getEmpleado().getPrecioHora() * tra.getHoras()) + ""); } doc.add(table); doc.add(new Paragraph("I.V.A: " + this.getGestoSAT().getIva() + "%")); doc.add(new Paragraph( "Total I.V.A: " + df.format((this.getGestoSAT().getIva() / (float) 100) * auxPrecio))); doc.add(new Paragraph( "Total: " + df.format(((this.getGestoSAT().getIva() / (float) 100) + 1) * auxPrecio))); doc.add(new Paragraph(" ")); } doc.add(new Paragraph(" ")); doc.add(new Paragraph("Tota factura: " + df.format(this.factura.getTotal()))); doc.close(); return "descargables/" + arch; } catch (IOException ex) { Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex); return ""; } catch (BadElementException ex) { Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex); return ""; } catch (DocumentException ex) { Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex); return ""; } }
From source file:gov.utah.dts.det.ccl.actions.facility.information.license.reports.LicenseCertificate.java
private static void writePdf(License license, ByteArrayOutputStream ba, HttpServletRequest request) throws DocumentException, BadElementException { SimpleDateFormat df = new SimpleDateFormat("MMMM d, yyyy"); StringBuilder sb;//from w ww .java2 s.com // Retrieve the certificate template to use as watermark ServletContext context = request.getSession().getServletContext(); String templatefile = context.getRealPath("/resources") + "/LicenseCertificateTemplate.pdf"; PdfReader reader = getTemplateReader(templatefile); if (reader != null && reader.getNumberOfPages() > 0) { Phrase phrase; // Create new document using the page size of the certificate template document Document document = new Document(reader.getPageSizeWithRotation(1), 0, 0, 0, 0); PdfWriter writer = PdfWriter.getInstance(document, ba); document.open(); // Get the writer under content byte for placing of watermark PdfContentByte under = writer.getDirectContentUnder(); PdfContentByte over = writer.getDirectContent(); // Retrieve the first page of the template document and wrap as an Image to use as new document watermark PdfImportedPage page = writer.getImportedPage(reader, 1); Image img = Image.getInstance(page); // Make sure the image has an absolute page position if (!img.hasAbsoluteX() || !img.hasAbsoluteY()) { img.setAbsolutePosition(0, 0); } under.addImage(img); /* * THE FOLLOWING TWO FUNCTION CALLS DISPLAY THE PAGE MARGINS AND TEXT COLUMN BORDERS FOR DEBUGGING TEXT PLACEMENT. * UNCOMMENT EACH FUNCTION CALL TO HAVE BORDERS DISPLAYED ON THE OUTPUT DOCUMENT. THIS WILL HELP WHEN YOU NEED * TO SEE WHERE TEXT WILL BE PLACED ON THE CERTIFICATE FORM. */ // Show the page margins //showPageMarginBorders(over); // Show the text column borders //showColumnBorders(over); ColumnText ct = new ColumnText(over); ct.setLeading(fixedLeading); // Add Facility Name to column String text = license.getFacility().getName(); if (text != null) { phrase = new Phrase(text.toUpperCase(), mediumfontB); phrase.setLeading(noLeading); ct.addText(phrase); ct.addText(Chunk.NEWLINE); } // Add Facility Site to column text = license.getFacility().getSiteName(); if (text != null) { phrase = new Phrase(text.toUpperCase(), mediumfontB); phrase.setLeading(noLeading); ct.addText(phrase); ct.addText(Chunk.NEWLINE); } // Add Facility Address to column text = license.getFacility().getLocationAddress().getAddressOne(); if (text != null) { phrase = new Phrase(text.toUpperCase(), mediumfontB); phrase.setLeading(noLeading); ct.addText(phrase); ct.addText(Chunk.NEWLINE); } text = license.getFacility().getLocationAddress().getCityStateZip(); if (text != null) { phrase = new Phrase(text.toUpperCase(), mediumfontB); phrase.setLeading(noLeading); ct.addText(phrase); ct.addText(Chunk.NEWLINE); } // Write column to document ct.setAlignment(Element.ALIGN_CENTER); ct.setSimpleColumn(COLUMNS[0][0], COLUMNS[0][1], COLUMNS[0][2], COLUMNS[0][3]); ct.go(); // Add Certification Service Code to column ct = new ColumnText(over); ct.setLeading(fixedLeading); String service = ""; if (license.getSpecificServiceCode() != null && StringUtils.isNotBlank(license.getSpecificServiceCode().getValue()) && DV_TREATMENT.equalsIgnoreCase(license.getSpecificServiceCode().getValue())) { service += DOMESTIC_VIOLENCE; } if (!license.getProgramCodeIds().isEmpty()) { // redmine 25410 mentalHealthLoop: for (PickListValue pkv : license.getProgramCodeIds()) { String program = pkv.getValue(); int idx = program.indexOf(" -"); if (idx >= 0) { String code = program.substring(0, idx); if (MENTAL_HEALTH_CODES.indexOf(code + ":") >= 0) { if (service.length() > 0) { service += " / "; } service += MENTAL_HEALTH; break mentalHealthLoop; } } } substanceAbuseLoop: for (PickListValue pkv : license.getProgramCodeIds()) { String program = pkv.getValue(); int idx = program.indexOf(" -"); if (idx >= 0) { String code = program.substring(0, idx); if (SUBSTANCE_ABUSE_CODES.indexOf(code + ":") >= 0) { if (service.length() > 0) { service += " / "; } service += SUBSTANCE_ABUSE; break substanceAbuseLoop; } } } } if (StringUtils.isNotBlank(license.getServiceCodeDesc())) { if (service.length() > 0) { service += " / "; } service += license.getServiceCodeDesc(); } if (StringUtils.isNotEmpty(service)) { phrase = new Phrase(service.toUpperCase(), mediumfont); phrase.setLeading(noLeading); ct.addText(phrase); ct.addText(Chunk.NEWLINE); } // Add CLIENTS Info to column sb = new StringBuilder("FOR "); if (license.getAgeGroup() == null || license.getAgeGroup().getValue().equalsIgnoreCase("Adult & Youth")) { // Adult & Youth if (license.getAdultTotalSlots() != null) { sb.append(license.getAdultTotalSlots().toString()); } sb.append(" ADULT AND YOUTH CLIENTS"); } else if (license.getAgeGroup().getValue().equalsIgnoreCase("Adult")) { // Adult if (license.getAdultTotalSlots() != null) { // Are male or female counts specified? sb.append(license.getAdultTotalSlots().toString()); sb.append(" ADULT"); if (license.getAdultFemaleCount() != null || license.getAdultMaleCount() != null) { // Does either the male or female count equal the total slot count? if ((license.getAdultFemaleCount() != null && license.getAdultFemaleCount().equals(license.getAdultTotalSlots()))) { sb.append(" FEMALE CLIENTS"); } else if (license.getAdultMaleCount() != null && license.getAdultMaleCount().equals(license.getAdultTotalSlots())) { sb.append(" MALE CLIENTS"); } else { sb.append(" CLIENTS, "); if (license.getAdultMaleCount() != null) { sb.append(license.getAdultMaleCount().toString() + " MALE"); } if (license.getAdultFemaleCount() != null) { if (license.getAdultMaleCount() != null) { sb.append(" AND "); } sb.append(license.getAdultFemaleCount().toString() + " FEMALE"); } if (license.getFromAge() != null || license.getToAge() != null) { sb.append(","); } } } else { sb.append(" CLIENTS"); } } else { sb.append(" ADULT CLIENTS"); } } else { // Youth if (license.getYouthTotalSlots() != null) { // Are male or female counts specified? sb.append(license.getYouthTotalSlots().toString()); sb.append(" YOUTH"); if (license.getYouthFemaleCount() != null || license.getYouthMaleCount() != null) { // Does either the male or female count equal the total slot count? if ((license.getYouthFemaleCount() != null && license.getYouthFemaleCount().equals(license.getYouthTotalSlots()))) { sb.append(" FEMALE CLIENTS"); } else if (license.getYouthMaleCount() != null && license.getYouthMaleCount().equals(license.getYouthTotalSlots())) { sb.append(" MALE CLIENTS"); } else { sb.append(" CLIENTS, "); if (license.getYouthMaleCount() != null) { sb.append(license.getYouthMaleCount().toString() + " MALE"); } if (license.getYouthFemaleCount() != null) { if (license.getYouthMaleCount() != null) { sb.append(" AND "); } sb.append(license.getYouthFemaleCount().toString() + " FEMALE"); } if (license.getFromAge() != null || license.getToAge() != null) { sb.append(","); } } } else { sb.append(" CLIENTS"); } } else { sb.append(" YOUTH CLIENTS"); } } if (license.getFromAge() != null || license.getToAge() != null) { sb.append(" AGES "); if (license.getFromAge() != null) { sb.append(license.getFromAge().toString()); if (license.getToAge() != null) { sb.append(" TO " + license.getToAge().toString()); } else { sb.append(" AND OLDER"); } } else { sb.append("TO " + license.getToAge().toString()); } } phrase = new Phrase(sb.toString(), mediumfont); phrase.setLeading(noLeading); ct.addText(phrase); ct.addText(Chunk.NEWLINE); // Add Certificate Comments if (StringUtils.isNotBlank(license.getCertificateComment())) { phrase = new Phrase(license.getCertificateComment().toUpperCase(), mediumfont); phrase.setLeading(noLeading); ct.addText(phrase); } // Write column to document ct.setAlignment(Element.ALIGN_CENTER); ct.setSimpleColumn(COLUMNS[1][0], COLUMNS[1][1], COLUMNS[1][2], COLUMNS[1][3]); ct.go(); // Add Certificate Start Date if (license.getStartDate() != null) { phrase = new Phrase(df.format(license.getStartDate()), mediumfont); phrase.setLeading(noLeading); ct = new ColumnText(over); ct.setSimpleColumn(phrase, COLUMNS[2][0], COLUMNS[2][1], COLUMNS[2][2], COLUMNS[2][3], fixedLeading, Element.ALIGN_RIGHT); ct.go(); } // Add Certificate End Date if (license.getEndDate() != null) { phrase = new Phrase(df.format(license.getEndDate()), mediumfont); phrase.setLeading(noLeading); ct = new ColumnText(over); ct.setSimpleColumn(phrase, COLUMNS[3][0], COLUMNS[3][1], COLUMNS[3][2], COLUMNS[3][3], fixedLeading, Element.ALIGN_LEFT); ct.go(); } // Add License Number if (license.getLicenseNumber() != null) { phrase = new Phrase(license.getLicenseNumber().toString(), largefontB); phrase.setLeading(noLeading); ct = new ColumnText(over); ct.setSimpleColumn(phrase, COLUMNS[4][0], COLUMNS[4][1], COLUMNS[4][2], COLUMNS[4][3], numberLeading, Element.ALIGN_CENTER); ct.go(); } document.close(); } }
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 . java2 s . c o 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:info.longnetpro.examples.PdfLibExamples.java
public static void generatePdf() throws DocumentException, URISyntaxException, MalformedURLException, IOException { String licFile = getLicenseFilePath(); loadLicenseFile(licFile);/* www. j a 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:it.vige.magazzino.pdf.Format1DocumentReceipt.java
License:Apache License
@Model public void build(Receipt receipt) throws Exception { ResourceBundle bundle = ResourceBundle.getBundle("messages"); Document document = new Document(); ByteArrayOutputStream bytesOS = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, bytesOS); document.open();//from ww w . j ava 2 s.c om Font normalFont = new Font(); Font headerFont = FontFactory.getFont(FontFactory.TIMES, 9); PdfContentByte canvas = writer.getDirectContentUnder(); List<Data> imagesJar = receipt.getJar().getFiles(); if (imagesJar != null && imagesJar.size() > 0) { Image image1 = Image.getInstance(imagesJar.get(0).getData()); image1.setAbsolutePosition(166, 738); image1.scalePercent(60); document.add(image1); if (imagesJar.size() > 1) { Image image2 = Image.getInstance(imagesJar.get(1).getData()); image2.setAbsolutePosition(326, 748); image2.scalePercent(40); document.add(image2); } } Phrase phrase1 = new Phrase(receipt.getJar().getRagSoc1(), normalFont); Phrase phrase2 = new Phrase( receipt.getJar().getAddress().getAddress() + " " + receipt.getJar().getAddress().getCivicNumber(), normalFont); Phrase phrase3 = new Phrase("Loc. " + receipt.getJar().getAddress().getTown() + " - " + receipt.getJar().getAddress().getCap() + " " + receipt.getJar().getAddress().getCity() + " (" + receipt.getJar().getAddress().getProvince() + ")", normalFont); Phrase phrase4 = new Phrase("Tel. " + receipt.getJar().getAddress().getPhone() + " r.a.Fax " + receipt.getJar().getAddress().getFax(), normalFont); Phrase phrase5 = new Phrase( receipt.getJar().getAddress().getSite() + " E-mail: " + receipt.getJar().getAddress().getEmail(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 36, 784, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 36, 774, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 36, 764, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 36, 754, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 36, 744, 0); Phrase phrase6 = new Phrase(bundle.getString("magazzino_iva") + " " + receipt.getJar().getIva(), normalFont); Phrase phrase7 = new Phrase(bundle.getString("magazzino_capsoc") + " " + receipt.getJar().getCapSoc() + " - " + bundle.getString("magazzino_reapi") + " n. " + receipt.getJar().getReaPI(), normalFont); Phrase phrase8 = new Phrase("Reg. Impr. PI n. " + receipt.getJar().getIva(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 36, 724, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 36, 714, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 36, 704, 0); Phrase phrase9 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase10 = new Phrase("prova 3: prova 3", normalFont); Phrase phrase11 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase12 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase13 = new Phrase("prova 3: prova 3", normalFont); Phrase phrase14 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase15 = new Phrase("prova 4: prova 4", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 664, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 36, 654, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 644, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 36, 634, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 624, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 36, 614, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 604, 0); List<Data> imagesCustomer = receipt.getCustomer().getFiles(); if (imagesCustomer != null && imagesCustomer.size() > 0) { Image image3 = Image.getInstance(imagesCustomer.get(0).getData()); image3.setAbsolutePosition(212, 664); image3.scalePercent(40); document.add(image3); } Phrase phrase16 = new Phrase(receipt.getCustomer().getName(), normalFont); Phrase phrase17 = new Phrase(receipt.getCustomer().getAddress().getAddress() + ", " + receipt.getCustomer().getAddress().getCivicNumber(), normalFont); Phrase phrase18 = new Phrase( receipt.getCustomer().getAddress().getCap() + " " + receipt.getCustomer().getAddress().getCity() + " " + receipt.getCustomer().getAddress().getProvince(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 206, 644, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 206, 624, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 206, 604, 0); Phrase phrase19 = new Phrase("prova", normalFont); Phrase phrase20 = new Phrase("prova", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 316, 694, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 356, 694, 0); Phrase phrase21 = new Phrase( bundle.getString("customer_code").toUpperCase() + " " + bundle.getString("customer").toUpperCase(), headerFont); Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva").toUpperCase(), headerFont); Phrase phrase23 = new Phrase(bundle.getString("pdf_agent").toUpperCase(), headerFont); Phrase phrase24 = new Phrase(bundle.getString("pdf_number_receipt").toUpperCase(), headerFont); Phrase phrase25 = new Phrase( bundle.getString("receipt_date").toUpperCase() + " " + bundle.getString("receipt").toUpperCase(), headerFont); Phrase phrase26 = new Phrase(bundle.getString("pdf_number_page").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 24, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 100, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 176, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 390, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 466, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase26, 542, 540, 0); Phrase phrase27 = new Phrase("aaqaqaq", normalFont); Phrase phrase28 = new Phrase("cddcddcd", normalFont); Phrase phrase29 = new Phrase("cnjcndkd", normalFont); Phrase phrase30 = new Phrase(receipt.getCodeReceipt() + "", normalFont); Phrase phrase31 = new Phrase(receipt.getDate(), normalFont); Phrase phrase32 = new Phrase("tgsb", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase27, 36, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase28, 106, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase29, 176, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase30, 396, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase31, 470, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase32, 546, 530, 0); Phrase phrase33 = new Phrase("aaqaqaq", headerFont); Phrase phrase34 = new Phrase("cddcddcd", headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 24, 513, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 264, 513, 0); Phrase phrase35 = new Phrase("cnjcndkd", normalFont); Phrase phrase36 = new Phrase("dddedreqq", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 36, 503, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 276, 503, 0); Phrase phrase37 = new Phrase(bundle.getString("article_code").toUpperCase(), headerFont); Phrase phrase38 = new Phrase(bundle.getString("article_description").toUpperCase(), headerFont); Phrase phrase39 = new Phrase(bundle.getString("article_um").toUpperCase(), headerFont); Phrase phrase40 = new Phrase(bundle.getString("pdf_number_articles").toUpperCase(), headerFont); Phrase phrase41 = new Phrase(bundle.getString("article_prize").toUpperCase(), headerFont); Phrase phrase42 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont); Phrase phrase43 = new Phrase(bundle.getString("pdf_amount").toUpperCase(), headerFont); Phrase phrase44 = new Phrase(bundle.getString("pdf_iva").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase37, 47, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase38, 126, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase39, 286, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase40, 324, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase41, 373, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase42, 440, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 488, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 552, 480, 0); Phrase phrase45 = null; Phrase phrase46 = null; Phrase phrase47 = null; Phrase phrase48 = null; Phrase phrase49 = null; Phrase phrase50 = null; Phrase phrase51 = null; Phrase phrase52 = null; int i = 0; for (i = 0; i < 70; i = i + 15) { phrase45 = new Phrase("dgbsbb", normalFont); phrase46 = new Phrase("323232", normalFont); phrase47 = new Phrase("bbg", normalFont); phrase48 = new Phrase("wefwe", normalFont); phrase49 = new Phrase("ewrew", normalFont); phrase50 = new Phrase("ewr5", normalFont); phrase51 = new Phrase("dsadasd", normalFont); phrase52 = new Phrase("ds", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase45, 59, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase46, 126, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase47, 280, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 306, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase49, 368, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 436, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase51, 480, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 556, 460 - i, 0); } int j = 298; if (i - 298 < 0) i = 298; else { j = i; i = 460 - i; } Phrase phrase81 = new Phrase(receipt.getCause(), normalFont); Phrase phrase82 = new Phrase(receipt.getDescription(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase81, 59, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase82, 326, i, 0); Phrase phrase53 = new Phrase(bundle.getString("pdf_total_goods").toUpperCase(), headerFont); Phrase phrase54 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont); Phrase phrase55 = new Phrase(bundle.getString("pdf_total_net").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase53, 26, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase54, 104, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase55, 182, i - 30, 0); Phrase phrase56 = new Phrase("opoppp", normalFont); Phrase phrase57 = new Phrase("2ws", normalFont); Phrase phrase58 = new Phrase("78900", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase56, 96, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase57, 176, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase58, 252, i - 50, 0); Phrase phrase59 = new Phrase(bundle.getString("pdf_expiries").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase59, 36, i - 70, 0); Phrase phrase60 = new Phrase("78900", normalFont); Phrase phrase61 = new Phrase("opoppp", normalFont); Phrase phrase62 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase60, 166, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase61, 166, i - 110, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase62, 166, i - 130, 0); Phrase phrase63 = new Phrase("78900", normalFont); Phrase phrase64 = new Phrase("opoppp", normalFont); Phrase phrase65 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase63, 256, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase64, 256, i - 110, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase65, 256, i - 130, 0); Phrase phrase66 = new Phrase(bundle.getString("pdf_transport").toUpperCase(), headerFont); Phrase phrase67 = new Phrase(bundle.getString("pdf_caching").toUpperCase(), headerFont); Phrase phrase68 = new Phrase(bundle.getString("pdf_various_costs").toUpperCase(), headerFont); Phrase phrase69 = new Phrase(bundle.getString("pdf_stamps").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase66, 260, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase67, 340, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase68, 418, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase69, 496, i - 30, 0); Phrase phrase70 = new Phrase("2ws", normalFont); Phrase phrase71 = new Phrase("78900", normalFont); Phrase phrase72 = new Phrase("opoppp", normalFont); Phrase phrase73 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase70, 300, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase71, 390, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase72, 468, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase73, 546, i - 50, 0); Phrase phrase74 = new Phrase(bundle.getString("article_imponible").toUpperCase(), headerFont); Phrase phrase75 = new Phrase(bundle.getString("pdf_tax").toUpperCase(), headerFont); Phrase phrase76 = new Phrase(bundle.getString("pdf_total_receipt").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase74, 260, i - 70, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase75, 352, i - 70, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase76, 484, i - 70, 0); Phrase phrase77 = new Phrase("2ws", normalFont); Phrase phrase78 = new Phrase("78900", normalFont); Phrase phrase79 = new Phrase("opoppp", normalFont); Phrase phrase80 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase77, 310, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase78, 352, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase79, 450, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase80, 536, i - 110, 0); PdfPTable table = new PdfPTable(1); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); PdfPCell cell = new PdfPCell(); cell.setPadding(127); table.addCell(cell); document.add(table); table = new PdfPTable(6); table.getDefaultCell().setPadding(5); table.setWidthPercentage(105); table.setWidths(new float[] { 7, 7, 20, 7, 7, 3 }); cell = new PdfPCell(); cell.setPadding(14); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(2); table.getDefaultCell().setPadding(5); table.setWidthPercentage(105); table.setWidths(new float[] { 15.5f, 20 }); cell = new PdfPCell(); cell.setPadding(14); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(1); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); cell = new PdfPCell(); cell.setPadding(3); table.addCell(cell); document.add(table); table = new PdfPTable(7); table.getDefaultCell().setPadding(100); table.setWidths(new float[] { 23.5f, 2, 5, 6, 4, 7, 3 }); table.setWidthPercentage(105); cell = new PdfPCell(); cell.setPadding(j * 8 - 2279); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(7); table.getDefaultCell().setPadding(5); table.setWidthPercentage(105); cell = new PdfPCell(); cell.setPadding(17); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(5); table.setWidths(new float[] { 10.5f, 4, 6, 4 }); table.setWidthPercentage(105); cell = new PdfPCell(); cell.setPadding(48); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); document.close(); HttpServletResponse response = (HttpServletResponse) extCtx.getResponse(); response.setContentType("application/pdf"); response.addHeader("Content-disposition", "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\""); ServletOutputStream os = response.getOutputStream(); os.write(bytesOS.toByteArray()); os.flush(); os.close(); facesContext.responseComplete(); }
From source file:it.vige.magazzino.pdf.Format2DocumentReceipt.java
License:Apache License
@Model public void build(Receipt receipt) throws Exception { ResourceBundle bundle = ResourceBundle.getBundle("messages"); Document document = new Document(); ByteArrayOutputStream bytesOS = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, bytesOS); document.open();//from w w w. j ava2 s . c om Font normalFont = new Font(); PdfContentByte canvas = writer.getDirectContentUnder(); List<Data> imagesJar = receipt.getJar().getFiles(); if (imagesJar != null && imagesJar.size() > 0) { Image image1 = Image.getInstance(imagesJar.get(0).getData()); image1.setAbsolutePosition(36, 742); image1.scalePercent(60); document.add(image1); } Phrase phrase1 = new Phrase(bundle.getString("pdf_number_receipt"), normalFont); Phrase phrase2 = new Phrase(receipt.getCodeReceipt() + "", normalFont); Phrase phrase3 = new Phrase(bundle.getString("receipt_date"), normalFont); Phrase phrase4 = new Phrase(receipt.getDate(), normalFont); Phrase phrase5 = new Phrase(receipt.getCause(), normalFont); Phrase phrase6 = new Phrase(receipt.getDescription(), normalFont); Phrase phrase7 = new Phrase(bundle.getString("customer_code") + " " + bundle.getString("customer"), normalFont); Phrase phrase8 = new Phrase("prova 4: prova 4", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 286, 797, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 386, 797, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 286, 777, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 386, 777, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 286, 757, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 386, 757, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 286, 737, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 386, 737, 0); Phrase phrase9 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase10 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase11 = new Phrase("prova 3: prova 3", normalFont); Phrase phrase12 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase13 = new Phrase(bundle.getString("pdf_tel"), normalFont); Phrase phrase14 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase15 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont); Phrase phrase16 = new Phrase("prova 4: prova 4", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 718, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 136, 718, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 698, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 136, 698, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 678, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 136, 678, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 658, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 136, 658, 0); Phrase phrase17 = new Phrase("Ditta", normalFont); Phrase phrase18 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase19 = new Phrase("prova 3: prova 3", normalFont); Phrase phrase20 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase21 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont); Phrase phrase23 = new Phrase("prova 2: ", normalFont); Phrase phrase24 = new Phrase(bundle.getString("pdf_cod_fisc"), normalFont); Phrase phrase25 = new Phrase("prova 2: ", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 236, 736, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 236, 708, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 236, 688, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 236, 668, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 386, 668, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 236, 648, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 286, 648, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 356, 648, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 416, 648, 0); Phrase phrase26 = new Phrase(bundle.getString("article_code"), normalFont); Phrase phrase27 = new Phrase(bundle.getString("article_description"), normalFont); Phrase phrase28 = new Phrase(bundle.getString("pdf_number_articles"), normalFont); Phrase phrase29 = new Phrase(bundle.getString("article_prize"), normalFont); Phrase phrase30 = new Phrase(bundle.getString("pdf_reduction"), normalFont); Phrase phrase31 = new Phrase(bundle.getString("pdf_amount"), normalFont); Phrase phrase32 = new Phrase(bundle.getString("pdf_iva"), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase26, 59, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase27, 146, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase28, 208, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase29, 280, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase30, 353, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase31, 422, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase32, 498, 618, 0); Phrase phrase33 = null; Phrase phrase34 = null; Phrase phrase35 = null; Phrase phrase36 = null; Phrase phrase37 = null; Phrase phrase38 = null; Phrase phrase39 = null; int i = 0; for (i = 0; i < 70; i = i + 15) { phrase33 = new Phrase("dsadasd", normalFont); phrase34 = new Phrase("dgbsbb", normalFont); phrase35 = new Phrase("323232", normalFont); phrase36 = new Phrase("bbgdbdfbdb", normalFont); phrase37 = new Phrase("wefwew", normalFont); phrase38 = new Phrase("ewrew", normalFont); phrase39 = new Phrase("ewr5", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 59, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 136, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 196, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 266, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase37, 351, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase38, 416, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase39, 496, 598 - i, 0); } int j = 298; if (i - 298 < 0) i = 298; else { j = i; i = 588 - i; } Phrase phrase40 = new Phrase(bundle.getString("pdf_references").toUpperCase(), normalFont); Phrase phrase41 = new Phrase(bundle.getString("pdf_delivery").toUpperCase(), normalFont); Phrase phrase42 = new Phrase(bundle.getString("pdf_payments").toUpperCase(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase40, 105, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase41, 206, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase42, 316, i, 0); Phrase phrase43 = new Phrase("opoppp", normalFont); Phrase phrase44 = new Phrase("2ws", normalFont); Phrase phrase45 = new Phrase("78900", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 59, i - 20, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 186, i - 20, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase45, 276, i - 20, 0); Phrase phrase46 = new Phrase(bundle.getString("pdf_sign_producer").toUpperCase(), normalFont); Phrase phrase47 = new Phrase(bundle.getString("pdf_sign_receiver").toUpperCase(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase46, 154, i - 40, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase47, 321, i - 40, 0); Phrase phrase48 = new Phrase(bundle.getString("article_imponible"), normalFont); Phrase phrase49 = new Phrase("opoppp", normalFont); Phrase phrase50 = new Phrase(bundle.getString("pdf_tax"), normalFont); Phrase phrase51 = new Phrase("78900", normalFont); Phrase phrase52 = new Phrase(bundle.getString("pdf_total_receipt"), normalFont); Phrase phrase53 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 356, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase49, 566, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 356, i - 25, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase51, 566, i - 25, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 356, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase53, 566, i - 50, 0); PdfPTable table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 47, 18, 18, 17 }); PdfPCell cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 47, 18, 18, 17 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 47, 18, 18, 17 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 47, 18, 18, 17 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); document.add(table); table = new PdfPTable(1); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(3); table.addCell(cell); document.add(table); table = new PdfPTable(3); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 38, 48, 14 }); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(40); table.addCell(cell); cell.enableBorderSide(PdfPCell.RIGHT); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); table.addCell(cell); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); table.addCell(cell); document.add(table); table = new PdfPTable(1); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(3); table.addCell(cell); document.add(table); table = new PdfPTable(7); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(7); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(j * 8 - 2234); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(5); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 20, 20, 20, 20, 20 }); cell = new PdfPCell(); cell.setPadding(20); table.addCell(cell); table.addCell(cell); table.addCell(cell); cell.disableBorderSide(PdfPCell.BOTTOM); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 30, 30, 20, 20 }); cell = new PdfPCell(); cell.setPadding(20); table.addCell(cell); table.addCell(cell); cell.disableBorderSide(PdfPCell.TOP); table.addCell(cell); table.addCell(cell); document.add(table); document.close(); HttpServletResponse response = (HttpServletResponse) extCtx.getResponse(); response.setContentType("application/pdf"); response.addHeader("Content-disposition", "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\""); ServletOutputStream os = response.getOutputStream(); os.write(bytesOS.toByteArray()); os.flush(); os.close(); facesContext.responseComplete(); }
From source file:itext_result.Main.java
private int developScreeningSheet() { new SwingWorker<Object, Object>() { String filename;/* w w w. ja va 2s . co m*/ @Override protected void done() { // ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. "); } public PdfPCell createBarcode(PdfWriter writer, String code) throws DocumentException, IOException { BarcodeEAN barcode = new BarcodeEAN(); barcode.setCodeType(Barcode.EAN8); barcode.setCode(code); PdfPCell cell = new PdfPCell( barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY), true); cell.setPadding(10); return cell; } class ImageContent implements PdfPTableEvent { protected com.itextpdf.text.Image content; public ImageContent(com.itextpdf.text.Image content) { this.content = content; } public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { try { PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS]; float x = widths[3][1] + 10; float y = heights[3] - 10 - content.getScaledHeight(); content.setAbsolutePosition(x, y); canvas.addImage(content); } catch (DocumentException e) { throw new ExceptionConverter(e); } } } @Override protected Object doInBackground() throws Exception { // System.err.println(" Roll No Received ....." + rollno); Document doc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("12345" + ".pdf")); doc.open(); doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : "); doc.addSubject("Confidential Report Eyes Only"); doc.addKeywords(""); doc.addAuthor("SOS"); doc.addCreator("SOS"); // A4 = 210mm x 297mm ~ 605points x 855points doc.setPageSize(PageSize.A5); doc.setMargins(15f, 15f, 15f, 15f); ///////////////////////////////////////////////////////////// int pageno = 1; for (int i = 0; i == pageno; i++) { // doc.add(imageRight); } PdfContentByte cb = writer.getDirectContent(); //DONE BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCodeType(Barcode.EAN8); Barcode128 code128 = new Barcode128(); code128.setCode(String.valueOf("123456")); Barcode128 code128_jacket = new Barcode128(); code128_jacket.setCode(String.valueOf("10345")); codeEAN.setCode(String.valueOf("123456")); com.itextpdf.text.Image imageEAN = code128.createImageWithBarcode(cb, null, null); // imageEAN.scalePercent(10f); //464f, 725f // imageEAN.setAbsolutePosition(474f, 662f); int i = 1; while (i <= pageno) { doc.newPage(); // cb.addImage(imageRight); // cb.addImage(imageEAN); i++; } com.itextpdf.text.Image carcode = code128_jacket.createImageWithBarcode(cb, null, null); carcode.scaleAbsolute(100f, 35f); carcode.setAbsolutePosition(500f, 600f); writer.addDirectImageSimple(carcode); // cb.addImage(carcode); com.itextpdf.text.Image carcode2 = code128.createImageWithBarcode(cb, null, null); carcode2.scaleAbsolute(100f, 35f); carcode2.setAbsolutePosition(450f, 760f); writer.addDirectImageSimple(carcode2); // cb.addImage(carcode2); Image image1 = Image.getInstance("jklogo.gif"); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(99); table.addCell(image1); doc.add(table); table = new PdfPTable(4); table.setWidthPercentage(99); float[] columnWidths = { 6, 2 }; PdfPTable CandidateTable = new PdfPTable(columnWidths); Font f = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); Font fsmall = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); PdfPCell rollno = new PdfPCell(new Phrase("Roll No# " + String.valueOf("123456"), fsmall)); PdfPCell cname = new PdfPCell(new Phrase("Name #" + String.valueOf("John Doe"), fsmall)); // DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); // String today = formatter.format(cInfo.getDob()); PdfPCell dob = new PdfPCell(new Phrase("DOB#" + String.valueOf("12-03-1989"), fsmall)); PdfPCell fname = new PdfPCell(new Phrase("F/H Name #" + String.valueOf("Big John"), fsmall)); PdfPCell type = new PdfPCell(new Phrase("Total Time #" + String.valueOf("350.00"), fsmall)); // String scrtoday = formatter.format(cInfo.getScreeningdate()); // System.out.println("Today : " + today); PdfPCell scrdate = new PdfPCell(new Phrase("Laps #" + String.valueOf("4"), fsmall)); PdfPCell cell = new PdfPCell(new Phrase(" ", fsmall)); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); dob.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); fname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); type.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); scrdate.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); CandidateTable.addCell(rollno); CandidateTable.addCell(cell); CandidateTable.addCell(cname); CandidateTable.addCell(cell); CandidateTable.addCell(dob); CandidateTable.addCell(cell); PdfPTable CandidateOtherTable = new PdfPTable(columnWidths); CandidateOtherTable.addCell(fname); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(scrdate); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(type); CandidateOtherTable.addCell(cell); PdfPCell race_start_time = new PdfPCell(new Phrase("Start Time :XX-XX-XX ", fsmall)); PdfPCell race_end_time = new PdfPCell(new Phrase("End Time :XX-XX-XX", fsmall)); PdfPCell race_total_time = new PdfPCell(new Phrase("Total Time : 350.00 ", fsmall)); race_start_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_end_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_total_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); PdfPTable CandidateRaceDetails = new PdfPTable(columnWidths); CandidateRaceDetails.addCell(race_start_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_end_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_total_time); CandidateRaceDetails.addCell(cell); PdfPTable tablewith3cells = new PdfPTable(3); //1 St Col for Roll No Name and DOB tablewith3cells.addCell(CandidateTable); //2 nd Col for Father Name sCREEning Date Gurkha tablewith3cells.addCell(CandidateOtherTable); //3rd Col for Barcode to be Printed tablewith3cells.addCell(CandidateRaceDetails); // Setting the Width here to 101 tablewith3cells.setWidthPercentage(99); doc.add(tablewith3cells); PdfPTable userArea = new PdfPTable(1); userArea.setWidthPercentage(99); userArea.addCell(" \n \n Congratulations \n \n "); doc.add(userArea); PdfPTable footerCSBC = new PdfPTable(2); footerCSBC.setWidthPercentage(99); PdfPCell height_box = new PdfPCell(new Phrase("Height \n\n\n", f)); height_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_box = new PdfPCell(new Phrase("Chest \n\n\n", f)); chest_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_exp_box = new PdfPCell(new Phrase("Chest Exp \n\n\n", f)); chest_exp_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell pushup_box = new PdfPCell(new Phrase("Pushup \n\n\n", f)); pushup_box.setBorder(com.itextpdf.text.Rectangle.BOX); //CSignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); // ASignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); footerCSBC.addCell(height_box); footerCSBC.addCell(chest_box); footerCSBC.addCell(chest_exp_box); footerCSBC.addCell(pushup_box); doc.add(footerCSBC); float[] columnWidths_ForBarcode = { 6, 3 }; PdfPTable terminalinfo = new PdfPTable(columnWidths_ForBarcode); // terminalinfo.setWidthPercentage(99); String computername = InetAddress.getLocalHost().getHostName(); System.out.println(computername); PdfPCell pcname = new PdfPCell(new Phrase("\t Jacket \n\n ", f)); String UserMatchScore = "\t Barcode\n\n"; PdfPCell score = new PdfPCell(new Phrase(UserMatchScore, f)); PdfPCell barcode = new PdfPCell(carcode2); PdfPCell jacketnumber = new PdfPCell(carcode); pcname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); score.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); barcode.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); jacketnumber.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); terminalinfo.addCell(score); terminalinfo.addCell(pcname); terminalinfo.addCell(barcode); terminalinfo.addCell(jacketnumber); doc.add(terminalinfo); PdfPCell eula_notice = new PdfPCell(new Phrase(" ", f)); eula_notice.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable eula_notice_table = new PdfPTable(1); eula_notice_table.setWidthPercentage(25); eula_notice_table.addCell(eula_notice); doc.add(eula_notice_table); } catch (Exception e) { System.err.println(e.getMessage()); // ConsoleMsg(e.getMessage()); } finally { doc.close(); doc.close(); doc.close(); } //ConsoleMsg("PDF... GENERATED"); return null; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }.execute(); return 0; }
From source file:learn.PdfRendererBasicFragment.java
License:Apache License
public void merge(int pageNum) { try {//w w w .j a v a2 s . c om Image image = Image.getInstance(signatureByte); pdfReader = new PdfReader(path); //fix y Matrix matrix = mSignatureImage.getImageMatrix(); // Get the values of the matrix float[] values = new float[9]; matrix.getValues(values); float relativeX = (mSignatureImage.getX() - values[2]) / values[0]; float relativeY = (mSignatureImage.getY() - values[5]) / values[4]; x = relativeX; y = relativeY; if (pageNum != -1) { y = pdfReader.getCropBox(pageNum).getHeight() - y; y -= mSign.getHeight(); } PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(newP)); if (pageNum == -1) { y = pdfReader.getCropBox(1).getHeight() - y; y -= mSign.getHeight(); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { //put content under PdfContentByte content;// = pdfStamper.getUnderContent(i); // image.setAbsolutePosition(x, y); // content.addImage(image); //put content over content = pdfStamper.getOverContent(i); image.setAbsolutePosition(x, y); content.addImage(image); //Text over the existing page /*BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 18); content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Page No: " + i, 430, 15, 0); content.endText();*/ } } else { PdfContentByte content = pdfStamper.getOverContent(pageNum); image.setAbsolutePosition(x, y); content.addImage(image); } pdfStamper.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Login.ventas.fproyectos.java
public void fondos(Document documento, PdfContentByte canvas) { try {/*from w ww. jav a 2 s.com*/ Image imghead = Image.getInstance(usuario.getDireccion() + "/plantilla.jpg"); imghead.setAbsolutePosition(0, 0); imghead.setAlignment(Image.ALIGN_CENTER); float scaler = ((documento.getPageSize().getWidth() - documento.leftMargin() - documento.rightMargin()) / imghead.getWidth()) * 100; imghead.scalePercent(scaler); PdfTemplate tp = canvas.createTemplate(PageSize.A4.getWidth(), PageSize.A4.getHeight()); //el rea destinada para el encabezado tp.addImage(imghead); x = (int) imghead.getWidth(); y = (int) imghead.getHeight(); canvas.addTemplate(tp, 0, 0);//posicin del tmplate derecha y abajo } catch (IOException | DocumentException io) { } }