List of usage examples for com.itextpdf.text.pdf PdfPCell setColspan
public void setColspan(int colspan)
From source file:tm.article_promotion.GArticlePromotionController.java
@FXML private void btnImprimerOnAction(ActionEvent event) throws DocumentException, FileNotFoundException { String s = cbPromotion.getSelectionModel().getSelectedItem().toString(); Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("promotion/promotion" + s + ".pdf")); PDFLogReport.open();//from w ww.ja v a 2 s . c om PdfPTable LogTable = new PdfPTable(5); PdfPCell table_cell; table_cell = new PdfPCell(new Phrase("Id Promotion")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Id Article")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Taux Reduction Gros")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Taux Reduction Detail")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Nombre Point")); LogTable.addCell(table_cell); ObservableList<ArticlePromotion> list = FXCollections.observableArrayList(); list = tblViewArtPromo.getItems(); for (ArticlePromotion ar : list) { table_cell = new PdfPCell(new Phrase(Integer.toString(ar.getIdPromotion()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Integer.toString(ar.getIdArticle()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(ar.getTauxReductionGros()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(ar.getTauxReductionDetail()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Integer.toString(ar.getNombrePointFidele()))); LogTable.addCell(table_cell); } table_cell.setBorder(4); table_cell.setColspan(6); PDFLogReport.add(LogTable); PDFLogReport.close(); }
From source file:tm.stock.GFactureController.java
@FXML private void btnImprimerOnAction(ActionEvent event) throws DocumentException, FileNotFoundException { Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream( "facture/facture" + tblView.getSelectionModel().getSelectedItem().getIdFacture() + ".pdf")); PDFLogReport.open();// w w w. j av a 2 s. com PdfPTable LogTable = new PdfPTable(10); PdfPCell table_cell; table_cell = new PdfPCell(new Phrase("ID_Article")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Designation")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Prix Unitaire")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Quantite")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("TVA (%)")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Total TVA")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Remise (%)")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Total Remise")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Total HT")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Total TTC")); LogTable.addCell(table_cell); ObservableList<Vente> list = FXCollections.observableArrayList(); list = tblViewVente.getItems(); for (Vente v : list) { table_cell = new PdfPCell(new Phrase(Integer.toString(v.getIdArticle()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(v.getNomArticle())); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getPrixUnitaire()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Integer.toString(v.getTva()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Integer.toString(v.getQuantite()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getTotalTVA()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getRemise()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getTotalRemise()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getTotalHT()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getTotalTTC()))); LogTable.addCell(table_cell); } table_cell.setBorder(4); table_cell.setColspan(6); PDFLogReport.add(LogTable); PDFLogReport.close(); }
From source file:tm.stock.GventeController.java
@FXML private void btnValiderOnAction(ActionEvent event) throws DocumentException, FileNotFoundException { Facture f = new Facture(); float prixTotal = 0; for (Vente v : ventes) { prixTotal += v.getTotalTTC();/*w ww .jav a 2 s . com*/ } f.setPrixTotal(prixTotal); DateFormat df = new SimpleDateFormat("dd/MM/yy"); Date dateobj = new Date(); System.out.println(df.format(dateobj)); f.setDateAchat(df.format(dateobj).toString()); IFactureDAO facture = new FactureDAO(); facture.insertFacture(f); Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("facture/facture" + facture.getFacture() + ".pdf")); PDFLogReport.open(); PdfPTable LogTable = new PdfPTable(10); PdfPCell table_cell; table_cell = new PdfPCell(new Phrase("ID_Article")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Designation")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Prix Unitaire")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Quantite")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("TVA (%)")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Total TVA")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Remise (%)")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Total Remise")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Total HT")); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Total TTC")); LogTable.addCell(table_cell); for (Vente v : ventes) { table_cell = new PdfPCell(new Phrase(Integer.toString(v.getIdArticle()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(v.getNomArticle())); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getPrixUnitaire()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Integer.toString(v.getTva()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Integer.toString(v.getQuantite()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getTotalTVA()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getRemise()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getTotalRemise()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getTotalHT()))); LogTable.addCell(table_cell); table_cell = new PdfPCell(new Phrase(Float.toString(v.getTotalTTC()))); LogTable.addCell(table_cell); v.setIdFacture(facture.getFacture()); } table_cell.setBorder(4); table_cell.setColspan(6); PDFLogReport.add(LogTable); PDFLogReport.close(); IVenteDAO v = new VenteDAO(); v.insertVente(ventes); }
From source file:tn.com.hitechart.eds.Util.pdfRpport.FirstPdf.java
private void createTable(Section subCatPart) throws BadElementException { //-------------------------- TAB POINTAGE -------------------// PdfPTable table = new PdfPTable(8); table.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); table.setLockedWidth(true);/*from ww w .java2 s. c o m*/ // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); //----------- C1 --------------// PdfPCell c1 = new PdfPCell(new Phrase("Date Rapport")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C2 --------------// c1 = new PdfPCell(new Phrase("Technicien")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C3 --------------// c1 = new PdfPCell(new Phrase("Poinatge")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); //----------- C4 --------------// c1 = new PdfPCell(new Phrase("Matin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); //----------- C5 --------------// c1 = new PdfPCell(new Phrase("Aprs-Midi")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); //----------- C6 --------------// c1 = new PdfPCell(new Phrase("Rapport Journalier", catFont)); c1.setBorder(Rectangle.NO_BORDER); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(3); table.addCell(c1); //----------- C7 --------------// //----------- C8 --------------// table.setHeaderRows(1); //----------- R2 --------------// //----------- C1 --------------// c1 = new PdfPCell(new Phrase(tabDatapointage[0], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setRowspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase(user.getLogin(), dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setRowspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("Arrive")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(tabDatapointage[1], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(tabDatapointage[2], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C7 --------------// c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C8 --------------// c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- R3 --------------// c1 = new PdfPCell(new Phrase("Sortie")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(tabDatapointage[3], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(tabDatapointage[4], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C7 --------------// c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C8 --------------// c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); table.setSpacingAfter(10); subCatPart.add(table); //-------------------------- END TAB POINTAGE -------------------// // TODO: 20/01/2017 //--------------------------------- TASK ---------------------// PdfPTable tableTask = new PdfPTable(5); tableTask.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableTask.setLockedWidth(true); PdfPCell c2 = new PdfPCell(new Phrase("Dossiers Traits", catFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setColspan(5); c2.setBorder(Rectangle.NO_BORDER); tableTask.addCell(c2); tableTask.setHeaderRows(1); c2 = new PdfPCell(new Phrase("NDoss.", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); c2 = new PdfPCell(new Phrase("Client", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); c2 = new PdfPCell(new Phrase("Dure", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); c2 = new PdfPCell(new Phrase("Mission", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); c2 = new PdfPCell(new Phrase("Resultat", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); if (tasks.isEmpty()) { c2 = new PdfPCell(new Phrase("Aucune Tache a t trait", catFontempty)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setColspan(5); tableTask.addCell(c2); } else { if (!dossiers.isEmpty()) { for (Dossier d : dossiers) { tableTask.addCell(d.getNumDoss()); tableTask.addCell(d.getClient()); tableTask.addCell(convertLongtoDurationfr(d.getTimeDuration())); tableTask.addCell(td.getTaskById(d.get_idTask()).getType()); tableTask.addCell(td.getTaskById(d.get_idTask()).getRes()); } } } tableTask.setSpacingAfter(10); subCatPart.add(tableTask); //-------------------------- END TAB TASK -------------------// // TODO: 20/01/2017 tab achat //-------------------------- TAB ACHAT -------------------// PdfPTable tableAchat = new PdfPTable(3); tableAchat.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableAchat.setLockedWidth(true); PdfPCell c3 = new PdfPCell(new Phrase("Frais Engags", catFont)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); c3.setColspan(3); c3.setBorder(Rectangle.NO_BORDER); tableAchat.addCell(c3); tableAchat.setHeaderRows(1); c3 = new PdfPCell(new Phrase("N.Doss.", dataFont)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); tableAchat.addCell(c3); c3 = new PdfPCell(new Phrase("Dsignation", dataFont)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); tableAchat.addCell(c3); c3 = new PdfPCell(new Phrase("Montant TCC", dataFont)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); tableAchat.addCell(c3); if (achats.isEmpty()) { c3 = new PdfPCell(new Phrase("la liste des achats est vide", catFontempty)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); c3.setColspan(3); tableAchat.addCell(c3); } else { for (Achat achat : achats) { tableAchat.addCell(String.valueOf(achat.getNumDoss())); tableAchat.addCell(achat.getDesignation()); tableAchat.addCell(String.valueOf(achat.getPrix())); } } tableAchat.setSpacingAfter(10); subCatPart.add(tableAchat); //-------------------------- END TAB ACHAT -------------------// // TODO: 20/01/2017 tab composant //-------------------------- TAB COMPOSANT -------------------// PdfPTable tableComp = new PdfPTable(3); tableComp.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableComp.setLockedWidth(true); PdfPCell c4 = new PdfPCell(new Phrase("Composants", catFont)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); c4.setColspan(3); c4.setBorder(Rectangle.NO_BORDER); tableComp.addCell(c4); tableComp.setHeaderRows(1); c4 = new PdfPCell(new Phrase("N.Doss.", dataFont)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); tableComp.addCell(c4); c4 = new PdfPCell(new Phrase("Dsignation", dataFont)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); tableComp.addCell(c4); c4 = new PdfPCell(new Phrase("Quantit", dataFont)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); tableComp.addCell(c4); if (comps.isEmpty()) { c4 = new PdfPCell(new Phrase("la liste des composants est vide", catFontempty)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); c4.setColspan(3); tableComp.addCell(c4); } else { for (Composant comp : comps) { tableComp.addCell(String.valueOf(comp.getNumDoss())); tableComp.addCell(comp.getName()); tableComp.addCell(String.valueOf(comp.getQte())); } } tableComp.setSpacingAfter(10); subCatPart.add(tableComp); //-------------------------- END TAB COMPOSANT -------------------// // TODO: 20/01/2017 tab message //-------------------------- TAB MESSAGE -------------------// PdfPTable tableMsg = new PdfPTable(2); tableMsg.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableMsg.setLockedWidth(true); PdfPCell c5 = new PdfPCell(new Phrase("Message Transmettre", catFont)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); c5.setColspan(3); c5.setBorder(Rectangle.NO_BORDER); tableMsg.addCell(c5); c5 = new PdfPCell(new Phrase("N.Doss.", dataFont)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); tableMsg.addCell(c5); tableMsg.setHeaderRows(1); c5 = new PdfPCell(new Phrase("Message", dataFont)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); tableMsg.addCell(c5); tableMsg.setHeaderRows(1); if (msgs.isEmpty()) { c5 = new PdfPCell(new Phrase("Aucun message", catFontempty)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); c5.setColspan(3); tableMsg.addCell(c5); } else { for (Message msg : msgs) { tableMsg.addCell(String.valueOf(msg.getNumDoss())); tableMsg.addCell(msg.getMsg()); } } tableMsg.setSpacingAfter(10); subCatPart.add(tableMsg); //-------------------------- END TAB MESSAGE -------------------// // TODO: 20/01/2017 tab Activitee //-------------------------- TAB ACTIVITEE -------------------// PdfPTable tableAct = new PdfPTable(2); tableAct.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableAct.setLockedWidth(true); PdfPCell c6 = new PdfPCell(new Phrase("Autre Activites", catFont)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); c6.setColspan(2); c6.setBorder(Rectangle.NO_BORDER); tableAct.addCell(c6); tableAct.setHeaderRows(1); c6 = new PdfPCell(new Phrase("N.Doss.", dataFont)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); tableAct.addCell(c6); c6 = new PdfPCell(new Phrase("Dure", dataFont)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); tableAct.addCell(c6); if (autreActs.isEmpty()) { c6 = new PdfPCell(new Phrase("Aucune autre Activite a t effectu", catFontempty)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); c6.setColspan(3); tableAct.addCell(c6); } else { for (Task autreA : autreActs) { tableAct.addCell(String.valueOf(autreA.getType())); tableAct.addCell(autreA.getNumDoss()); } } tableAct.setSpacingAfter(10); subCatPart.add(tableAct); //-------------------------- END TAB MESSAGE -------------------// }
From source file:Utility.PDFDemo.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);/*www. ja v a 2 s. c o m*/ //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:utils.PrintInvoice.java
public void getDocument() { try {/*from w ww . java 2 s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SaleBill#" + salebill.getId() + ".pdf")); document.open(); //////////////////////////////////////////////////////////////////////////////////// ///////////////////Start Document Here///////////////////////////////// PdfContentByte directContent = writer.getDirectContent(); Paragraph p1 = new Paragraph("SALE BILL"); p1.setFont(FONT[4]); p1.setAlignment(Element.ALIGN_CENTER); document.add(p1); //show the company details here. Phrase company = new Phrase(new Chunk("BIO PHARMA\nAKOT 444101(M.S)", FONT[3])); document.add(company); document.add(new Phrase( "\nLicense No : 20B : AK-88888\n 21B : AK-88889\n Mobile : " + SessionClass.getInstance().getMobileNumber(), FONT[2])); // Phrase mobNum = new Phrase(" Mobile : "+SessionClass.getInstance().getMobileNumber() ); // mobNum.setFont(FONT[2]); // ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, mobNum, 35, 710, 0); System.out.println(dateFormatter.format(salebill.getBillDate())); //show the invoice details // String txt = "Bill No. : " + salebill.getId()+"\nBill Date : " + dateFormatter.format(salebill.getBillDate()) +; Phrase invoiceDetails = new Phrase("Bill No. : " + salebill.getId()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 693, 0); invoiceDetails = new Phrase("Bill Date : " + dateFormatter2.format(salebill.getBillDate())); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 681, 0); invoiceDetails = new Phrase("Mode of Payment : " + salebill.getMode()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 668, 0); //show the customer details Customer c = salebill.getCustomerId(); Phrase custDetails = new Phrase("SOLD TO", FONT[3]); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 693, 0); custDetails = new Phrase(c.getCompanyName()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 681, 0); custDetails = new Phrase(c.getSiteAddress()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 668, 0); custDetails = new Phrase("Licence : " + c.getLicenceNo()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 655, 0); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); //Item Particulars are shown here PdfPTable table = new PdfPTable(7); table.setTotalWidth(new float[] { 175, 80, 80, 50, 50, 50, 75 }); table.setHeaderRows(1); //headers table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell("Particulars"); table.addCell("Batch"); table.addCell("Expiry"); table.addCell("MRP"); table.addCell("Rate"); table.addCell("Qnty"); table.addCell("SubTotal"); table.getDefaultCell().setBackgroundColor(null); table.setSpacingAfter(5.0f); List<SaleBillPharmaItem> items = salebill.getSaleBillPharmaItemList(); for (int i = 0; i < items.size(); i++) { PdfPCell desc = new PdfPCell(new Phrase(items.get(i).getItemName())); table.addCell(desc); PdfPCell batch = new PdfPCell(new Phrase(items.get(i).getBatch())); table.addCell(batch); PdfPCell expiry = null; Date tDate = null; try { tDate = dateFormatter2.parse(items.get(i).getExpDate()); } catch (ParseException ex) { Logger.getLogger(PrintInvoice.class.getName()).log(Level.SEVERE, null, ex); } expiry = new PdfPCell(new Phrase(dateFormatter.format(tDate))); table.addCell(expiry); PdfPCell mrp = new PdfPCell(new Phrase(items.get(i).getMrp() + "")); // //mrp.setBorderColor(BaseColor.WHITE); // mrp.setBorderColorLeft(BaseColor.BLACK); // mrp.setBorderColorRight(BaseColor.WHITE); table.addCell(mrp); PdfPCell rate = new PdfPCell(new Phrase(items.get(i).getItemRate() + "")); // //rate.setBorderColor(BaseColor.WHITE); // rate.setBorderColorLeft(BaseColor.BLACK); // rate.setBorderColorRight(BaseColor.WHITE); table.addCell(rate); PdfPCell quantity = new PdfPCell(new Phrase(items.get(i).getQnty() + "")); // //quantity.setBorderColor(BaseColor.WHITE); // quantity.setBorderColorLeft(BaseColor.BLACK); // quantity.setBorderColorRight(BaseColor.WHITE); table.addCell(quantity); PdfPCell subtotal = new PdfPCell(new Phrase(items.get(i).getAmt() + "")); // //subtotal.setBorderColor(BaseColor.WHITE); // subtotal.setBorderColorLeft(BaseColor.BLACK); // subtotal.setBorderColorRight(BaseColor.WHITE); table.addCell(subtotal); } //now show the sub details //PdfPCell finalCell = new PdfPCell(new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + " Total Amount : Rs ")); //Todo change code here to show vat amount when there is vat number PdfPCell finalCell = new PdfPCell( new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + " Total Amount : Rs ")); finalCell.setHorizontalAlignment(Element.ALIGN_RIGHT); finalCell.setColspan(6); table.addCell(finalCell); table.addCell("" + salebill.getTotalAmt()); PdfPCell cdCell = new PdfPCell(new Phrase("Cash Discount (2 %) : (-) Rs")); cdCell.setColspan(6); cdCell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cdCell); table.addCell("" + salebill.getDiscount()); PdfPCell finalAmtCell = new PdfPCell(new Phrase("Final Amount : Rs")); finalAmtCell.setColspan(6); finalAmtCell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(finalAmtCell); table.addCell("" + salebill.getFinalAmt()); document.add(table); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); Paragraph sign = new Paragraph(new Chunk("Authorized signatory\n(BIO PHARMA)")); sign.setAlignment(Element.ALIGN_RIGHT); document.add(sign); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); Paragraph p = new Paragraph("THANK YOU FOR YOUR BUSINESS"); p.setFont(FONT[4]); p.setAlignment(Element.ALIGN_CENTER); document.add(p); ///////////////////End Documnet here////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// document.close(); // no need to close PDFwriter? } catch (DocumentException | FileNotFoundException e) { //LOGGER e.printStackTrace(); Stage dialogStage = new Stage(); dialogStage.setTitle("Printing Error"); dialogStage.initModality(Modality.WINDOW_MODAL); dialogStage.setScene(new Scene(VBoxBuilder.create() .children(new Text( "The file to be printed is already open \n. Please close the file and Print Again")) .alignment(Pos.CENTER).padding(new Insets(50)).build())); dialogStage.show(); } }
From source file:utils.PrintUtils.java
public static PdfPCell createPdfPCell(String sCell, int colspan, boolean etatHori, Font font) { PdfPCell cell = new PdfPCell(new Paragraph(sCell, font)); cell.setColspan(colspan); if (etatHori) { cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); }//w ww .j av a2s . c om cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER); return cell; }
From source file:utils.PrintUtils.java
public static PdfPCell createPdfPCell(String sCell, int colspan, boolean etatHori) { PdfPCell cell = new PdfPCell(new Paragraph(sCell)); cell.setColspan(colspan); if (etatHori) { cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); }/* w w w . j a va2 s . c o m*/ cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER); return cell; }
From source file:View.TelaRelatorio.java
public void GerarEntrega(int codigo) throws IOException { NegociosCompra nc = new NegociosCompra(); Compra compra = nc.ConsultarCompra(codigo); Document documentoPDF = new Document(); String output = "C:\\Users\\Marilia Nayara\\Documents\\NetBeansProjects\\SistemaInformao\\Relatorios\\VendasEntrega\\Compra" + codigo + ".pdf"; try {//from w w w. j a v a2 s . c o m PdfWriter.getInstance(documentoPDF, new FileOutputStream(output)); documentoPDF.open(); documentoPDF.setPageSize(PageSize.A4); Image imagem = Image.getInstance( "C:\\Users\\Marilia Nayara\\Documents\\NetBeansProjects\\SistemaInformao\\src\\View\\image.png"); imagem.scaleToFit(100, 75); imagem.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(imagem); Font fonte1 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD); Paragraph agr = new Paragraph("Aplicao para Gesto de Restaurantes", fonte1); agr.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(agr); Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD); Paragraph cabecalho = new Paragraph("COMPRA ENTREGA", fonte); cabecalho.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(cabecalho); documentoPDF.add(new Paragraph("\n")); Cliente c = new NegociosCliente().ProcurarCliente(compra.getCpf_c()); Timestamp t = compra.getData(); SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); String a = formato.format(t); PdfPTable dadosC = new PdfPTable(new float[] { 0.10f, 0.70f, 0.20f }); List<String> dados = new ArrayList<String>(); dados.add("CODIGO DA COMPRA"); dados.add("CLIENTE"); dados.add("DATA DA COMPRA"); dados.add("" + compra.getCodigo()); dados.add(c.getNome()); dados.add(a); for (String s : dados) { dadosC.addCell(s); } dadosC.setWidthPercentage(110f); documentoPDF.add(dadosC); documentoPDF.add(new Paragraph("\n")); /*documentoPDF.add(new Paragraph(" LISTA DE PRODUTOS COMPRADOS")); documentoPDF.add(new Paragraph("\n")); documentoPDF.add(new Paragraph("Codigo Produto Valor Unitrio Quantidade Valor ")); String tam = "Codigo Produto Valor Unitrio Quantidade Valor "; JOptionPane.showMessageDialog(null, tam.length()); for(int x=0;x<compra.getLista_prod().size();x++){ Produto p = new NegociosProduto().ProcurarProduto(compra.getLista_prod().get(x).intValue()); String cod = ""+p.getCodigo(); String nome = p.getNome(); float pv = p.getPvenda(); String pvs = ""+pv; int quant = compra.getQuantidades().get(x).intValue(); String squant = ""+quant; float pf = pv*quant; String spf = ""+pf; int espaco = 13 - cod.length(); String esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } cod = cod+esp; espaco = 49 - nome.length(); esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } nome = nome + esp; espaco = 24 - pvs.length(); esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } pvs = pvs + esp; espaco = 23 - squant.length(); esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } squant = squant + esp; espaco = 8 - spf.length(); esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } spf = spf + esp; String fina = cod+nome+pvs+squant+spf; //JOptionPane.showMessageDialog(null, fina.length()); documentoPDF.add(new Paragraph(fina)); }*/ Font fonte3 = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL); // Criando uma tabela com 3 colunas PdfPTable table = new PdfPTable(new float[] { 0.1f, 0.45f, 0.15f, 0.15f, 0.15f }); table.setWidthPercentage(110.f); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("LISTA DE PRODUTOS COMPRADOS", fonte3); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 3 colunas header.setColspan(5); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela table.addCell(header); List<String> list = new ArrayList<String>(); list.add("CODIGO"); list.add("PRODUTO"); list.add("VALOR UNIT?RIO"); list.add("QUANTIDADE"); list.add("VALOR"); for (int x = 0; x < compra.getLista_prod().size(); x++) { Produto p = new NegociosProduto().ProcurarProduto(compra.getLista_prod().get(x).intValue()); String cod = "" + p.getCodigo(); String nome = p.getNome(); float pv = p.getPvenda(); String pvs = "" + pv; int quant = compra.getQuantidades().get(x).intValue(); String squant = "" + quant; float pf = pv * quant; String spf = "" + pf; list.add(cod); list.add(nome); list.add(pvs); list.add(squant); list.add(spf); } for (String s : list) { table.addCell(s); } documentoPDF.add(table); documentoPDF.add(new Paragraph("\n")); Paragraph total = new Paragraph("Total: " + compra.getPreco_final(), fonte3); total.setAlignment(Element.ALIGN_RIGHT); documentoPDF.add(total); documentoPDF.add(new Paragraph("\n")); PdfPTable endereco = new PdfPTable(new float[] { 0.30f, 0.80f }); endereco.setWidthPercentage(60f); endereco.setHorizontalAlignment(Element.ALIGN_CENTER); Paragraph tableH = new Paragraph("ENDEREO DE ENTREGA", fonte3); PdfPCell hea = new PdfPCell(tableH); hea.setColspan(2); hea.setHorizontalAlignment(Paragraph.ALIGN_CENTER); endereco.addCell(hea); List<String> dadosE = new ArrayList<String>(); dadosE.add("LOGRADOURO"); dadosE.add(c.getEndereco().getRua()); dadosE.add("NUMERO"); dadosE.add("" + c.getEndereco().getNumero()); dadosE.add("BAIRRO"); dadosE.add(c.getEndereco().getBairro()); dadosE.add("CIDADE"); dadosE.add(c.getEndereco().getCidade()); dadosE.add("ESTADO"); dadosE.add(c.getEndereco().getEstado()); for (String s : dadosE) { endereco.addCell(s); } documentoPDF.add(endereco); documentoPDF.add(new Paragraph("\n")); documentoPDF .add(new Paragraph("Assinatura: __________________________________________________________")); Paragraph ass = new Paragraph("(" + c.getNome() + ")", fonte1); ass.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(ass); documentoPDF.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); Paragraph comp = new Paragraph("COMPROVANTE DE ENTREGA"); comp.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(comp); documentoPDF.add(new Paragraph("\n")); documentoPDF.add(dadosC); documentoPDF.add(total); documentoPDF .add(new Paragraph("Assinatura: __________________________________________________________")); documentoPDF.add(ass); } catch (DocumentException de) { de.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { documentoPDF.close(); java.awt.Desktop.getDesktop().open(new File(output)); } }
From source file:Visao.grafico.GraficoRelatorioEstoque.java
private void GerarPDF() throws DocumentException, FileNotFoundException { try {//from ww w .ja v a 2 s .c om int linha = jTableRelatorioGrafico.getSelectedRow(); Document document = new Document(PageSize.A4, 10, 10, 10, 10); //System.out.println(new File(".").getAbsolutePath()); String arquivo = new File("RelatorioFaz.").getAbsolutePath() + "pdf"; PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(arquivo)); document.open(); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); //String titulo = jTableRelatorioEstoquePrincipal.getValueAt(linha, 3).toString()+ " "+jTableRelatorioEstoquePrincipal.getValueAt(linha, 2).toString()+"-"+jTableRelatorioEstoquePrincipal.getValueAt(linha, 0).toString(); String titulo = "Relatorio"; Paragraph pgt = new Paragraph(titulo, font); pgt.setAlignment(Element.ALIGN_CENTER); document.add(pgt); document.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(colunas.length); // Definindo uma fonte, com tamanho 20 e negrito PdfPCell header = new PdfPCell(new Paragraph(titulo, font)); header.setColspan(colunas.length); table.addCell(header); table.setWidthPercentage(100.0f); table.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL); //System.out.println("Tamanho: "+linhas.size()); font = new Font(Font.FontFamily.TIMES_ROMAN, 4, Font.NORMAL); for (String coluna : colunas) { table.addCell(new Paragraph(coluna, font)); } //varias linhas for (int i = 0; i < linhas.size(); i++) {//linha for (int j = 0; j < colunas.length; j++) {//coluna table.addCell(new Paragraph(jTableRelatorioGrafico.getValueAt(i, j).toString(), font)); } } document.add(table); document.add(new Paragraph(" ")); font = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); document.add(new Paragraph("Dados Totais", font)); font = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL); document.close(); JOptionPane.showMessageDialog(null, "PDF: " + arquivo + " gerado!"); } catch (FileNotFoundException | DocumentException | HeadlessException ex) { Logger.getLogger(GerarRelatorioEstoqueBasico.class.getName()).log(Level.SEVERE, null, "Erro ao gerar pdf: " + ex); JOptionPane.showMessageDialog(null, "Erro ao gerar pdf: " + ex); } }