List of usage examples for com.itextpdf.text.pdf BarcodeEAN createImageWithBarcode
public Image createImageWithBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)
Image
with the barcode. From source file:EmployeeInfo.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed String value1 = txt_empID.getText(); String value2 = txt_firstName.getText(); String value3 = txt_lastName.getText(); String value4 = txt_age.getText(); try {//from w w w. ja v a 2s . com Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Report1.pdf")); document.open(); //add barcode PdfContentByte CB = writer.getDirectContent(); BarcodeEAN codEAN = new BarcodeEAN(); codEAN.setCode("1234567891023"); //this value must be 13 digits Paragraph para = new Paragraph(); document.add(new Paragraph("Barcode UDCA")); codEAN.setCodeType(BarcodeEAN.UPCA); codEAN.setCode("1098765432112"); document.add(codEAN.createImageWithBarcode(CB, BaseColor.BLACK, BaseColor.BLACK)); document.add(para); Image image = Image.getInstance("images/Cherry.png"); document.add(new Paragraph("Image")); document.add(image); // write tile with style document.add(new Paragraph("Hello World", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED))); // write date document.add(new Paragraph(new Date().toString())); document.add(new Paragraph("--------------------------------------------")); PdfPTable table = new PdfPTable(2);// 2 columns // set title , column sapn, aliignment,background color PdfPCell cell = new PdfPCell(new Paragraph("Title")); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.BLUE); table.addCell(cell); // PdfPTable table = new PdfPTable(x); should add multiple of x table.addCell("EmployeeID"); table.addCell(value1); table.addCell("Name"); table.addCell(value2); table.addCell("Last Name"); table.addCell(value3); table.addCell("Age"); table.addCell(value4); document.add(table); List list = new List(true, 20); list.add("First Item"); list.add("Second Item"); list.add("Third Item"); list.add("Fourth Item"); document.add(list); document.close(); JOptionPane.showMessageDialog(null, "Report saved"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:com.maxl.java.amikodesk.SaveBasket.java
License:Open Source License
public PdfPTable getShoppingBasketForAuthor(Author a, PdfContentByte cb) { int position = 0; float subtotal_CHF = 0.0f; float shipping_CHF = 0.0f; float vat25_CHF = 0.0f; float vat80_CHF = 0.0f; String author = a.getShortName(); BarcodeEAN codeEAN = new BarcodeEAN(); // Pos | Menge | Eancode | Bezeichnung | MwSt | Preis PdfPTable table = new PdfPTable(new float[] { 1, 2, 3, 6, 1, 2 }); table.setWidthPercentage(100f);/*ww w . ja v a 2 s .c o m*/ table.getDefaultCell().setPadding(5); table.setSpacingAfter(5f); PdfPCell cell = new PdfPCell(); table.addCell(getStringCell(m_rb.getString("position"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("quantity"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("ean"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("article"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("vat"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1)); table.addCell(getStringCell(m_rb.getString("price") + " (CHF)", font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1)); if (m_shopping_basket.size() > 0 && !author.isEmpty()) { for (Map.Entry<String, Article> entry : m_shopping_basket.entrySet()) { Article article = entry.getValue(); if (article.getAuthor().trim().toLowerCase().contains(author)) { String price_pruned = ""; String total_price_CHF = ""; if (article.getCode() != null && article.getCode().equals("ibsa")) { float cr = article.getCashRebate(); if (article.getDraufgabe() > 0) { price_pruned = String.format("%.2f", article.getBuyingPrice(0.0f)); total_price_CHF = String.format("%.2f", article.getTotBuyingPrice(0.0f)); } else { price_pruned = String.format("%.2f", article.getBuyingPrice(cr)); total_price_CHF = String.format("%.2f", article.getTotBuyingPrice(cr)); } } else { price_pruned = article.getCleanExfactoryPrice(); total_price_CHF = String.format("%.2f", article.getTotExfactoryPrice()); } if (!price_pruned.isEmpty() && !price_pruned.equals("..")) { // Index table.addCell(getStringCell(Integer.toString(++position), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); // Anzahl table.addCell(getStringCell(Integer.toString(article.getQuantity()), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); // EAN code codeEAN.setCode(article.getEanCode()); Image img = codeEAN.createImageWithBarcode(cb, null, null); img.scalePercent(120); cell = new PdfPCell(img); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setUseBorderPadding(true); cell.setBorderWidth(5); if (position == 1) cell.setPaddingTop(8); else cell.setPaddingTop(0); cell.setPaddingBottom(8); table.addCell(cell); // Artikelbezeichnung table.addCell(getStringCell(article.getPackTitle(), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); // MwSt table.addCell(getStringCell(String.format("%.1f%%", article.getVat()), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1)); // Preis (exkl. MwSt) // float price_CHF = article.getQuantity()*Float.parseFloat(price_pruned); table.addCell(getStringCell(total_price_CHF, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1)); } } } subtotal_CHF = a.getSubtotal(); shipping_CHF = a.getShippingCosts(); vat25_CHF = a.getVat25(); vat80_CHF = a.getVat80() + a.getShippingCosts() * 0.08f; float fulltotal_CHF = subtotal_CHF + shipping_CHF + vat25_CHF + vat80_CHF; table.addCell(getStringCell(m_rb.getString("subtotal"), font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", subtotal_CHF), font_bold_10, Rectangle.TOP, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("shipping"), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", shipping_CHF), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("vat") + " (2.5%)", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", vat25_CHF), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("vat") + " (8.0%)", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", vat80_CHF), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("gesamttotal"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", fulltotal_CHF), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); } return table; }
From source file:com.maxl.java.amikodesk.SaveBasket.java
License:Open Source License
public PdfPTable getFullShoppingBasket(PdfContentByte cb, String mode) { int position = 0; float sub_total_CHF = 0.0f; BarcodeEAN codeEAN = new BarcodeEAN(); // Pos | Menge | Eancode | Bezeichnung | Preis PdfPTable table = new PdfPTable(new float[] { 1, 1, 3, 6, 2 }); table.setWidthPercentage(100f);// ww w . jav a 2 s . c o m table.getDefaultCell().setPadding(5); table.setSpacingAfter(5f); PdfPCell cell = new PdfPCell(); table.addCell(getStringCell(m_rb.getString("position"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("quantity"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("ean"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("article"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("price") + " (CHF)", font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1)); if (m_shopping_basket.size() > 0) { for (Map.Entry<String, Article> entry : m_shopping_basket.entrySet()) { Article article = entry.getValue(); if (mode.equals("all") || (mode.equals("rest") && (m_map_of_authors == null || !anyElemIsContained(m_map_of_authors, article.getAuthor().trim().toLowerCase())))) { String price_pruned = ""; if (article.getCode() != null && article.getCode().equals("ibsa")) { float cr = article.getCashRebate(); if (article.getDraufgabe() > 0) price_pruned = String.format("%.2f", article.getBuyingPrice(0.0f)); else price_pruned = String.format("%.2f", article.getBuyingPrice(cr)); } else { price_pruned = article.getCleanExfactoryPrice(); } if (!price_pruned.isEmpty() && !price_pruned.equals("..")) { table.addCell(getStringCell(Integer.toString(++position), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(Integer.toString(article.getQuantity()), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); codeEAN.setCode(article.getEanCode()); Image img = codeEAN.createImageWithBarcode(cb, null, null); img.scalePercent(120); cell = new PdfPCell(img); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setUseBorderPadding(true); cell.setBorderWidth(5); if (position == 1) cell.setPaddingTop(8); else cell.setPaddingTop(0); cell.setPaddingBottom(8); table.addCell(cell); table.addCell(getStringCell(article.getPackTitle(), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); float price_CHF = article.getQuantity() * Float.parseFloat(price_pruned); sub_total_CHF += price_CHF; table.addCell(getStringCell(String.format("%.2f", price_CHF), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1)); } } } table.addCell(getStringCell(m_rb.getString("subtotal"), font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", sub_total_CHF), font_bold_10, Rectangle.TOP, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("vat") + " (2.5%)", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", sub_total_CHF * 0.025f), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("gesamttotal"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", sub_total_CHF * 1.025f), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); } return table; }
From source file:itext_result.Main.java
private int developScreeningSheet() { new SwingWorker<Object, Object>() { String filename;//from ww w . j a v a 2 s . c om @Override protected void done() { // ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. "); } public PdfPCell createBarcode(PdfWriter writer, String code) throws DocumentException, IOException { BarcodeEAN barcode = new BarcodeEAN(); barcode.setCodeType(Barcode.EAN8); barcode.setCode(code); PdfPCell cell = new PdfPCell( barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY), true); cell.setPadding(10); return cell; } class ImageContent implements PdfPTableEvent { protected com.itextpdf.text.Image content; public ImageContent(com.itextpdf.text.Image content) { this.content = content; } public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { try { PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS]; float x = widths[3][1] + 10; float y = heights[3] - 10 - content.getScaledHeight(); content.setAbsolutePosition(x, y); canvas.addImage(content); } catch (DocumentException e) { throw new ExceptionConverter(e); } } } @Override protected Object doInBackground() throws Exception { // System.err.println(" Roll No Received ....." + rollno); Document doc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("12345" + ".pdf")); doc.open(); doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : "); doc.addSubject("Confidential Report Eyes Only"); doc.addKeywords(""); doc.addAuthor("SOS"); doc.addCreator("SOS"); // A4 = 210mm x 297mm ~ 605points x 855points doc.setPageSize(PageSize.A5); doc.setMargins(15f, 15f, 15f, 15f); ///////////////////////////////////////////////////////////// int pageno = 1; for (int i = 0; i == pageno; i++) { // doc.add(imageRight); } PdfContentByte cb = writer.getDirectContent(); //DONE BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCodeType(Barcode.EAN8); Barcode128 code128 = new Barcode128(); code128.setCode(String.valueOf("123456")); Barcode128 code128_jacket = new Barcode128(); code128_jacket.setCode(String.valueOf("10345")); codeEAN.setCode(String.valueOf("123456")); com.itextpdf.text.Image imageEAN = code128.createImageWithBarcode(cb, null, null); // imageEAN.scalePercent(10f); //464f, 725f // imageEAN.setAbsolutePosition(474f, 662f); int i = 1; while (i <= pageno) { doc.newPage(); // cb.addImage(imageRight); // cb.addImage(imageEAN); i++; } com.itextpdf.text.Image carcode = code128_jacket.createImageWithBarcode(cb, null, null); carcode.scaleAbsolute(100f, 35f); carcode.setAbsolutePosition(500f, 600f); writer.addDirectImageSimple(carcode); // cb.addImage(carcode); com.itextpdf.text.Image carcode2 = code128.createImageWithBarcode(cb, null, null); carcode2.scaleAbsolute(100f, 35f); carcode2.setAbsolutePosition(450f, 760f); writer.addDirectImageSimple(carcode2); // cb.addImage(carcode2); Image image1 = Image.getInstance("jklogo.gif"); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(99); table.addCell(image1); doc.add(table); table = new PdfPTable(4); table.setWidthPercentage(99); float[] columnWidths = { 6, 2 }; PdfPTable CandidateTable = new PdfPTable(columnWidths); Font f = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); Font fsmall = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); PdfPCell rollno = new PdfPCell(new Phrase("Roll No# " + String.valueOf("123456"), fsmall)); PdfPCell cname = new PdfPCell(new Phrase("Name #" + String.valueOf("John Doe"), fsmall)); // DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); // String today = formatter.format(cInfo.getDob()); PdfPCell dob = new PdfPCell(new Phrase("DOB#" + String.valueOf("12-03-1989"), fsmall)); PdfPCell fname = new PdfPCell(new Phrase("F/H Name #" + String.valueOf("Big John"), fsmall)); PdfPCell type = new PdfPCell(new Phrase("Total Time #" + String.valueOf("350.00"), fsmall)); // String scrtoday = formatter.format(cInfo.getScreeningdate()); // System.out.println("Today : " + today); PdfPCell scrdate = new PdfPCell(new Phrase("Laps #" + String.valueOf("4"), fsmall)); PdfPCell cell = new PdfPCell(new Phrase(" ", fsmall)); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); dob.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); fname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); type.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); scrdate.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); CandidateTable.addCell(rollno); CandidateTable.addCell(cell); CandidateTable.addCell(cname); CandidateTable.addCell(cell); CandidateTable.addCell(dob); CandidateTable.addCell(cell); PdfPTable CandidateOtherTable = new PdfPTable(columnWidths); CandidateOtherTable.addCell(fname); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(scrdate); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(type); CandidateOtherTable.addCell(cell); PdfPCell race_start_time = new PdfPCell(new Phrase("Start Time :XX-XX-XX ", fsmall)); PdfPCell race_end_time = new PdfPCell(new Phrase("End Time :XX-XX-XX", fsmall)); PdfPCell race_total_time = new PdfPCell(new Phrase("Total Time : 350.00 ", fsmall)); race_start_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_end_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_total_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); PdfPTable CandidateRaceDetails = new PdfPTable(columnWidths); CandidateRaceDetails.addCell(race_start_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_end_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_total_time); CandidateRaceDetails.addCell(cell); PdfPTable tablewith3cells = new PdfPTable(3); //1 St Col for Roll No Name and DOB tablewith3cells.addCell(CandidateTable); //2 nd Col for Father Name sCREEning Date Gurkha tablewith3cells.addCell(CandidateOtherTable); //3rd Col for Barcode to be Printed tablewith3cells.addCell(CandidateRaceDetails); // Setting the Width here to 101 tablewith3cells.setWidthPercentage(99); doc.add(tablewith3cells); PdfPTable userArea = new PdfPTable(1); userArea.setWidthPercentage(99); userArea.addCell(" \n \n Congratulations \n \n "); doc.add(userArea); PdfPTable footerCSBC = new PdfPTable(2); footerCSBC.setWidthPercentage(99); PdfPCell height_box = new PdfPCell(new Phrase("Height \n\n\n", f)); height_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_box = new PdfPCell(new Phrase("Chest \n\n\n", f)); chest_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_exp_box = new PdfPCell(new Phrase("Chest Exp \n\n\n", f)); chest_exp_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell pushup_box = new PdfPCell(new Phrase("Pushup \n\n\n", f)); pushup_box.setBorder(com.itextpdf.text.Rectangle.BOX); //CSignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); // ASignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); footerCSBC.addCell(height_box); footerCSBC.addCell(chest_box); footerCSBC.addCell(chest_exp_box); footerCSBC.addCell(pushup_box); doc.add(footerCSBC); float[] columnWidths_ForBarcode = { 6, 3 }; PdfPTable terminalinfo = new PdfPTable(columnWidths_ForBarcode); // terminalinfo.setWidthPercentage(99); String computername = InetAddress.getLocalHost().getHostName(); System.out.println(computername); PdfPCell pcname = new PdfPCell(new Phrase("\t Jacket \n\n ", f)); String UserMatchScore = "\t Barcode\n\n"; PdfPCell score = new PdfPCell(new Phrase(UserMatchScore, f)); PdfPCell barcode = new PdfPCell(carcode2); PdfPCell jacketnumber = new PdfPCell(carcode); pcname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); score.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); barcode.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); jacketnumber.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); terminalinfo.addCell(score); terminalinfo.addCell(pcname); terminalinfo.addCell(barcode); terminalinfo.addCell(jacketnumber); doc.add(terminalinfo); PdfPCell eula_notice = new PdfPCell(new Phrase(" ", f)); eula_notice.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable eula_notice_table = new PdfPTable(1); eula_notice_table.setWidthPercentage(25); eula_notice_table.addCell(eula_notice); doc.add(eula_notice_table); } catch (Exception e) { System.err.println(e.getMessage()); // ConsoleMsg(e.getMessage()); } finally { doc.close(); doc.close(); doc.close(); } //ConsoleMsg("PDF... GENERATED"); return null; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }.execute(); return 0; }
From source file:org.unesco.jisis.printsort.BarCodeGenerator.java
/** Creating a barcode image using BarcodeEAN for myText*/ public Image createBarcodeEAN(String myText) { BarcodeEAN myBarcodeEAN = new BarcodeEAN(); myBarcodeEAN.setCodeType(Barcode.EAN13); // 13 characters. myBarcodeEAN.setCode(myText);/*w w w . ja v a2 s . c o m*/ Image myBarCodeImageEAN = myBarcodeEAN.createImageWithBarcode(contentByte, null, null); return myBarCodeImageEAN; }
From source file:py.com.palermo.imprimeetiquetas.web.ProductoController.java
public String createPdf() throws IOException, DocumentException { if (hayParaImprimir()) { HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.setContentType("application/x-pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"etiquetas.pdf\""); // step 1 Document document = new Document(new Rectangle(86, 35)); // step 2 document.setMargins(0f, 0f, 0f, 0f); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // step 3 document.open();// www . ja va 2 s . c om // step 4 PdfContentByte cb = writer.getDirectContent(); for (ProductoCantidad p : productos) { if (p.getCantidad() > 0) { BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCode(p.getCodigo()); codeEAN.setCodeType(Barcode.EAN13); codeEAN.setBarHeight(10f); codeEAN.setX(0.7f); codeEAN.setSize(4f); NumberFormat nf = NumberFormat.getCurrencyInstance(new Locale("es", "py")); Font fontbold = FontFactory.getFont("Times-Roman", 5, Font.NORMAL); Chunk productTitle = new Chunk(p.getNombre() + "," + " " + nf.format(p.getPrecio()), fontbold); // EAN 13 Paragraph pTitile = new Paragraph(productTitle); pTitile.setAlignment(Element.ALIGN_CENTER); pTitile.setLeading(0, 1); PdfPTable table = new PdfPTable(1); table.setPaddingTop(0f); table.setWidthPercentage(96); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(Rectangle.NO_BORDER); cell.addElement(codeEAN.createImageWithBarcode(cb, null, BaseColor.BLACK)); table.addCell(cell); PdfPCell cell2 = new PdfPCell(); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBorder(Rectangle.NO_BORDER); cell2.addElement(pTitile); table.addCell(cell2); for (int i = 0; i < p.getCantidad(); i++) { document.add(table); document.newPage(); } } } // step 5 document.close(); response.getOutputStream().flush(); response.getOutputStream().close(); FacesContext.getCurrentInstance().responseComplete(); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "No hay nada que imprimir", "")); } return null; }
From source file:se.billes.pdf.renderer.model.Barcode.java
License:Open Source License
public void onRender(PdfContentByte cb) throws PdfRenderException { float[] positions = new BlockFactory().getBoundsInPs(this); BarcodeEAN barcode = new BarcodeEAN(); barcode.setCodeType(BarCodeType.getBarCodeType(barCodeType).codeType); barcode.setCode(getCode());//from w ww. j a v a 2 s.c o m barcode.setSize(getFontSize()); barcode.setGuardBars(isShowGuardBars()); barcode.setBarHeight(positions[3]); barcode.setTextAlignment(Element.ALIGN_RIGHT); if (getBaseFont() != null) { barcode.setFont(getBaseFont()); } if (align.equals("top")) { barcode.setBaseline(-1f); } PdfDocument request = getPage().getPdfDocument(); float pageHeight = request.getSize()[1]; float pageHeightInPs = SizeFactory.millimetersToPostscriptPoints(pageHeight); com.itextpdf.text.Image image = barcode.createImageWithBarcode(cb, getBarBaseColor(), getCodeBaseColor()); image.setRotationDegrees(rotation); image.setAbsolutePosition(positions[0], pageHeightInPs - (positions[1] + positions[3] + fontSize)); try { cb.addImage(image); } catch (DocumentException e) { throw new PdfRenderException(e); } }