List of usage examples for com.lowagie.text Element ALIGN_TOP
int ALIGN_TOP
To view the source code for com.lowagie.text Element ALIGN_TOP.
Click Source Link
From source file:airportpainter.util.AirportPainter.java
License:Open Source License
private void createSheetsFreqs(Airport airport, Document document) { // FREQs Nearest Navaid notifyAction("createSheetsFreqs"); PdfPTable table = new PdfPTable(2); {//from ww w .ja v a 2 s. co m PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(Element.ALIGN_TOP); { if (_airport.getAtises().size() > 0) { String freq = ""; for (final Atis atis : _airport.getAtises()) { freq = freq + new Double(atis.getFreq()).toString() + " "; } Paragraph p = createTinyParagraph("ATIS ", freq); cell.addElement(p); } } { String[] reqs = { "50", "51", "52", "53", "54", "55", "56" }; for (String req : reqs) { List<ATCFreq> tempFreqs = _airport.getATCFreqs(req); if (tempFreqs.size() > 0) { String freq = ""; for (final ATCFreq tower : tempFreqs) { freq = freq + tower.getFreq() + " "; } Paragraph p = createTinyParagraph(ATCFreq.typeNames.get(req) + " ", freq); cell.addElement(p); } } } //cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER); cell.setBorderWidth(borderWidth); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); } { PdfPCell cell = new PdfPCell(); { Paragraph p = new Paragraph("Nearest Navaid:", new com.lowagie.text.Font( com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL)); cell.addElement(p); } { Paragraph p = new Paragraph(getNEarestBeaconString(airport), new com.lowagie.text.Font( com.lowagie.text.Font.TIMES_ROMAN, 10, com.lowagie.text.Font.NORMAL)); cell.addElement(p); } cell.setBorderWidth(borderWidth); //cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); } table.setWidthPercentage(100); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:airportpainter.util.AirportPainter.java
License:Open Source License
private void createSheetsFakeShops(Airport airport, Document document) { // FREQs Nearest Navaid notifyAction("createSheetsFakeShops"); PdfPTable table = new PdfPTable(1); {//from www . j a v a2 s . c o m PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setMinimumHeight(20); boolean addWorker = false; for (final Runway runway : airport.getRunways()) { if (runway.getLength() > 1200 / FEET_PER_METER) { addWorker = true; } } boolean addFork = (airport.hasTower()); Paragraph p = new Paragraph(); p.setLeading((p.leading() / 2) + 4); if (addWorker) { try { p.add(new Chunk(" ")); p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "avail_work.png")), 0, -3)); } catch (BadElementException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } } if (addFork) { try { p.add(new Chunk(" ")); p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "avail_fork.png")), 0, -3)); } catch (BadElementException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } } cell.addElement(p); //cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER); cell.setBorderWidth(borderWidth); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); } table.setWidthPercentage(100); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:airportpainter.util.AirportPainter.java
License:Open Source License
private void createSheetsLights(Airport airport, Document document) { // FREQs Nearest Navaid notifyAction("createSheetsLights"); PdfPTable table = new PdfPTable(1); {//from w w w . j ava 2s. co m PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setMinimumHeight(20); Paragraph p = new Paragraph(); p.setLeading((p.leading() / 2) + 4); com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 10, com.lowagie.text.Font.NORMAL); oneLightDone = false; try { p.add(new Chunk(" ", font)); p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "light.png")), 0, 0)); p.add(new Chunk(" ", font)); } catch (BadElementException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } boolean addABN = airport.hasBeacon(); if (addABN) { p.add(addOneLight("ABN", font)); } boolean addALS = false; boolean addPAPI = false; for (final Runway runway : airport.getRunways()) { if ((runway.hasALSF_I(false) || runway.hasALSF_I(true)) || (runway.hasALSF_II(false) || runway.hasALSF_II(true))) { addALS = true; } if ((runway.hasPapi(false) || runway.hasPapi(true))) { addPAPI = true; } } if (addALS) { p.add(addOneLight("ALS", font)); } if (addPAPI) { p.add(addOneLight("PAPI ", font)); String separ = ""; for (final Runway runway : airport.getRunways()) { if (runway.hasPapi(false)) { p.add(new Chunk(separ + runway.getNumber() + " (3.5)" + degrees + " ", font)); separ = ", "; } if (runway.hasPapi(true)) { p.add(new Chunk(separ + runway.getOppositeNumber() + " (3.5)" + degrees + " ", font)); separ = ", "; } } } cell.addElement(p); //cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER); cell.setBorderWidth(borderWidth); cell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } table.setWidthPercentage(100); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:airportpainter.util.AirportPainter.java
License:Open Source License
private void createSheets2Freqs(Airport airport, Document document) { // FREQs Nearest Navaid notifyAction("createSheets2Freqs"); PdfPTable table = new PdfPTable(2); {/* w w w. java 2 s .co m*/ PdfPCell cell = new PdfPCell(); { Paragraph p = new Paragraph("Within Airspace:", new com.lowagie.text.Font( com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL)); cell.addElement(p); } cell.setBorderWidth(borderWidth); cell.setBorderWidthBottom(borderWidthThin); //cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); } { PdfPCell cell = new PdfPCell(); com.lowagie.text.Font fontBold = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD); com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.NORMAL); { Paragraph p = new Paragraph(airport.getId(), fontBold); cell.addElement(p); } { Paragraph p = new Paragraph(); p.add(new Chunk("Elev ", font)); int feets = (int) (airport.getElevation()); p.add(new Chunk(new Integer(feets).toString() + "'", fontBold)); int meters = (int) (feets / FEET_PER_METER); p.add(new Chunk("/" + new Integer(meters).toString() + "m", font)); cell.addElement(p); } { Paragraph p = new Paragraph(); p.add(new Chunk(airport.getLatitudeString1(airport.getLat(), "N", "S", 2, false) + "\r\n" + airport.getLatitudeString1(airport.getLong(), "W", "E", 3, true), font)); cell.addElement(p); } cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell(cell); } table.setWidthPercentage(100); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:airportpainter.util.AirportPainter.java
License:Open Source License
private void createSheets2ILS(Airport airport, Document document) { // FREQs Nearest Navaid notifyAction("createSheets2ILS"); PdfPTable table = new PdfPTable(2); {/*w ww. ja va2 s. c o m*/ PdfPCell cell = new PdfPCell(); { Paragraph p = new Paragraph("(TWR)", new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL)); p.setLeading((p.leading() / 2) + 2); cell.addElement(p); } List<ATCFreq> tempFreqsTwr = _airport.getATCFreqs("54"); List<ATCFreq> tempFreqsGnd = _airport.getATCFreqs("53"); if (tempFreqsTwr.size() > 0 || tempFreqsGnd.size() > 0) { if (tempFreqsTwr.size() > 0) { Paragraph p = new Paragraph(); p.setLeading((p.leading() / 2) + 6); Chunk c = new Chunk(airport.getName().toUpperCase() + " APPROACH ", new com.lowagie.text.Font( com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL)); p.add(c); for (final ATCFreq tower : tempFreqsTwr) { Chunk c2 = new Chunk((tower.getFreq() + " ").substring(0, 9) + " ", new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.BOLD)); p.add(c2); } cell.addElement(p); } if (tempFreqsGnd.size() > 0) { Paragraph p = new Paragraph(); p.setLeading((p.leading() / 2) + 6); Chunk c = new Chunk("GROUND ", new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL)); p.add(c); for (final ATCFreq tower : tempFreqsGnd) { Chunk c2 = new Chunk((tower.getFreq() + " ").substring(0, 9) + " ", new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.BOLD)); p.add(c2); } cell.addElement(p); } } cell.setBorderWidth(borderWidth); cell.setBorderWidthTop(borderWidthThin); cell.setBorderWidthRight(borderWidthThin); //cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); } { com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.NORMAL); PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setLeading((p.leading()) + 6); Chunk c = new Chunk("ATIS ", new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL)); p.add(c); for (final Atis atis : _airport.getAtises()) { Chunk c2 = new Chunk((atis.getFreq() + " ").substring(0, 9) + " ", new com.lowagie.text.Font( com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.BOLD)); p.add(c2); } cell.addElement(p); /// ILS table { height1 = 0; PdfPTable tableILS = new PdfPTable(4); tableILS.setWidthPercentage(100); // titles com.lowagie.text.Font fontTitle = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL); { PdfPCell cellTitle = new PdfPCell(); cellTitle.setVerticalAlignment(Element.ALIGN_CENTER); cellTitle.setBorderWidth(borderWidthThin); Paragraph pt = new Paragraph("RWY", fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellTitle.addElement(pt); tableILS.addCell(cellTitle); } { PdfPCell cellTitle = new PdfPCell(); cellTitle.setVerticalAlignment(Element.ALIGN_CENTER); cellTitle.setBorderWidth(borderWidthThin); Paragraph pt = new Paragraph("ILS", fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellTitle.addElement(pt); tableILS.addCell(cellTitle); } { PdfPCell cellTitle = new PdfPCell(); cellTitle.setVerticalAlignment(Element.ALIGN_CENTER); cellTitle.setBorderWidth(borderWidthThin); Paragraph pt = new Paragraph("RWY", fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellTitle.addElement(pt); tableILS.addCell(cellTitle); } { PdfPCell cellTitle = new PdfPCell(); cellTitle.setVerticalAlignment(Element.ALIGN_CENTER); cellTitle.setBorderWidth(borderWidthThin); Paragraph pt = new Paragraph("ILS", fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellTitle.addElement(pt); tableILS.addCell(cellTitle); } int pos = 0; int rs = airport.getRunways().size(); for (final Runway runway : airport.getRunways()) { if (runway.getIlsFreq() != 0) { height1 = height1 + 10; { PdfPCell cellFreq = new PdfPCell(); cellFreq.setVerticalAlignment(Element.ALIGN_CENTER); cellFreq.setBorderWidth(borderWidthThin); if (pos > 0) { cellFreq.setBorderWidthTop(0); } if (pos < rs - 1) { cellFreq.setBorderWidthBottom(0); } Paragraph pt = new Paragraph(runway.getNumber(), fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellFreq.addElement(pt); tableILS.addCell(cellFreq); } { PdfPCell cellFreq = new PdfPCell(); cellFreq.setVerticalAlignment(Element.ALIGN_CENTER); cellFreq.setBorderWidth(borderWidthThin); if (pos > 0) { cellFreq.setBorderWidthTop(0); } if (pos < rs - 1) { cellFreq.setBorderWidthBottom(0); } Paragraph pt = new Paragraph( runway.getIlsFreq() + " " + "... " + new Integer((int) runway.getHeading()).toString() + degrees, fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellFreq.addElement(pt); tableILS.addCell(cellFreq); } } /*else { { PdfPCell cellFreq = new PdfPCell(); cellFreq.setVerticalAlignment(Element.ALIGN_CENTER); cellFreq.setBorderWidth(borderWidthThin); if (pos>0) { cellFreq.setBorderWidthTop(0); } if (pos<rs-1) { cellFreq.setBorderWidthBottom(0); } Paragraph pt=new Paragraph( "",fontTitle); pt.setLeading((pt.leading()/2)+2); pt.setAlignment(Element.ALIGN_CENTER); cellFreq.addElement(pt); tableILS.addCell(cellFreq); } { PdfPCell cellFreq = new PdfPCell(); cellFreq.setVerticalAlignment(Element.ALIGN_CENTER); cellFreq.setBorderWidth(borderWidthThin); if (pos>0) { cellFreq.setBorderWidthTop(0); } if (pos<rs-1) { cellFreq.setBorderWidthBottom(0); } Paragraph pt=new Paragraph( "",fontTitle); pt.setLeading((pt.leading()/2)+2); pt.setAlignment(Element.ALIGN_CENTER); cellFreq.addElement(pt); tableILS.addCell(cellFreq); } }*/ if (runway.getIlsOppositeFreq() != 0) { { PdfPCell cellFreq = new PdfPCell(); cellFreq.setVerticalAlignment(Element.ALIGN_CENTER); cellFreq.setBorderWidth(borderWidthThin); if (pos > 0) { cellFreq.setBorderWidthTop(0); } if (pos < rs - 1) { cellFreq.setBorderWidthBottom(0); } Paragraph pt = new Paragraph(runway.getOppositeNumber(), fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellFreq.addElement(pt); tableILS.addCell(cellFreq); } { PdfPCell cellFreq = new PdfPCell(); cellFreq.setVerticalAlignment(Element.ALIGN_CENTER); cellFreq.setBorderWidth(borderWidthThin); if (pos > 0) { cellFreq.setBorderWidthTop(0); } if (pos < rs - 1) { cellFreq.setBorderWidthBottom(0); } Paragraph pt = new Paragraph(runway.getIlsOppositeFreq() + " " + "... " + new Integer((int) (runway.getHeading() + 180) % 180).toString() + degrees, fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellFreq.addElement(pt); tableILS.addCell(cellFreq); } } else { { PdfPCell cellFreq = new PdfPCell(); cellFreq.setVerticalAlignment(Element.ALIGN_CENTER); cellFreq.setBorderWidth(borderWidthThin); if (pos > 0) { cellFreq.setBorderWidthTop(0); } if (pos < rs - 1) { cellFreq.setBorderWidthBottom(0); } Paragraph pt = new Paragraph("", fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellFreq.addElement(pt); tableILS.addCell(cellFreq); } { PdfPCell cellFreq = new PdfPCell(); cellFreq.setVerticalAlignment(Element.ALIGN_CENTER); cellFreq.setBorderWidth(borderWidthThin); if (pos > 0) { cellFreq.setBorderWidthTop(0); } if (pos < rs - 1) { cellFreq.setBorderWidthBottom(0); } Paragraph pt = new Paragraph("", fontTitle); pt.setLeading((pt.leading() / 2) + 2); pt.setAlignment(Element.ALIGN_CENTER); cellFreq.addElement(pt); tableILS.addCell(cellFreq); } } pos++; } float[] widths2 = { 1f, 3f, 1f, 3f }; try { tableILS.setWidths(widths2); } catch (DocumentException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } cell.addElement(tableILS); } cell.setBorderWidth(borderWidth); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); } table.setWidthPercentage(100); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.formbuilder.ITextOuterTable.java
License:Open Source License
private void resetDefaultCell() { getDefaultCell().setColspan(2); getDefaultCell().setHorizontalAlignment(Element.ALIGN_TOP); getDefaultCell().setPadding(0); }
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 www . j av a 2s . c om*/ 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 {//from www . j a v a 2 s . c o 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:com.gtdfree.test.TableBorders.java
License:Open Source License
private static void makeTestPage(Font tableFont, Rectangle borders, @SuppressWarnings("unused") PdfWriter writer, Document document, float padding, boolean ascender, boolean descender) throws BadElementException, DocumentException { document.newPage();/*w w w.ja v a 2 s. co m*/ PdfPTable table = null; table = new PdfPTable(4); table.setWidthPercentage(100f); float leading = tableFont.getSize() * 1.2f; table.addCell(makeCell("1-Top", Element.ALIGN_TOP, Element.ALIGN_LEFT, tableFont, leading, padding, borders, ascender, descender)); table.addCell(makeCell("2-Middle", Element.ALIGN_MIDDLE, Element.ALIGN_LEFT, tableFont, leading, padding, borders, ascender, descender)); table.addCell(makeCell("3-Bottom", Element.ALIGN_BOTTOM, Element.ALIGN_LEFT, tableFont, leading, padding, borders, ascender, descender)); table.addCell(makeCell("4-Has a y", Element.ALIGN_TOP, Element.ALIGN_LEFT, tableFont, leading, padding, borders, ascender, descender)); table.addCell(makeCell("5-Abcdy", Element.ALIGN_TOP, Element.ALIGN_LEFT, tableFont, leading, padding, borders, ascender, descender)); table.addCell(makeCell("6-Abcdy", Element.ALIGN_MIDDLE, Element.ALIGN_LEFT, tableFont, leading, padding, borders, ascender, descender)); table.addCell(makeCell("7-Abcdy", Element.ALIGN_BOTTOM, Element.ALIGN_LEFT, tableFont, leading, padding, borders, ascender, descender)); table.addCell(makeCell("8-This\nis\na little\ntaller", Element.ALIGN_TOP, Element.ALIGN_LEFT, tableFont, leading, padding, borders, ascender, descender)); document.add(table); }
From source file:com.ideaspymes.proyecttemplate.stock.web.ProductoConsultaBean.java
public String createPdf() throws IOException, DocumentException { EtiquetaConf conf = etiquetaConfDAO.getEtiquetaConfDefault(); if (hayParaImprimir() && conf != null) { HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.setContentType("application/x-pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"etiquetas.pdf\""); float ancho = Utilities.millimetersToPoints(conf.getAnchoHoja().floatValue()); System.out.println("Ancho: " + ancho); float largo = Utilities.millimetersToPoints(conf.getLargoHoja().floatValue()); System.out.println("Alto: " + largo); // step 1 Document document = new Document(new Rectangle(ancho, largo)); // step 2 document.setMargins(0f, 0f, 0f, 0f); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // step 3 document.open();//from w w w . j a v a 2 s . com // step 4 PdfContentByte cb = writer.getDirectContent(); for (Producto p : getLista()) { if (p.getCantidadEtiquetas() > 0) { PdfPTable table = new PdfPTable(2); table.setWidthPercentage(96); Font fontbold = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); Chunk productTitle = new Chunk("HC", fontbold); Paragraph pTitile = new Paragraph(productTitle); pTitile.setAlignment(Element.ALIGN_LEFT); pTitile.setLeading(6, 0); PdfPCell cellTitle = new PdfPCell(); cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT); cellTitle.setVerticalAlignment(Element.ALIGN_TOP); cellTitle.setBorder(Rectangle.NO_BORDER); cellTitle.addElement(pTitile); Font font2 = FontFactory.getFont("Times-Roman", conf.getTamDescripcion().floatValue(), Font.NORMAL); Chunk productName = new Chunk(p.getNombre(), font2); Paragraph pName = new Paragraph(productName); pName.setAlignment(Element.ALIGN_CENTER); //pTitile.setLeading(0, 1); cellTitle.addElement(pName); table.addCell(cellTitle); Barcode39 code39 = new Barcode39(); code39.setCode(p.getCodigo()); //code39.setCodeType(Barcode.EAN13); code39.setBarHeight(conf.getAltoCodBarra().floatValue()); //codeEan.setX(0.7f); code39.setSize(conf.getTamDescripcion().floatValue()); //code39.setAltText("HC - " + p.getNombre()); PdfPCell cellBarcode = new PdfPCell(); cellBarcode.setHorizontalAlignment(Element.ALIGN_CENTER); cellBarcode.setBorder(Rectangle.NO_BORDER); cellBarcode.addElement(code39.createImageWithBarcode(cb, null, Color.BLACK)); table.addCell(cellBarcode); for (int i = 0; i < p.getCantidadEtiquetas(); 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; }