List of usage examples for com.lowagie.text.pdf PdfPCell setLeading
public void setLeading(float fixedLeading, float multipliedLeading)
From source file:bucks.AuditSheet.java
License:Open Source License
void generateSheet(HttpServletResponse res, List<Batch> batches) { ////from w w w.j av a2 s. c om // paper size legal (A4) 8.5 x 11 // page 1-inch = 72 points // String spacer = " \n"; ServletOutputStream out = null; String filename = "marketbucks_audit_sheet.pdf"; try { // space // Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11" Document document = new Document(pageSize, 36, 36, 18, 18);// 18,18,54,35 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); document.open(); URL imgUrl = new URL(imageUrl); Image image = Image.getInstance(imgUrl); image.scalePercent(20f); // image.scaleAbsolute(100f, 100f);// width, height // image.setRotation(3.1f); // in radians // image.setRotationDegrees(90f); // degrees // image.setSpacingBefore(10f); // image.setSpacingAfter(10f); // image.setWidthPercentage(25.0f); Font fnt = new Font(Font.TIMES_ROMAN, 12, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 12, Font.BOLD); Font fntb2 = new Font(Font.TIMES_ROMAN, 14, Font.BOLD); Phrase spacePhrase = new Phrase(); Chunk ch = new Chunk(spacer, fnt); spacePhrase.add(ch); float[] widths = { 25f, 75f }; // percentages PdfPTable headTable = new PdfPTable(widths); headTable.setWidthPercentage(100); headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headTable.addCell(cell); Phrase phrase = new Phrase(); ch = new Chunk("Printed Market Bucks Audit Sheet\n ", fntb2); phrase.add(ch); Paragraph pp = new Paragraph(); pp.setIndentationLeft(20); pp.setAlignment(Element.ALIGN_LEFT); pp.add(phrase); cell = new PdfPCell(pp); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); headTable.addCell(cell); document.add(headTable); // document.add(spacePhrase); document.add(spacePhrase); // float[] widths3 = { 50f, 50f }; // percentages PdfPTable table = new PdfPTable(widths3); table.setWidthPercentage(100); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); phrase = new Phrase(); ch = new Chunk(" Date: ", fntb); phrase.add(ch); ch = new Chunk(Helper.getToday() + "\n\n\n", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk(" ", fntb); // empty cell phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // document.add(table); // phrase = new Phrase(new Chunk("\n", fnt)); document.add(phrase); // float[] widths2 = { 15f, 10f, 15f, 15f, 15f, 15f, 15f }; // percentages table = new PdfPTable(widths2); table.setWidthPercentage(90); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); // table.getDefaultCell().setPadding(5); phrase = new Phrase(); ch = new Chunk("Count of MB/GC", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Value", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Total Dollars", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Printed By", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Start Number", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("End Number", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("Printed Date", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // // next rows // for (Batch one : batches) { phrase = new Phrase(); ch = new Chunk(one.getBatch_size(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("$" + one.getValue() + ".00", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk(moneyFormat.format(one.getTotal()), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk(one.getUser().toString(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk(one.getStart_seq(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk(one.getEnd_seq(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk(one.getDate(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); } document.add(table); // document.add(spacePhrase); document.add(spacePhrase); // ch = new Chunk("Audit By:____________________________________________________________________\n\n", fnt); phrase = new Phrase(); phrase.add(ch); document.add(phrase); ch = new Chunk(" :_______________________________________)_____________________________\n\n", fnt); phrase = new Phrase(); phrase.add(ch); document.add(phrase); ch = new Chunk(" :_____________________________________________________________________\n\n", fnt); phrase = new Phrase(); phrase.add(ch); document.add(phrase); // document.add(spacePhrase); document.add(spacePhrase); // document.close(); writer.close(); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "public"); // // setting the content type res.setHeader("Content-Disposition", " attachment; filename=" + filename); res.setContentType("application/pdf"); // // the contentlength is needed for MSIE!!! res.setContentLength(baos.size()); // out = res.getOutputStream(); if (out != null) { baos.writeTo(out); } } catch (Exception ex) { System.err.println(ex); } }
From source file:bucks.GenerateChecks.java
License:Open Source License
void generate_mb(Document document, int seq, String value, Image image, PdfWriter writer) { try {/*from ww w .j a v a 2 s . com*/ float[] widths = { 15f, 40f, 45f }; // percentages PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100); table.setSpacingAfter(0f); table.setSpacingBefore(0f); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_TOP); // cell.setFixedHeight(46f); table.addCell(cell); Phrase phrase = new Phrase(); Chunk ch = new Chunk("FARMERS' MARKET BUCKS\n", fntb2); phrase.add(ch); ch = new Chunk("Parks & Recreation\nBloomington, IN", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Issue Date___________ ", fnt10); phrase.add(ch); ch = new Chunk("No. " + seq, fnt10); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); // // document.add(table); // phrase = new Phrase(); ch = new Chunk("\nThis certificate is good for ", fnt); phrase.add(ch); ch = new Chunk("$" + value + ".00 ", fntb2); phrase.add(ch); ch = new Chunk("towards the purchase of ", fnt); phrase.add(ch); ch = new Chunk("eligible food items ", fntb); phrase.add(ch); ch = new Chunk("at the Bloomington Community Farmers' Market. ", fnt); phrase.add(ch); ch = new Chunk("No change allowed. \n", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setFixedHeight(48f); cell.setColspan(3); table.addCell(cell); document.add(table); // float[] widths2 = { 60f, 25f, 10f, 5f }; table = new PdfPTable(widths2); table.setWidthPercentage(100); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); //table.getDefaultCell().setPadding(0); table.setSpacingAfter(0f); table.setSpacingBefore(0f); // phrase = new Phrase(); ch = new Chunk( "Customers shall redeem this certificate at Farmers' Market\nby December 1st of the year issued.", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setColspan(2); cell.setFixedHeight(81f); table.addCell(cell); // Barcode barcode = BarcodeFactory.createCode39("" + seq, false); // barcode text has problem, so we turned off // and decided to add it ourselves. barcode.setDrawingText(false); // barcode.setFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 16)); // barcode.setLabel(""+seq); BufferedImage bi = BarcodeImageHandler.getImage(barcode); /* int width = bi.getWidth(); int height = bi.getHeight(); Graphics2D g2 = bi.createGraphics(); g2.setColor(Color.BLACK); g2.drawString(""+seq, 60, 70); g2.dispose(); */ ByteArrayOutputStream baos = new ByteArrayOutputStream(); // // added this hack to get rid of underline in the barcode // this worked on windows, but the text did not show up on linux // that is why we decided to abandon the text all the way // and add it ourselves /* BarcodeImageHandler.writePNG(barcode, baos); File bcImg = File.createTempFile("bc-", ".png"); bcImg.deleteOnExit(); byte[] imageBytes = baos.toByteArray(); FileOutputStream fos = new FileOutputStream(bcImg); BarcodeImageHandler.writePNG(barcode, fos); */ // // old ImageIO.write(bi, "png", baos); byte[] imageBytes = baos.toByteArray(); // Image barCodeImage = Image.getInstance(imageBytes); barCodeImage.setRotationDegrees(90f); // barCodeImage.scalePercent(35f); barCodeImage.scalePercent(35f, 50f); // float widthf = barCodeImage.getWidth(); // float heightf = barCodeImage.getHeight(); cell = new PdfPCell(barCodeImage); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(0); cell.setLeading(0f, 0f); // cell.setFixedHeight(81f); table.addCell(cell); // // the barcode text that we added underneath the barcode // int textWidth = 53, textHeight = 50; BufferedImage bi2 = new BufferedImage(textWidth, textHeight, BufferedImage.TYPE_BYTE_BINARY); Graphics2D g = bi2.createGraphics(); g.setFont(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 10)); g.setColor(Color.WHITE); g.fillRect(0, 0, textWidth, textHeight); g.setColor(Color.BLACK); g.drawString("" + seq, 5, 10); g.dispose(); baos = new ByteArrayOutputStream(); ImageIO.write(bi2, "png", baos); imageBytes = baos.toByteArray(); Image barCodeTextImage = Image.getInstance(imageBytes); barCodeTextImage.setRotationDegrees(90f); cell = new PdfPCell(barCodeTextImage); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(0); cell.setLeading(0f, 0f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("\nThis certificate is not refundable and cannot be replaced if lost or stolen.\n\n", fnts); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setFixedHeight(34f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("\nMust have official stamp to be valid.\n\n", fnts); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(3); table.addCell(cell); document.add(table); // float[] widths4 = { 40f, 60f }; // percentages table = new PdfPTable(widths4); table.setWidthPercentage(100); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.setSpacingBefore(0f); table.setSpacingAfter(0f); phrase = new Phrase(); ch = new Chunk("APPROVED BY THE STATE BOARD OF ACCOUNTS\nFOR THE CITY OF BLOOMINGTON, IN 2007\n\n\n", fnts); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setFixedHeight(40f); // 40 table.addCell(cell); phrase = new Phrase(); ch = new Chunk( "VENDERS SHALL REDEEM THIS CERTIFICATE THROUGH BLOOMINGTON'S\nPARKS & REC DEPT. BY DECEMBER 15TH OF THE YEAR ISSUED\n\n\n", fnts); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); document.add(table); } catch (Exception ex) { System.err.println(ex); } }
From source file:bucks.GenerateChecks.java
License:Open Source License
void generate_gc(Document document, int seq, String value, Image image, PdfWriter writer) { try {/*w w w .j a va2s.co m*/ float[] widths = { 13f, 54f, 33f }; // percents PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.setSpacingAfter(0f); table.setSpacingBefore(0f); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setFixedHeight(46f); table.addCell(cell); Phrase phrase = new Phrase(); Chunk ch = new Chunk("FARMERS' MARKET GIFT CERTIFICATE\n", fntb2); phrase.add(ch); ch = new Chunk("Parks & Recreation\nBloomington, IN", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Issue Date__________ ", fnt10); phrase.add(ch); ch = new Chunk("No. " + seq, fnt10); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("\nThis certificate is good for ", fnt); phrase.add(ch); ch = new Chunk("$" + value + ".00 ", fntb2); phrase.add(ch); ch = new Chunk("towards the purchase of ", fnt); phrase.add(ch); ch = new Chunk("products from ", fnt); phrase.add(ch); ch = new Chunk("the Bloomington Community Farmers' Market and A Fair of The Arts Vendors. ", fnt); phrase.add(ch); ch = new Chunk("Change may be given. \n", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(3); cell.setFixedHeight(48f); table.addCell(cell); document.add(table); // float[] widths2 = { 60f, 25f, 10f, 5f }; table = new PdfPTable(widths2); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); // phrase = new Phrase(); ch = new Chunk("Customers shall redeem this certificate at Market\nwithin one year of date issued. ", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setColspan(2); cell.setFixedHeight(81f); table.addCell(cell); Barcode barcode = BarcodeFactory.createCode39("" + seq, true); barcode.setDrawingText(false); BufferedImage bi = BarcodeImageHandler.getImage(barcode); ByteArrayOutputStream baos = new ByteArrayOutputStream(); // ImageIO.write(bi, "png", baos); byte[] imageBytes = baos.toByteArray(); // Image barCodeImage = Image.getInstance(imageBytes); barCodeImage.setRotationDegrees(90); // barCodeImage.scalePercent(35f); barCodeImage.scalePercent(35f, 50f); cell = new PdfPCell(barCodeImage); // cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(0); cell.setLeading(0f, 0f); table.addCell(cell); // // adding text underneath the barcode // int textWidth = 53, textHeight = 50; BufferedImage bi2 = new BufferedImage(textWidth, textHeight, BufferedImage.TYPE_BYTE_BINARY); Graphics2D g = bi2.createGraphics(); g.setFont(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 10)); g.setColor(Color.WHITE); g.fillRect(0, 0, textWidth, textHeight); g.setColor(Color.BLACK); g.drawString("" + seq, 5, 10); g.dispose(); baos = new ByteArrayOutputStream(); ImageIO.write(bi2, "png", baos); imageBytes = baos.toByteArray(); Image barCodeTextImage = Image.getInstance(imageBytes); barCodeTextImage.setRotationDegrees(90f); cell = new PdfPCell(barCodeTextImage); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(0); cell.setLeading(0f, 0f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("\nThis certificate is not refundable and cannot be replaced if lost or stolen.\n\n\n", fnts); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setFixedHeight(30f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("\nMust have official stamp to be valid.\n\n", fnts); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(3); table.addCell(cell); document.add(table); // float[] widths3 = { 40f, 60f }; // percentages table = new PdfPTable(widths3); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); phrase = new Phrase(); ch = new Chunk("APPROVED BY THE STATE BOARD OF ACCOUNTS\nFOR THE CITY OF BLOOMINGTON, IN 2007\n\n\n", fnts); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); // cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setFixedHeight(44f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk( "VENDERS SHALL REDEEM THIS CERTIFICATE THROUGH BLOOMINGTON'S\nPARKS & REC DEPT. BY DECEMBER 15TH OF THE YEAR RECEIVED\n\n\n", fnts); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); document.add(table); // document.add( Chunk.NEWLINE ); } catch (Exception ex) { System.err.println(ex); } }
From source file:bucks.RedeemInvoice.java
License:Open Source License
void generateInvoice(HttpServletResponse res, Redeem redeem) { ///* w ww .j a v a 2 s . c o m*/ // paper size legal (A4) 8.5 x 11 // page 1-inch = 72 points // String spacer = " \n"; User user = redeem.getUser(); Vendor vendor = redeem.getVendor(); List<Buck> bk_bucks = redeem.getBk_bucks(); List<Buck> gc5_bucks = redeem.getGc5_bucks(); List<Buck> gc20_bucks = redeem.getGc20_bucks(); List<Buck> gc_bucks = redeem.getGc_bucks(); List<Dispute> disputes = redeem.getDisputes(); int bk_total = 0, gc5_total = 0, gc20_total = 0, total = 0; if (bk_bucks.size() > 0) { bk_total = bk_bucks.size() * 3; } if (gc5_bucks.size() > 0) { gc5_total = gc5_bucks.size() * 5; } if (gc20_bucks.size() > 0) { gc20_total = gc20_bucks.size() * 20; } total = bk_total + gc5_total + gc20_total; String vendor_name = ""; if (vendor != null) { vendor_name = vendor.getCleanName(); } ServletOutputStream out = null; String filename = "invoice_" + vendor_name + "_" + redeem.getId() + ".pdf"; try { // space // Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11" Document document = new Document(pageSize, 36, 36, 18, 18);// 18,18,54,35 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); document.open(); Image image = Image.getInstance(imageUrl); // image = Image.getInstance(byte bytes[]);// generated image image.scalePercent(20f); Font fnt = new Font(Font.TIMES_ROMAN, 12, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 12, Font.BOLD); Font fntb2 = new Font(Font.TIMES_ROMAN, 14, Font.BOLD); // Phrase spacePhrase = new Phrase(); Chunk ch = new Chunk(spacer, fnt); spacePhrase.add(ch); float[] widths = { 15f, 85f }; // percentages PdfPTable headTable = new PdfPTable(widths); headTable.setWidthPercentage(100); headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // image.setWidthPercentage(15.0f); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setFixedHeight(46f); headTable.addCell(cell); Phrase phrase = new Phrase(); ch = new Chunk( "City of Bloomington Community Farmers Market\n Gift Certificates/Market Bucks Invoice\n ", fntb2); phrase.add(ch); Paragraph pp = new Paragraph(); pp.setIndentationLeft(20); pp.setAlignment(Element.ALIGN_LEFT); pp.add(phrase); cell = new PdfPCell(pp); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); headTable.addCell(cell); document.add(headTable); // float[] widths3 = { 50f, 50f }; // percentages PdfPTable table = new PdfPTable(widths3); table.setWidthPercentage(100); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); phrase = new Phrase(); ch = new Chunk(" Vendor Name: ", fntb); phrase.add(ch); ch = new Chunk(vendor.getFullName(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Date: ", fntb); phrase.add(ch); ch = new Chunk(redeem.getDate(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); phrase = new Phrase(); ch = new Chunk(" Vendor Number: ", fntb); phrase.add(ch); ch = new Chunk(vendor.getId(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); phrase = new Phrase(); // empty cell ch = new Chunk(" ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); table.addCell(cell); // extra space table.addCell(cell); document.add(table); // phrase = new Phrase(new Chunk("\n", fnt)); document.add(phrase); // float[] widths2 = { 30f, 25f, 15f, 15f, 15f }; // percentages table = new PdfPTable(widths2); table.setWidthPercentage(90); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); // table.getDefaultCell().setPadding(5); phrase = new Phrase(); ch = new Chunk("Type of Voucher", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("City Account Number", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Quantity", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("Multiply", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("Value", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // // second row phrase = new Phrase(); ch = new Chunk("Market Bucks", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("201-18-1865003-47240", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); String str = " "; if (bk_bucks.size() > 0) { str = "" + bk_bucks.size(); } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("x $3.00 = ", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); phrase = new Phrase(); str = " "; if (bk_total > 0) { str = "$" + bk_total + ".00"; } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); // // 3rd row phrase = new Phrase(); ch = new Chunk("$5 Gift Cerificates", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("201-18-1865003-47230", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); str = " "; if (gc5_bucks.size() > 0) { str = "" + gc5_bucks.size(); } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("x $5.00 = ", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); phrase = new Phrase(); str = " "; if (gc5_total > 0) { str = "$" + gc5_total + ".00"; } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); // // 4th row phrase = new Phrase(); ch = new Chunk("$20 Gift Certificates", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("201-18-1865003-47230", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); str = " "; if (gc20_bucks.size() > 0) { str = "" + gc20_bucks.size(); } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("x $20.00 = ", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); str = " "; if (gc20_total > 0) { str = "$" + gc20_total + ".00"; } phrase = new Phrase(); ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); // // 5th row total phrase = new Phrase(); ch = new Chunk(" Total Value: ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("$" + total + ".00", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); document.add(table); // // float[] withs5 = { 100f }; table = new PdfPTable(withs5); table.setWidthPercentage(100); cell = new PdfPCell(new Phrase(" ")); cell.setBorder(Rectangle.BOTTOM); // cell.setBorderColorBottom(Color.BLACK); cell.setBorderWidthBottom(2f); table.addCell(cell); document.add(table); // ch = new Chunk("\n", fnt); phrase = new Phrase(); phrase.add(ch); document.add(phrase); // // float[] widths3 = {50f, 50f}; // percentages table = new PdfPTable(widths3); table.setWidthPercentage(100); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); phrase = new Phrase(); ch = new Chunk(" Data Entry Completed by: ", fntb); phrase.add(ch); ch = new Chunk(user.getFullName(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk(" Invoice Number: ", fntb); phrase.add(ch); ch = new Chunk(redeem.getId(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); document.add(table); document.add(spacePhrase); document.add(spacePhrase); // // adding bucks and GC // float[] widths4 = { 100f }; // percentages table = new PdfPTable(widths4); table.setWidthPercentage(100); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); int row = 1, col = 1; if (bk_bucks.size() > 0) { phrase = new Phrase(); ch = new Chunk(" Market Bucks ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); table.addCell(cell); phrase = new Phrase(); for (Buck one : bk_bucks) { ch = new Chunk("" + one.getId() + " ", fntb); phrase.add(ch); col++; if (col > 15) { row++; col = 1; cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); phrase = new Phrase(); } } if (col > 1) { cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } if (row < 10) { for (int j = 0; j < 2; j++) { phrase = new Phrase(); ch = new Chunk(" ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); row++; } } } col = 1; if (gc_bucks.size() > 0) { phrase = new Phrase(); ch = new Chunk(" Gift Certificates ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); table.addCell(cell); phrase = new Phrase(); for (Buck one : gc_bucks) { ch = new Chunk("" + one.getId() + " ", fntb); phrase.add(ch); col++; if (col > 15) { row++; col = 1; cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); phrase = new Phrase(); } } if (col > 1) { cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } if (row < 15) { for (int j = 0; j < 2; j++) { phrase = new Phrase(); ch = new Chunk(" ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); row++; } } } if (disputes != null && disputes.size() > 0) { phrase = new Phrase(); ch = new Chunk(" Disputed Market Bucks and/or Gift Certificates (number: reason)", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); table.addCell(cell); row++; for (Dispute one : disputes) { phrase = new Phrase(); ch = new Chunk(one.getBuck_id() + ": " + one.getReason(), fnt); phrase.add(ch); if (one.hasNotes()) { ch = new Chunk("\nNotice: " + one.getNotes(), fnt); phrase.add(ch); row++; } cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); row++; } } if (redeem.hasNotes()) { phrase = new Phrase(); ch = new Chunk("\nNotice: " + redeem.getNotes(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); row++; } if (row < 18) { for (int j = row; j < 18; j++) { phrase = new Phrase(); ch = new Chunk(" ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } } document.add(table); document.close(); writer.close(); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "public"); // // setting the content type res.setHeader("Content-Disposition", " attachment; filename=" + filename); res.setContentType("application/pdf"); // // the contentlength is needed for MSIE!!! res.setContentLength(baos.size()); // out = res.getOutputStream(); if (out != null) { baos.writeTo(out); } } catch (Exception ex) { System.err.println(ex); } }
From source file:com.gtdfree.test.TableBorders.java
License:Open Source License
private static PdfPCell makeCell(String text, int vAlignment, int hAlignment, Font font, float leading, float padding, Rectangle borders, boolean ascender, boolean descender) { Paragraph p = new Paragraph(text, font); p.setLeading(leading);//from w w w.ja v a 2 s.co m PdfPCell cell = new PdfPCell(p); cell.setLeading(leading, 0); cell.setVerticalAlignment(vAlignment); cell.setHorizontalAlignment(hAlignment); cell.cloneNonPositionParameters(borders); cell.setUseAscender(ascender); cell.setUseDescender(descender); cell.setUseBorderPadding(true); cell.setPadding(padding); return cell; }
From source file:de.dhbw.humbuch.util.PDFHandler.java
/** * Use the configuration information to fill the table cells * @param tableBuilder Table configuration *//* ww w .j a va 2s. c o m*/ private static void fillTableWithContent(TableBuilder tableBuilder) { PdfPCell cell = null; for (int i = 0; i < tableBuilder.contentArray.length; i++) { if (tableBuilder.contentArray[i] == null || tableBuilder.contentArray[i].equals("null")) { tableBuilder.contentArray[i] = ""; } if (tableBuilder.font != null) { cell = new PdfPCell(new Phrase(tableBuilder.contentArray[i], tableBuilder.font)); } else { cell = new PdfPCell(new Phrase(tableBuilder.contentArray[i])); } if (tableBuilder.isAlignedCentrally) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); } if (!tableBuilder.withBorder) { cell.setBorder(0); } if (tableBuilder.padding != 0f) { cell.setPadding(tableBuilder.padding); } if (tableBuilder.leading != 0f) { cell.setLeading(tableBuilder.leading, tableBuilder.leading); } tableBuilder.table.addCell(cell); } }
From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java
License:Apache License
private PdfPCell writeCell(ReportModel model, jdbreport.model.Cell srcCell, int row, int col) throws BadElementException, IOException, SaveReportException { CellStyle style = model.getStyles(srcCell.getStyleId()); java.awt.Rectangle rect = model.getCellRect(row, col, true, true); float h = Math.round((float) Units.PT.setYPixels((int) rect.getHeight())); float w = Math.round((float) Units.PT.setXPixels((int) rect.getWidth())); PdfPCell pdfCell = null; if (srcCell.getPicture() != null) { java.awt.Image awtImage = srcCell.getPicture().getImage(); com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } else {/*w w w.j a v a 2 s .co m*/ String text = null; if (srcCell.getValue() instanceof CellValue<?>) { StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter); if (!((CellValue<?>) srcCell.getValue()).write(printWriter, model, row, col, this, ReportBook.PDF)) { java.awt.Image awtImage = ((CellValue<?>) srcCell.getValue()).getAsImage(model, row, col); if (awtImage != null) { com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } } else { text = strWriter.getBuffer().toString(); } } else { if (jdbreport.model.Cell.TEXT_HTML.equals(srcCell.getContentType())) { pdfCell = new PdfPCell(); writeHTMLText(model.getStyles(srcCell.getStyleId()), srcCell, pdfCell); } else { text = model.getCellText(srcCell); } } if (pdfCell == null) { pdfCell = new PdfPCell(); } if (text != null && text.length() > 0) { com.lowagie.text.Font font; if (fonts.containsKey(style.getId())) { font = fonts.get(style.getId()); } else { font = getFontMapper().styleToPdf(style); fonts.put(style.getId(), font); } Paragraph p; if (font != null) { p = new Paragraph(text, font); } else { p = new Paragraph(text); } pdfCell.setPhrase(p); pdfCell.setPadding(1); pdfCell.setLeading(0f, 1.1f); } else { pdfCell.setPadding(0); } } pdfCell.setFixedHeight(h); pdfCell.setBackgroundColor(style.getBackground()); pdfCell.setHorizontalAlignment(toPdfHAlignment(style.getHorizontalAlignment())); pdfCell.setVerticalAlignment(toPdfVAlignment(style.getVerticalAlignment())); if (style.getAngle() != 0) { pdfCell.setRotation(roundAngle(style.getAngle())); } assignBorders(style, pdfCell); pdfCell.setNoWrap(!style.isWrapLine()); if (srcCell.getColSpan() > 0) { pdfCell.setColspan(srcCell.getColSpan() + 1); } if (srcCell.getRowSpan() > 0) { pdfCell.setRowspan(srcCell.getRowSpan() + 1); } return pdfCell; }
From source file:net.bull.javamelody.internal.web.pdf.PdfCounterRequestContextReport.java
License:Apache License
private void writeContexts(List<CounterRequestContext> contexts) throws DocumentException, IOException { boolean displayRemoteUser = false; for (final CounterRequestContext context : contexts) { if (context.getRemoteUser() != null) { displayRemoteUser = true;/*from w ww . ja va 2 s. c o m*/ break; } } writeHeader(contexts, displayRemoteUser); final PdfPCell defaultCell = getDefaultCell(); defaultCell.setLeading(2, 1); defaultCell.setPaddingTop(0); for (final CounterRequestContext context : contexts) { nextRow(); writeContext(context, displayRemoteUser); } addTableToDocument(); writeFooter(); }
From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java
License:Apache License
private void writeRequests() throws IOException, DocumentException { final Map<String, Long> childRequests = request.getChildRequestsExecutionsByRequestId(); final boolean hasChildren = !childRequests.isEmpty(); final Counter parentCounter = getCounterByRequestId(request); final boolean allChildHitsDisplayed = parentCounter != null && parentCounter.getChildCounterName() != null && request.hasChildHits(); final PdfPCell defaultCell = getDefaultCell(); defaultCell.setLeading(2, 1); defaultCell.setPaddingTop(0);/*from ww w .j ava2s .c o m*/ nextRow(); writeRequest(request, -1, allChildHitsDisplayed); if (hasChildren) { writeChildRequests(childRequests, allChildHitsDisplayed); } }
From source file:nl.dykema.jxmlnote.spikes.Spacing.java
License:Open Source License
/** * Main method./*from w ww . j av a2 s.c o m*/ * @param args no arguments needed * @throws DocumentException * @throws IOException */ public static void main(String[] args) throws DocumentException, IOException { // step 1 Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); Phrase p = new Phrase( "Dr. iText or: How I Learned to Stop Worrying " + "and Love the Portable Document Format."); PdfPCell cell = new PdfPCell(p); table.addCell("default leading / spacing"); table.addCell(cell); table.addCell("absolute leading: 20"); cell.setLeading(20f, 0f); table.addCell(cell); table.addCell("absolute leading: 3; relative leading: 1.2"); cell.setLeading(3f, 1.2f); table.addCell(cell); table.addCell("absolute leading: 0; relative leading: 1.2"); cell.setLeading(0f, 1.2f); table.addCell(cell); table.addCell("no leading at all"); cell.setLeading(0f, 0f); table.addCell(cell); cell = new PdfPCell(new Phrase("Dr. iText or: How I Learned to Stop Worrying and Love PDF")); table.addCell("padding 10"); cell.setPadding(10); table.addCell(cell); table.addCell("padding 0"); cell.setPadding(0); table.addCell(cell); table.addCell("different padding for left, right, top and bottom"); cell.setPaddingLeft(20); cell.setPaddingRight(50); cell.setPaddingTop(0); cell.setPaddingBottom(5); table.addCell(cell); p = new Phrase("iText in Action Second Edition"); table.getDefaultCell().setPadding(2); table.getDefaultCell().setUseAscender(false); table.getDefaultCell().setUseDescender(false); table.addCell("padding 2; no ascender, no descender"); table.addCell(p); table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(false); table.addCell("padding 2; ascender, no descender"); table.addCell(p); table.getDefaultCell().setUseAscender(false); table.getDefaultCell().setUseDescender(true); table.addCell("padding 2; descender, no ascender"); table.addCell(p); table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(true); table.addCell("padding 2; ascender and descender"); cell.setPadding(2); cell.setUseAscender(true); cell.setUseDescender(true); table.addCell(p); document.add(table); // step 5 document.close(); }