List of usage examples for com.itextpdf.text.pdf BaseFont WINANSI
String WINANSI
To view the source code for com.itextpdf.text.pdf BaseFont WINANSI.
Click Source Link
From source file:Almacen.Reporte2.java
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);/*from www. j a v a2 s . c om*/ if (t_datos2.getRowCount() > 0) { javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction().begin(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); PDF reporte = new PDF(); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); reporte.Abrir2(PageSize.LETTER, "reporte pedidos", ruta + ".pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float[] nuevos = new float[] { 60, 340, 170, 60, 90, 90, 90 }; PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_CENTER); cabecera1(reporte, bf, tabla, "Reporte de Consultar Pedidos.", 1); for (int ren = 0; ren < t_datos2.getRowCount(); ren++) { for (int col = 0; col < t_datos2.getColumnCount(); col++) { try { tabla.addCell(reporte.celda(t_datos2.getValueAt(ren, col).toString(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } catch (Exception e) { tabla.addCell( reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } } } tabla.setHeaderRows(1); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto."); } if (session != null) if (session.isOpen()) session.close(); } } } }
From source file:book.pdfabc.chapter05.C0505_SupportedEncoding.java
public static void main(String[] args) throws DocumentException, IOException { C0505_SupportedEncoding app = new C0505_SupportedEncoding(); app.listEncodings(BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED)); app.listEncodings(BaseFont.createFont(TYPE1, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED)); app.listEncodings(BaseFont.createFont(OT_T1, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED)); app.listEncodings(BaseFont.createFont(OT_TT, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED)); }
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Generate a bout sheet report for the given list of bouts. * It is assumed that the list is in the desired order (no sorting is done here). * * @param list// www. ja v a 2s . c o m * @return True if the report was generated. */ public boolean generateReport(Dao dao, List<Bout> list) { // step 1: creation of a document-object // rotate to make page landscape Document document = new Document(PageSize.A4.rotate()); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); writer.setPageEvent(this); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); float pageWidth = cb.getPdfDocument().getPageSize().getWidth(); float midPage = pageWidth / 2; setHeaderString(dao); int count = 0; for (Bout b : list) { boolean rightSide = false; if ((count++ % 2) == 0) { if (count > 2) { // We could put this after Bout 2 is added, but // that could leave a blank last page. document.newPage(); } // Bout 1 (Left side) drawBout(cb, bf, 35, midPage - 35, b); } else { // Bout 2 (Right side) drawBout(cb, bf, midPage + 35, pageWidth - 35, b); rightSide = true; } // Print the watermark, if necessary boolean doWatermark = false; String gClass = b.getGroup().getClassification(); String wmValues = dao.getBoutsheetWatermarkValues(); if ((wmValues != null) && !wmValues.isEmpty()) { String[] tokens = wmValues.split(","); for (String s : tokens) { if (s.trim().equalsIgnoreCase(gClass)) { doWatermark = true; break; } } } if (doWatermark) { int rotation = 45; PdfContentByte ucb = writer.getDirectContentUnder(); BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); ucb.saveState(); ucb.setColorFill(BaseColor.LIGHT_GRAY); ucb.beginText(); ucb.setFontAndSize(helv, 86); float centerWidth = document.getPageSize().getWidth() / 4; if (rightSide) { centerWidth = centerWidth * 3; } ucb.showTextAligned(Element.ALIGN_CENTER, gClass, centerWidth, document.getPageSize().getHeight() / 2, rotation); ucb.endText(); ucb.restoreState(); } } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Set the string for the page header.//from ww w . j av a 2 s . co m * @param dao Dao object to use to retrieve data. */ private void setHeaderString(Dao dao) { try { this.baseFont = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); this.headerString = String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()); } catch (DocumentException de) { logger.error("Document Exception", de); this.headerString = null; } catch (IOException ioe) { logger.error("IO Exception", ioe); this.headerString = null; } }
From source file:bouttime.report.bracketsheet.BracketSheetReport.java
License:Open Source License
public static boolean generateReport(Dao dao, List<Group> list, String outputFile, boolean doBoutNumbers, boolean doTimestamp) { if (list.isEmpty()) { return false; }//from w w w . ja va 2 s .c o m // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(outputFile); if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); String timestamp = ""; if (doTimestamp) { timestamp = DateFormat.getInstance().format(new Date()); } int rv; int i = 0; int size = list.size(); for (Group g : list) { rv = addBracket(cb, dao, g, doBoutNumbers); if (rv != PAGE_ERROR) { // Print the watermark, if necessary boolean doWatermark = false; String gClass = g.getClassification(); String wmValues = dao.getBracketsheetWatermarkValues(); if ((wmValues != null) && !wmValues.isEmpty()) { String[] tokens = wmValues.split(","); for (String s : tokens) { if (s.trim().equalsIgnoreCase(gClass)) { doWatermark = true; break; } } } int rotation = (rv == PAGE_ROUNDROBIN) ? 45 : 135; if (doWatermark) { PdfContentByte ucb = writer.getDirectContentUnder(); BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); ucb.saveState(); ucb.setColorFill(BaseColor.LIGHT_GRAY); ucb.beginText(); ucb.setFontAndSize(helv, 86); ucb.showTextAligned(Element.ALIGN_CENTER, gClass, document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, rotation); ucb.endText(); ucb.restoreState(); } if (doTimestamp) { rotation -= 45; float width = cb.getPdfWriter().getPageSize().getWidth(); int x = (rv == PAGE_ROUNDROBIN) ? 15 : (int) (width - 15); int y = 15; BracketSheetUtil.drawTimestamp(cb, null, x, y, 10, timestamp, rotation); } // If not doing bout numbers, this is an 'award' type of // bracket. So print an image/logo, if configured. if (!doBoutNumbers && (dao.getBracketsheetAwardImage() != null) && !dao.getBracketsheetAwardImage().isEmpty()) { Image image = Image.getInstance(Image.getInstance(dao.getBracketsheetAwardImage())); image.setRotationDegrees((rv == PAGE_ROUNDROBIN) ? 0 : 90); PositionOnPage positionOnPage = dao.getBracketsheetAwardImagePosition(); if (PositionOnPage.UPPER_RIGHT == positionOnPage) { float x = (rv == PAGE_ROUNDROBIN) ? document.getPageSize().getWidth() - 10 - image.getWidth() : 10; float y = document.getPageSize().getHeight() - 10 - image.getHeight(); image.setAbsolutePosition(x, y); cb.addImage(image); } else if (PositionOnPage.CENTER == positionOnPage) { // put the image in the background, in the middle of the page PdfContentByte ucb = writer.getDirectContentUnder(); float pageX = document.getPageSize().getWidth() / 2; float pageY = document.getPageSize().getHeight() / 2; float imageX = image.getWidth() / 2; float imageY = image.getHeight() / 2; image.setAbsolutePosition(pageX - imageX, pageY - imageY); ucb.addImage(image); } } if (++i < size) { document.newPage(); } } } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bussiness.ReportHandler.java
private void BuildHeaderPrescription(Document veterinaryPrescription, String clientName, String petName) throws DocumentException, IOException { BaseFont baseFont = BaseFont.createFont("Cookie.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED); Font font = new Font(baseFont); font.setStyle(Font.BOLDITALIC); font.setSize(35);/*w w w . j a va 2 s . co m*/ Doctor doctor = SessionManager.getLoggedDoctor(); Paragraph p1 = new Paragraph("Dr. " + doctor.getName(), font); p1.setAlignment(Element.ALIGN_CENTER); veterinaryPrescription.add(p1); // veterinaryPrescription.add(new Chunk("\n")); Font font2 = new Font(); font2.setSize(20); Paragraph p2 = new Paragraph("CEDULA PROFESIONAL " + doctor.getIdentityCard(), font2); p2.setAlignment(Element.ALIGN_CENTER); veterinaryPrescription.add(p2); veterinaryPrescription.add(new Chunk("\n")); Paragraph p3 = new Paragraph("Nombre del cliente: " + clientName, font2); veterinaryPrescription.add(p3); Paragraph p4 = new Paragraph("Nombre de la mascota: " + petName, font2); veterinaryPrescription.add(p4); }
From source file:com.coderbd.pos.pdf.CodePDF.java
public boolean genCodeVer2Pdf() throws UnsupportedEncodingException { if (isFixedRated == true) { barcodeQuantity = 12;/*from w w w . jav a2 s . c om*/ } 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 {/*from ww w. j a v a2s . c o 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);//w ww .ja v a2 s . c om 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 . j a va 2s. c om 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; }