List of usage examples for com.itextpdf.text FontFactory getFont
public static Font getFont(final String fontname, final String encoding, final float size, final int style, final BaseColor color)
Font
-object. From source file:com.coderbd.pos.pdf.CodePDF.java
public boolean genCodeVer2Pdf() throws UnsupportedEncodingException { if (isFixedRated == true) { barcodeQuantity = 12;/*from w ww .j a v a 2 s. c o m*/ } else { barcodeQuantity = 15; } try { String filename = ""; if (isFixedRated) { filename = directory + "\\" + product.getProductBarcode() + "_FIXED_TK" + ".pdf"; } else { filename = directory + "\\" + product.getProductBarcode() + ".pdf"; } Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(product.getProductBarcode()); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(7); pdfPTable.setWidthPercentage(98); float[] widths = { 0.22f, 0.04f, 0.22f, 0.04f, 0.22f, 0.04f, 0.22f }; pdfPTable.setWidths(widths); String codeName = getCodeName(product.getShop().getShopName(), product.getShop().getShopId(), (int) product.getProductBuyRate()); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Font titleArialFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font priceFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD); Paragraph paragraph = new Paragraph(codeName, titleArialFont); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); Paragraph fixedTKParagraph = new Paragraph("FIXED TK: " + product.getProductSellRate(), priceFont); PdfPCell fixedRateCell = new PdfPCell(fixedTKParagraph); fixedRateCell.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * */ if (isFixedRated == true) { pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); } /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.add(new Paragraph( "Shop Name: " + product.getShop().getShopName() + ", Name:" + product.getProductName() + "\n,Qty: " + product.getProductStock() + ", " + new Date().toString(), titleArialFont)); document.close(); return true; } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); return false; } }
From source file:com.coderbd.pos.pdf.OrderReportPDF.java
public boolean genPdf() throws UnsupportedEncodingException { List<SupplierOrderProductReport> soprs = sor.getSupplierOrderProductReports(); IDBuilder idBuilder = new IDBuilder(); Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD); try {/* w w w . ja va2s. co m*/ String timestamp = idBuilder.getUniqueTimeStampID(); String filename = sor.getSupplier().getSupplierName() + "_O" + sor.getSupplierOrderId() + "_" + timestamp + ".pdf"; String filePath = directory + "\\" + filename; Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filePath)); document.open(); PdfPTable pdfPTable = new PdfPTable(5); pdfPTable.setWidthPercentage(90); float[] widths = { 0.40f, 0.13f, 0.15f, 0.15f, 0.17f }; pdfPTable.addCell(new Paragraph("Product Name", headerFont)); pdfPTable.addCell(new Paragraph("Buy Rate", headerFont)); pdfPTable.addCell(new Paragraph("Primary Qty", headerFont)); pdfPTable.addCell(new Paragraph("Unsold Qty", headerFont)); pdfPTable.addCell(new Paragraph("Unsold Amount", headerFont)); pdfPTable.setWidths(widths); for (SupplierOrderProductReport sopr : soprs) { SupplierOrderProduct sop = sopr.getSupplierOrderProduct(); String name = sop.getSupplierProductName(); Double rate = sop.getSupplierRate(); Integer pQty = sop.getSupplierProductQuantity(); Integer unQty = sopr.getUnSoldProductQuantity(); Double unAmount = sopr.getUnSoldProductAmount(); Paragraph nameParag = new Paragraph(name, innerFont); Paragraph buyRateParag = new Paragraph(rate.toString(), innerFont); Paragraph primaryQuantityParag = new Paragraph(pQty.toString(), innerFont); Paragraph unsoldQuantityParag = new Paragraph(unQty.toString(), innerFont); Paragraph unsoldAmountParag = new Paragraph(unAmount.toString(), innerFont); PdfPCell nameCell = new PdfPCell(nameParag); PdfPCell buyRateCell = new PdfPCell(buyRateParag); PdfPCell primaryQuantityCell = new PdfPCell(primaryQuantityParag); PdfPCell unsoldQuantityCell = new PdfPCell(unsoldQuantityParag); PdfPCell unsoldAmountCell = new PdfPCell(unsoldAmountParag); pdfPTable.addCell(nameCell); pdfPTable.addCell(buyRateCell); pdfPTable.addCell(primaryQuantityCell); pdfPTable.addCell(unsoldQuantityCell); pdfPTable.addCell(unsoldAmountCell); } document.add(getHeader()); document.add(pdfPTable); document.add(getFooter()); document.add(new Paragraph(" Report Generated: " + new Date().toString(), innerFont)); document.close(); return true; } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); return false; } }
From source file:com.coderbd.pos.pdf.OrderReportPDF.java
public PdfPTable getFooter() throws DocumentException { Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD); PdfPTable pdfPTableFooter = new PdfPTable(2); pdfPTableFooter.setWidthPercentage(90); float[] widthsFooter = { 0.80f, 0.20f }; pdfPTableFooter.setWidths(widthsFooter); Paragraph totalSoldPara = new Paragraph("Total Sold: " + sor.getOrderTotalSoldAmount().toString(), headerFont);//www. j a va 2 s . c o m PdfPCell totalSoldCell = new PdfPCell(totalSoldPara); totalSoldCell.setBorder(Rectangle.NO_BORDER); Paragraph totalUnSoldPara = new Paragraph("Total UnSold: " + sor.getOrderTotalUnsoldAmount().toString(), headerFont); PdfPCell totalUnSoldCell = new PdfPCell(totalUnSoldPara); totalUnSoldCell.setBorder(Rectangle.NO_BORDER); Paragraph blankPara = new Paragraph(""); PdfPCell blankCell = new PdfPCell(blankPara); blankCell.setBorder(Rectangle.NO_BORDER); Double bill = sor.getTotalBill(); Double paid = sor.getTotalPaid(); Double due = bill - paid; Paragraph billPara = new Paragraph("BILL: " + bill.toString(), headerFont); PdfPCell billCell = new PdfPCell(billPara); billCell.setBorder(Rectangle.NO_BORDER); Paragraph paidPara = new Paragraph("PAID: " + paid.toString(), headerFont); PdfPCell paidCell = new PdfPCell(paidPara); paidCell.setBorder(Rectangle.NO_BORDER); Paragraph duePara = new Paragraph("DUE: " + due.toString(), headerFont); PdfPCell dueCell = new PdfPCell(duePara); dueCell.setBorder(Rectangle.NO_BORDER); pdfPTableFooter.addCell(totalSoldCell); pdfPTableFooter.addCell(billCell); pdfPTableFooter.addCell(totalUnSoldCell); pdfPTableFooter.addCell(paidCell); pdfPTableFooter.addCell(blankCell); pdfPTableFooter.addCell(dueCell); return pdfPTableFooter; }
From source file:com.coderbd.pos.pdf.OrderReportPDF.java
public PdfPTable getHeader() throws DocumentException { Font innerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font headerFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 12, Font.BOLD); PdfPTable tableHeader = new PdfPTable(1); tableHeader.setWidthPercentage(90);//from www . jav a 2 s . c o m Paragraph supplierNamePara = new Paragraph(sor.getSupplier().getSupplierName(), headerFont); Paragraph addressPara = new Paragraph(sor.getSupplier().getSupplierAddress(), innerFont); Paragraph mobilePara = new Paragraph("Mobile: " + sor.getSupplier().getSupplierMobile(), innerFont); Paragraph orderPara = new Paragraph("Order: " + sor.getSupplierOrderId() + ", Time: " + sor.getOrderTime(), innerFont); PdfPCell supplierNameCell = new PdfPCell(); supplierNameCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER); supplierNameCell.setBorder(Rectangle.NO_BORDER); supplierNameCell.addElement(supplierNamePara); PdfPCell addressCell = new PdfPCell(); addressCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); addressCell.setBorder(Rectangle.NO_BORDER); addressCell.addElement(addressPara); PdfPCell mobileCell = new PdfPCell(mobilePara); mobileCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); mobileCell.setBorder(Rectangle.NO_BORDER); mobileCell.addElement(mobilePara); PdfPCell orderCell = new PdfPCell(orderPara); orderCell.setBorder(Rectangle.NO_BORDER); PdfPCell bCell = new PdfPCell(new Paragraph(" ")); bCell.setBorder(Rectangle.NO_BORDER); tableHeader.addCell(supplierNameCell); tableHeader.addCell(addressCell); tableHeader.addCell(mobileCell); tableHeader.addCell(orderCell); tableHeader.addCell(bCell); return tableHeader; }
From source file:com.myapp.struts.transaction.transactionAction.java
public ActionForward generatememberreport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SQLException, Exception { if (Constants.isSessionActive(request)) { transactionForm transactionForm = (transactionForm) form; try {//from w ww. jav a2 s . co m Date utilDate = new Date(); java.sql.Date date = new java.sql.Date(utilDate.getTime()); Font bigFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD, BaseColor.BLACK); Font bigFont_Uderline = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD | Font.UNDERLINE, BaseColor.BLACK); Font boldfont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 9, Font.BOLD); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); //Or whatever format fits best your needs. Paragraph para1 = new Paragraph("PALKE JEWELLERS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph("MEMBER ACCOUNT DETAILS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph(transactionForm.getSelectedmember(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph( transactionForm.getMemberaddress() + "\n" + transactionForm.getMembercontactno(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); Groups obj = (Groups) hmGroups.get(transactionForm.getGroupid() + ""); if (obj != null) { para1 = new Paragraph("Group : " + obj.getGroupname(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Paid Amount : " + transactionForm.getTotalpaidamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Prize Amount : " + transactionForm.getDrawamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Total Amount : " + transactionForm.getTotalamount(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Status : " + transactionForm.getStatus(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); if (transactionForm.getStatus().equalsIgnoreCase("Settled")) { para1 = new Paragraph(transactionForm.getSettlementcomment(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); } String dateStr = sdf.format(date); para1 = new Paragraph("DATED:" + dateStr, font); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); // add a couple of blank lines document.add(Chunk.NEWLINE); if (transactionForm.getLstPayment() != null && transactionForm.getLstPayment().size() > 0) { PdfPTable table2 = new PdfPTable(7); float[] columnWidths = { 1.5f, 1.5f, 3f, 4f, 4f, 7f, 2f }; table2.setWidthPercentage(100); table2.setWidths(columnWidths); para1 = new Paragraph("Sl No.", font); para1.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Term", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt No.", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt Date", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Payment Mode", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Remarks", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Paid Amount", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); int x = 1; double total = 0; //Iterator it = hmPayments.entrySet().iterator(); //while (it.hasNext()) { if (hmPayments.size() > 0) { for (int i = 1; i <= obj.getNoofinstallment(); i++) { //float f = columnWidths[i]; Payment f1 = (Payment) hmPayments.get(i + ""); //} //Map.Entry pairs = (Map.Entry) it.next(); //Payment f1 = (Payment) pairs.getValue(); String term = i + ""; para1 = new Paragraph(Integer.toString(x), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); x++; para1 = new Paragraph(term, font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentid() + "", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(sdf.format(f1.getPaiddate()), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentmode() == 1 ? "Cash" : "Cheque/NEFT", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getRemarks(), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); //para1 = new Paragraph(f1.getPaidamount() + "", boldfont); para1 = new Paragraph((int) obj.getInstallmentamount() + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); total = total + obj.getInstallmentamount(); if (hmPayments.size() == i) { break; } } para1 = new Paragraph("Total", boldfont); para1.setAlignment(Element.ALIGN_LEFT); cell = new PdfPCell(para1); cell.setColspan(6); table2.addCell(cell); //String numberStr = String.format("%.2f", total + ""); para1 = new Paragraph(total + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); //cell.setColspan(7); table2.addCell(cell); table2.setHorizontalAlignment(Element.ALIGN_LEFT); document.add(table2); } else { para1 = new Paragraph("NO PAYMENTS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } document.add(Chunk.NEWLINE); //document.close(); //fileInputStream = new FileInputStream(new File("C:\\reports\\PaymentReports.pdf")); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } } catch (DocumentException i) { System.out.println(i); return mapping.findForward("fail"); } catch (IOException i) { System.out.println(i); return mapping.findForward("fail"); } } else { return mapping.findForward("exp"); } }
From source file:cz.zcu.kiv.eegdatabase.logic.pdf.ReservationPDF.java
License:Apache License
public static PdfPTable formatReservation(Reservation reservation) { int padding = 5; GregorianCalendar created = new GregorianCalendar(); created.setTime(reservation.getCreationTime()); GregorianCalendar startTime = new GregorianCalendar(); startTime.setTime(reservation.getStartTime()); GregorianCalendar endTime = new GregorianCalendar(); endTime.setTime(reservation.getEndTime()); String personName = BookingRoomUtils.formatPersonName(reservation.getPerson()); Font title = FontFactory.getFont("Trebuchet MS", "utf-8", 15, Font.BOLD, new BaseColor(59, 70, 00)); Font header = FontFactory.getFont(FontFactory.TIMES_BOLD, 13, Font.BOLD, BaseColor.BLACK); Font value = FontFactory.getFont(FontFactory.TIMES, 13); PdfPTable table = new PdfPTable(2); PdfPCell cell;/*from ww w . j a v a 2 s.com*/ Phrase phrase; phrase = new Phrase("Reservation by " + personName); phrase.setFont(title); cell = new PdfPCell(phrase); cell.setColspan(2); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthTop(1); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPadding(padding); cell.setPaddingBottom(5); table.addCell(cell); phrase = new Phrase("Date: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getDate(startTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase("Start: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(startTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase("End: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setBorderWidthBottom(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(endTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setBorderWidthBottom(1); cell.setPadding(padding); table.addCell(cell); table.setSpacingBefore(10); table.setSpacingAfter(10); return table; }
From source file:de.jost_net.JVerein.io.Reporter.java
License:Open Source License
public static Font getFreeSans(float size, BaseColor color) { return FontFactory.getFont("/fonts/FreeSans.ttf", BaseFont.IDENTITY_H, size, Font.UNDEFINED, color); }
From source file:de.jost_net.JVerein.io.Reporter.java
License:Open Source License
public static Font getFreeSansBold(float size, BaseColor color) { return FontFactory.getFont("/fonts/FreeSansBold.ttf", BaseFont.IDENTITY_H, size, Font.UNDEFINED, color); }