List of usage examples for com.itextpdf.text.pdf PdfPCell setColspan
public void setColspan(int colspan)
From source file:naprawa.praca.PracaController.java
public void akcjaDrukuj() { mapaUslug = getDaoFactory().getDaoDefect().pobierzUslugi(getConnection(), wybranyDefect); FileOutputStream file = null; File druk = null;/*from www. j a va2 s . c o m*/ try { Document document = new Document(PageSize.A5, 0, 0, 0, 0); String userPath = System.getProperty("user.home"); druk = new File(userPath + "/Baks wydruki"); if (!druk.exists()) { druk.mkdirs(); } File wydruk = new File(druk + "/" + wybranyDefect.getInfoNaprawa() + ".pdf"); if (!wydruk.exists()) { try { wydruk.createNewFile(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } file = new FileOutputStream(wydruk); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(wydruk)); document.open(); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); PdfPTable tableO = new PdfPTable(2); tableO.setWidthPercentage(100); tableO.setSpacingBefore(0f); table.setSpacingAfter(0f); tableO.addCell(getNewCell( "BAK's Machine\nin. Baej Krzciuk\n26-800 Biaobrzegi\nul. Brzechwy 31\ntel. 509-281-487")); Image image = Image.getInstance(getClass().getClassLoader().getResource("baksZ.jpg")); tableO.addCell(image); table.addCell(tableO); PdfPCell cell1 = getNewCell( "Biaobrzegi, dn. " + new SimpleDateFormat("yyyy-MM-dd").format(new Date())); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(addTableCzesc()); table.addCell(addTableCzescService("Materiay", RodzajUslugi.MATERIAL)); table.addCell(addTableCzescService("Naprawa", RodzajUslugi.NAPRAWA)); PdfPTable tablePodsumowanie = new PdfPTable(3); tablePodsumowanie.setWidthPercentage(100); int[] width = { 8, 77, 15 }; tablePodsumowanie.setWidths(width); PdfPCell cell = getNewCell("Podsumowanie"); cell.setColspan(10); cell.setBorder(PdfPCell.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tablePodsumowanie.addCell(cell); tablePodsumowanie.addCell(getNewCell("1.")); tablePodsumowanie.addCell(getNewCell("Czci")); tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztCzesciS() + " z")); tablePodsumowanie.addCell(getNewCell("2.")); tablePodsumowanie.addCell(getNewCell("Materiay")); tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztMaterialyS() + " z")); tablePodsumowanie.addCell(getNewCell("3.")); tablePodsumowanie.addCell(getNewCell("Naprawa")); tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztNaprawyS() + " z")); tablePodsumowanie.addCell(getNewCell("")); tablePodsumowanie.addCell(getNewCell("RAZEM")); tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztSumaS() + " z")); table.addCell(tablePodsumowanie); document.add(table); document.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } catch (FileNotFoundException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); BaksSessionBean.getInstance().fireMessage(widok, "Wydruk", "Pdf do ktrego chcesz zapisa wynik jest otwarty!\n Zamknij i sprbuj jeszcze raz."); } finally { try { file.close(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.open(druk); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } BaksSessionBean.getInstance().fireMessage(widok, "Zapis", "Wydruk zapisany w folderze: " + System.getProperty("user.home") + "/Baks wydruki"); }
From source file:naprawa.praca.PracaController.java
public PdfPTable addTableCzesc() { PdfPTable tableCzesc = new PdfPTable(3); try {//from w w w . j a v a 2 s. co m tableCzesc.setWidthPercentage(100); int[] width = { 8, 77, 15 }; tableCzesc.setWidths(width); PdfPCell cell = getNewCell("Czci"); cell.setColspan(10); cell.setBorder(PdfPCell.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableCzesc.addCell(cell); int i = 1; for (Object item : mapaUslug.get(RodzajUslugi.CZESC)) { Czesc czesc = ((Czesc) item); tableCzesc.addCell(getNewCell(i + ".")); tableCzesc.addCell(getNewCell(czesc.getOpis())); tableCzesc.addCell(getNewCell(TO_Invoice.getWynikSumaKoszt(czesc.getCena()) + " z")); i++; } } catch (DocumentException ex) { Logger.getLogger(PracaController.class.getName()).log(Level.SEVERE, null, ex); } return tableCzesc; }
From source file:naprawa.praca.PracaController.java
public PdfPTable addTableCzescService(String rodzaj, RodzajUslugi usluga) { PdfPTable tableCzesc = new PdfPTable(3); try {// www . jav a 2 s . com tableCzesc.setWidthPercentage(100); int[] width = { 8, 77, 15 }; tableCzesc.setWidths(width); PdfPCell cell = getNewCell(rodzaj); cell.setColspan(10); cell.setBorder(PdfPCell.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableCzesc.addCell(cell); int i = 1; for (Object item : mapaUslug.get(usluga)) { Usluga czesc = ((Usluga) item); tableCzesc.addCell(getNewCell(i + ".")); tableCzesc.addCell(getNewCell(czesc.getOpis())); tableCzesc.addCell(getNewCell(TO_Invoice.getWynikSumaKoszt(czesc.getKoszt()) + " z")); i++; } } catch (DocumentException ex) { Logger.getLogger(PracaController.class.getName()).log(Level.SEVERE, null, ex); } return tableCzesc; }
From source file:net.digitstar.vanadio.helpers.PdfHelper.java
License:Apache License
public static PdfPCell newCell(CellStyle style) { PdfPCell cell = new PdfPCell(); if (style != null) { if (style.getNestedTable() != null) { cell = new PdfPCell(style.getNestedTable()); style.setNestedTable(null);/* w ww . j a v a 2s . c o m*/ } else if (style.getImage() != null) { cell = new PdfPCell(style.getImage(), style.isFitImage()); style.setImage(null); } else if (style.getText() != null) { cell = new PdfPCell(style.getText()); style.setText((String) null); } cell.setColspan(style.getColspan()); cell.setRowspan(style.getRowspan()); cell.setMinimumHeight(style.getMinimumHeight()); cell.setFixedHeight(style.getFixedHeight()); cell.setNoWrap(style.isNoWrap()); cell.setRotation(style.getRotation().getValue()); style = Alignment.assign(style); cell.setHorizontalAlignment(style.getHorizAlign().getValue()); cell.setVerticalAlignment(style.getVertAlign().getValue()); cell.setUseVariableBorders(style.isUseVariableBorders()); cell.setUseBorderPadding(style.isUseBorderPadding()); if (!style.getBorderWidth().isAllSideEqual()) { cell.setBorderWidthBottom(style.getBorderWidth().getBottom()); cell.setBorderWidthLeft(style.getBorderWidth().getLeft()); cell.setBorderWidthRight(style.getBorderWidth().getRight()); cell.setBorderWidthTop(style.getBorderWidth().getTop()); } else { cell.setBorderWidth(style.getBorderWidth().getValue()); } cell.setPaddingBottom(style.getPadding().getBottom()); cell.setPaddingLeft(style.getPadding().getLeft()); cell.setPaddingRight(style.getPadding().getRight()); cell.setPaddingTop(style.getPadding().getTop()); cell.setBorderColorBottom(style.getBorderColor().getBottom()); cell.setBorderColorLeft(style.getBorderColor().getLeft()); cell.setBorderColorRight(style.getBorderColor().getRight()); cell.setBorderColorTop(style.getBorderColor().getTop()); cell.setBorder(style.getBorder().getValue()); cell.setBackgroundColor(style.getBackgroundColor()); if (style.getGreyFill() >= 0) { cell.setGrayFill(style.getGreyFill()); } } return cell; }
From source file:net.pflaeging.PortableSigner.PDFSigner.java
License:Open Source License
/** Creates a new instance of DoSignPDF */ public void doSignPDF(String pdfInputFileName, String pdfOutputFileName, String pkcs12FileName, String password, Boolean signText, String signLanguage, String sigLogo, Boolean finalize, String sigComment, String signReason, String signLocation, Boolean noExtraPage, float verticalPos, float leftMargin, float rightMargin, Boolean signLastPage, byte[] ownerPassword) throws PDFSignerException { try {//from w w w . java2 s . c o m //System.out.println("-> DoSignPDF <-"); //System.out.println("Eingabedatei: " + pdfInputFileName); //System.out.println("Ausgabedatei: " + pdfOutputFileName); //System.out.println("Signaturdatei: " + pkcs12FileName); //System.out.println("Signaturblock?: " + signText); //System.out.println("Sprache der Blocks: " + signLanguage); //System.out.println("Signaturlogo: " + sigLogo); System.err.println("Position V:" + verticalPos + " L:" + leftMargin + " R:" + rightMargin); Rectangle signatureBlock; java.security.Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 2); pkcs12 = new GetPKCS12(pkcs12FileName, password); PdfReader reader = null; try { // System.out.println("Password:" + ownerPassword.toString()); if (ownerPassword == null) reader = new PdfReader(pdfInputFileName); else reader = new PdfReader(pdfInputFileName, ownerPassword); } catch (IOException e) { /* MODIFY BY: Denis Torresan Main.setResult( java.util.ResourceBundle.getBundle( "net/pflaeging/PortableSigner/i18n").getString( "CouldNotBeOpened"), true, e.getLocalizedMessage()); */ throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n") .getString("CouldNotBeOpened"), true, e.getLocalizedMessage()); } FileOutputStream fout = null; try { fout = new FileOutputStream(pdfOutputFileName); } catch (FileNotFoundException e) { /* MODIFY BY: Denis Torresan Main.setResult( java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("CouldNotBeWritten"), true, e.getLocalizedMessage()); */ throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n") .getString("CouldNotBeWritten"), true, e.getLocalizedMessage()); } PdfStamper stp = null; try { Date datum = new Date(System.currentTimeMillis()); int pages = reader.getNumberOfPages(); Rectangle size = reader.getPageSize(pages); stp = PdfStamper.createSignature(reader, fout, '\0', null, true); HashMap<String, String> pdfInfo = reader.getInfo(); // thanks to Markus Feisst String pdfInfoProducer = ""; if (pdfInfo.get("Producer") != null) { pdfInfoProducer = pdfInfo.get("Producer").toString(); pdfInfoProducer = pdfInfoProducer + " (signed with PortableSigner " + Version.release + ")"; } else { pdfInfoProducer = "Unknown Producer (signed with PortableSigner " + Version.release + ")"; } pdfInfo.put("Producer", pdfInfoProducer); //System.err.print("++ Producer:" + pdfInfo.get("Producer").toString()); stp.setMoreInfo(pdfInfo); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XmpWriter xmp = new XmpWriter(baos, pdfInfo); xmp.close(); stp.setXmpMetadata(baos.toByteArray()); if (signText) { String greet, signator, datestr, ca, serial, special, note, urn, urnvalue; int specialcount = 0; int sigpage; int rightMarginPT, leftMarginPT; float verticalPositionPT; ResourceBundle block = ResourceBundle .getBundle("net/pflaeging/PortableSigner/Signatureblock_" + signLanguage); greet = block.getString("greeting"); signator = block.getString("signator"); datestr = block.getString("date"); ca = block.getString("issuer"); serial = block.getString("serial"); special = block.getString("special"); note = block.getString("note"); urn = block.getString("urn"); urnvalue = block.getString("urnvalue"); //sigcomment = block.getString(signLanguage + "-comment"); // upper y float topy = size.getTop(); System.err.println("Top: " + topy * ptToCm); // right x float rightx = size.getRight(); System.err.println("Right: " + rightx * ptToCm); if (!noExtraPage) { sigpage = pages + 1; stp.insertPage(sigpage, size); // 30pt left, 30pt right, 20pt from top rightMarginPT = 30; leftMarginPT = 30; verticalPositionPT = topy - 20; } else { if (signLastPage) { sigpage = pages; } else { sigpage = 1; } System.err.println("Page: " + sigpage); rightMarginPT = Math.round(rightMargin / ptToCm); leftMarginPT = Math.round(leftMargin / ptToCm); verticalPositionPT = topy - Math.round(verticalPos / ptToCm); } if (!GetPKCS12.atEgovOID.equals("")) { specialcount = 1; } PdfContentByte content = stp.getOverContent(sigpage); float[] cellsize = new float[2]; cellsize[0] = 100f; // rightx = width of page // 60 = 2x30 margins // cellsize[0] = description row // cellsize[1] = 0 // 70 = logo width cellsize[1] = rightx - rightMarginPT - leftMarginPT - cellsize[0] - cellsize[1] - 70; // Pagetable = Greeting, signatureblock, comment // sigpagetable = outer table // consist: greetingcell, signatureblock , commentcell PdfPTable signatureBlockCompleteTable = new PdfPTable(2); PdfPTable signatureTextTable = new PdfPTable(2); PdfPCell signatureBlockHeadingCell = new PdfPCell( new Paragraph(new Chunk(greet, new Font(Font.FontFamily.HELVETICA, 12)))); signatureBlockHeadingCell.setPaddingBottom(5); signatureBlockHeadingCell.setColspan(2); signatureBlockHeadingCell.setBorderWidth(0f); signatureBlockCompleteTable.addCell(signatureBlockHeadingCell); // inner table start // Line 1 signatureTextTable.addCell( new Paragraph(new Chunk(signator, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD)))); signatureTextTable.addCell( new Paragraph(new Chunk(GetPKCS12.subject, new Font(Font.FontFamily.COURIER, 10)))); // Line 2 signatureTextTable.addCell( new Paragraph(new Chunk(datestr, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD)))); signatureTextTable.addCell( new Paragraph(new Chunk(datum.toString(), new Font(Font.FontFamily.COURIER, 10)))); // Line 3 signatureTextTable.addCell( new Paragraph(new Chunk(ca, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD)))); signatureTextTable.addCell( new Paragraph(new Chunk(GetPKCS12.issuer, new Font(Font.FontFamily.COURIER, 10)))); // Line 4 signatureTextTable.addCell( new Paragraph(new Chunk(serial, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD)))); signatureTextTable.addCell(new Paragraph( new Chunk(GetPKCS12.serial.toString(), new Font(Font.FontFamily.COURIER, 10)))); // Line 5 if (specialcount == 1) { signatureTextTable.addCell(new Paragraph( new Chunk(special, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD)))); signatureTextTable.addCell(new Paragraph( new Chunk(GetPKCS12.atEgovOID, new Font(Font.FontFamily.COURIER, 10)))); } signatureTextTable.addCell( new Paragraph(new Chunk(urn, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD)))); signatureTextTable .addCell(new Paragraph(new Chunk(urnvalue, new Font(Font.FontFamily.COURIER, 10)))); signatureTextTable.setTotalWidth(cellsize); System.err.println( "signatureTextTable Width: " + cellsize[0] * ptToCm + " " + cellsize[1] * ptToCm); // inner table end signatureBlockCompleteTable.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); Image logo; // System.out.println("Logo:" + sigLogo + ":"); if (sigLogo == null || "".equals(sigLogo)) { logo = Image.getInstance( getClass().getResource("/net/pflaeging/PortableSigner/SignatureLogo.png")); } else { logo = Image.getInstance(sigLogo); } PdfPCell logocell = new PdfPCell(); logocell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); logocell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); logocell.setImage(logo); signatureBlockCompleteTable.addCell(logocell); PdfPCell incell = new PdfPCell(signatureTextTable); incell.setBorderWidth(0f); signatureBlockCompleteTable.addCell(incell); PdfPCell commentcell = new PdfPCell( new Paragraph(new Chunk(sigComment, new Font(Font.FontFamily.HELVETICA, 10)))); PdfPCell notecell = new PdfPCell( new Paragraph(new Chunk(note, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD)))); //commentcell.setPaddingTop(10); //commentcell.setColspan(2); // commentcell.setBorderWidth(0f); if (!sigComment.equals("")) { signatureBlockCompleteTable.addCell(notecell); signatureBlockCompleteTable.addCell(commentcell); } float[] cells = { 70, cellsize[0] + cellsize[1] }; signatureBlockCompleteTable.setTotalWidth(cells); System.err.println( "signatureBlockCompleteTable Width: " + cells[0] * ptToCm + " " + cells[1] * ptToCm); signatureBlockCompleteTable.writeSelectedRows(0, 4 + specialcount, leftMarginPT, verticalPositionPT, content); System.err.println( "signatureBlockCompleteTable Position " + 30 * ptToCm + " " + (topy - 20) * ptToCm); signatureBlock = new Rectangle(30 + signatureBlockCompleteTable.getTotalWidth() - 20, topy - 20 - 20, 30 + signatureBlockCompleteTable.getTotalWidth(), topy - 20); // ////// // AcroFields af = reader.getAcroFields(); // ArrayList names = af.getSignatureNames(); // for (int k = 0; k < names.size(); ++k) { // String name = (String) names.get(k); // System.out.println("Signature name: " + name); // System.out.println("\tSignature covers whole document: " + af.signatureCoversWholeDocument(name)); // System.out.println("\tDocument revision: " + af.getRevision(name) + " of " + af.getTotalRevisions()); // PdfPKCS7 pk = af.verifySignature(name); // X509Certificate tempsigner = pk.getSigningCertificate(); // Calendar cal = pk.getSignDate(); // Certificate pkc[] = pk.getCertificates(); // java.util.ResourceBundle tempoid = // java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/SpecialOID"); // String tmpEgovOID = ""; // // for (Enumeration<String> o = tempoid.getKeys(); o.hasMoreElements();) { // String element = o.nextElement(); // // System.out.println(element + ":" + oid.getString(element)); // if (tempsigner.getNonCriticalExtensionOIDs().contains(element)) { // if (!tmpEgovOID.equals("")) { // tmpEgovOID += ", "; // } // tmpEgovOID += tempoid.getString(element) + " (OID=" + element + ")"; // } // } // //System.out.println("\tSigniert von: " + PdfPKCS7.getSubjectFields(pk.getSigningCertificate())); // System.out.println("\tSigniert von: " + tempsigner.getSubjectX500Principal().toString()); // System.out.println("\tDatum: " + cal.getTime().toString()); // System.out.println("\tAusgestellt von: " + tempsigner.getIssuerX500Principal().toString()); // System.out.println("\tSeriennummer: " + tempsigner.getSerialNumber()); // if (!tmpEgovOID.equals("")) { // System.out.println("\tVerwaltungseigenschaft: " + tmpEgovOID); // } // System.out.println("\n"); // System.out.println("\tDocument modified: " + !pk.verify()); //// Object fails[] = PdfPKCS7.verifyCertificates(pkc, kall, null, cal); //// if (fails == null) { //// System.out.println("\tCertificates verified against the KeyStore"); //// } else { //// System.out.println("\tCertificate failed: " + fails[1]); //// } // } // // ////// } else { signatureBlock = new Rectangle(0, 0, 0, 0); // fake definition } PdfSignatureAppearance sap = stp.getSignatureAppearance(); // sap.setCrypto(GetPKCS12.privateKey, GetPKCS12.certificateChain, null, // PdfSignatureAppearance.WINCER_SIGNED ); sap.setCrypto(GetPKCS12.privateKey, GetPKCS12.certificateChain, null, null); sap.setReason(signReason); sap.setLocation(signLocation); // if (signText) { // sap.setVisibleSignature(signatureBlock, // pages + 1, "PortableSigner"); // } if (finalize) { sap.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED); } else { sap.setCertificationLevel(PdfSignatureAppearance.NOT_CERTIFIED); } stp.close(); /* MODIFY BY: Denis Torresan Main.setResult( java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("IsGeneratedAndSigned"), false, ""); */ } catch (Exception e) { /* MODIFY BY: Denis Torresan Main.setResult( java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("ErrorWhileSigningFile"), true, e.getLocalizedMessage()); */ throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n") .getString("ErrorWhileSigningFile"), true, e.getLocalizedMessage()); } } catch (KeyStoreException kse) { /* MODIFY BY: Denis Torresan Main.setResult(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("ErrorCreatingKeystore"), true, kse.getLocalizedMessage()); */ throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n") .getString("ErrorCreatingKeystore"), true, kse.getLocalizedMessage()); } }
From source file:net.yuvideo.voipRacuni.classes.PrintPageListing.java
public void createListing() { document.open();//from ww w.j av a 2s. c o m PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); //HEADERS PdfPCell cell = new PdfPCell(new Phrase("IZVETAJ-LISTING", fontBold)); cell.setColspan(5); cell.setBorder(0); table.addCell(cell); //HEADER KORISNIK String korisnik; if (user.isFirma()) { korisnik = user.getNazivFirme(); } else { korisnik = user.getIme(); } cell = new PdfPCell( new Phrase(String.format("%s - %s - %s", korisnik, user.getBrojTelefona(), this.period), font)); cell.setColspan(5); cell.setBorder(0); table.addCell(cell); //HEADER TABLE PdfPCell cellH1 = new PdfPCell(new Phrase("br.", fontBold)); cellH1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH1).setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cellH2 = new PdfPCell(new Phrase("Pozivani broj", fontBold)); cellH2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH2).setHorizontalAlignment(1); PdfPCell cellH3 = new PdfPCell(new Phrase("Destinacija", fontBold)); cellH3.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH3).setHorizontalAlignment(1); PdfPCell cellH4 = new PdfPCell(new Phrase("Vreme", fontBold)); cellH4.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH4).setHorizontalAlignment(1); PdfPCell cellH5 = new PdfPCell(new Phrase("Trajanje poziva", fontBold)); cellH5.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH5).setHorizontalAlignment(1); PdfPCell cellIzvestaj; int ukupno = 0; for (izvestajPotrosnje izvestaj : listing) { //potrosnja ukupno //Redni broj cellIzvestaj = new PdfPCell(new Phrase(String.valueOf(izvestaj.br), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); //Pozivani broj cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getSource(), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); //Destinacija cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getDestination(), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); //Vreme cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getDatumPoziva(), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); //trajanje poziva cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getTrajanje(), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); ukupno = izvestaj.getUkupno_poziv(); } PdfPCell footer = new PdfPCell(new Phrase( String.format("Ukupno: %s", LocalTime.MIN.plusSeconds(ukupno).toString()), fontLargeBold)); footer.setColspan(5); footer.setHorizontalAlignment(2); footer.setBorder(0); table.addCell(footer); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(PrintPageListing.class.getName()).log(Level.SEVERE, null, ex); } document.close(); }
From source file:nl.avans.C3.BusinessLogic.InvoiceService.java
private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) { //create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); //set the cell alignment cell.setHorizontalAlignment(align);/*from w w w . j a v a 2 s.c om*/ //set the cell column span in case you want to merge two or more cells cell.setColspan(colspan); //in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } //add the call to the table table.addCell(cell); }
From source file:nl.infosys.hartigehap.barSystem.domain.Bon.java
/** * create the table for the PDF//from w w w . j ava2 s . co m * * @return table */ private Paragraph table() { Paragraph par = new Paragraph(); PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); PdfPCell cell; Font fontbold = FontFactory.getFont("Times-Roman", 13, Font.BOLD); Font normal = FontFactory.getFont("Times-Roman", 13); table.addCell(new Phrase("Product:", fontbold)); table.addCell(new Phrase("Prijs:", fontbold)); table.addCell(new Phrase("Aantal:", fontbold)); table.addCell(new Phrase("Totaalprijs:", fontbold)); for (ImmutableProduct product : bestelling.getProducten()) { table.addCell(new Phrase(product.getNaam(), normal)); table.addCell(new Phrase(product.getPrijsFormat(), normal)); table.addCell(new Phrase(String.valueOf(product.getAantal()), normal)); cell = new PdfPCell(new Phrase(product.getTotaalPrijsFormat(), normal)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); cell.setPaddingBottom(5); table.addCell(cell); } cell = new PdfPCell(new Phrase("Excl. BTW", fontbold)); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getPrijsExclBtwFormat(), fontbold)); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase("BTW 21%", fontbold)); cell.setBorder(0); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getBtwBedragFormat(), fontbold)); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("Incl. BTW", fontbold)); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getTotaalPrijsFormat(), fontbold)); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.TOP); table.addCell(cell); par.add(table); return par; }
From source file:nl.infosys.hartigehap.barSystem.presentation.BonGui.java
private Paragraph table() { Paragraph par = new Paragraph(); PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100);/* w w w. j a v a 2 s .c o m*/ table.getDefaultCell().setBorder(0); PdfPCell cell; Font fontbold = FontFactory.getFont("Times-Roman", 13, Font.BOLD); Font normal = FontFactory.getFont("Times-Roman", 13); table.addCell(new Phrase("Product:", fontbold)); table.addCell(new Phrase("Prijs:", fontbold)); table.addCell(new Phrase("Aantal:", fontbold)); table.addCell(new Phrase("Totaalprijs:", fontbold)); for (ImmutableProduct product : bestelling.getProducten()) { table.addCell(new Phrase(product.getNaam(), normal)); table.addCell(new Phrase(product.getPrijsFormat(), normal)); table.addCell(new Phrase(String.valueOf(product.getAantal()), normal)); cell = new PdfPCell(new Phrase(product.getTotaalPrijsFormat(), normal)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); cell.setPaddingBottom(5); table.addCell(cell); } cell = new PdfPCell(new Phrase("Excl. BTW", fontbold)); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getPrijsExclBtwFormat(), fontbold)); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase("BTW 21%", fontbold)); cell.setBorder(0); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getBtwBedragFormat(), fontbold)); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("Incl. BTW", fontbold)); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getTotaalPrijsFormat(), fontbold)); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.TOP); table.addCell(cell); par.add(table); return par; }
From source file:nwk.com.br.documents.OrcamentoPdf.java
private PdfPTable dadosCliente(Orcamento orcamento) throws Exception { cliente = clientedao.select(orcamento.getIdCliente()); PdfPTable dadosCliente = new PdfPTable(new float[] { 0.35f, 0.35f, 0.3f }); dadosCliente.setWidthPercentage(90.0f);//seta o tamanho da tabela em relaao ao documento dadosCliente.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);//alinha os dados a esquerda dadosCliente.getDefaultCell().setBorder(0);//retira a borda //Cria uma cedula da tabela que pegara tres colunas PdfPCell nomeCli = new PdfPCell(new Paragraph("Nome: " + cliente.getNome(), f)); nomeCli.setColspan(3); nomeCli.setHorizontalAlignment(Element.ALIGN_LEFT); nomeCli.setBorder(0);/*from w w w . j av a 2s . c o m*/ dadosCliente.addCell(nomeCli); //formatao do celular e do telefone String celular = new String(); String telefone = new String(); celular = "(" + cliente.getCelular().substring(0, 2) + ") " + cliente.getCelular().substring(2); telefone = "(" + cliente.getTelefone().substring(0, 2) + ") " + cliente.getCelular().substring(2); //adciona os demais dados do cliente a tabela dadosCliente.addCell("E-mail: " + cliente.getEmail()); dadosCliente.addCell("Telefone: " + telefone); dadosCliente.addCell("Celular: " + celular); dadosCliente.addCell("Rua: " + cliente.getRua() + ", " + cliente.getNumero()); dadosCliente.addCell("Bairro: " + cliente.getBairro()); dadosCliente.addCell("Complemento: " + cliente.getComplemento()); dadosCliente.addCell(cliente.getCidade() + "/" + cliente.getEstado()); dadosCliente.addCell(cliente.getCep()); return dadosCliente; }