List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(Image image)
From source file:permit.InvoicePdf.java
License:Open Source License
/** * handles the letter header//from ww w.j av a2 s . c o m */ PdfPTable getHeader() { // String str = ""; String spacer = " "; PdfPTable headTable = null; try { // // for http url use // Image image = Image.getInstance(url + "js/images/city_logo3.jpg"); Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); float[] widths = { 25f, 40f, 35f }; // percentages headTable = new PdfPTable(widths); headTable.setWidthPercentage(100); headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); image.scalePercent(15f); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headTable.addCell(cell); // float[] width = { 33f }; PdfPTable midTable = new PdfPTable(width); midTable.setWidthPercentage(33); midTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); midTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); Phrase phrase = new Phrase(); Chunk ch = new Chunk("City of Bloomington ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Planning and Transportation Department ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("bloomington.in.gov", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // headTable.addCell(midTable); // PdfPTable rightTable = new PdfPTable(width); rightTable.setWidthPercentage(33); rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); rightTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); phrase = new Phrase(); ch = new Chunk("401 N Morton St Suite 130 ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("PO Box 100 \nBloomington, IN 47404", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("\n Phone: (812) 349-3423\nFax (812) 349-3520\nEmail: planning@bloomington.in.gov", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); headTable.addCell(rightTable); } catch (Exception ex) { logger.error(ex); } return headTable; }
From source file:permit.PermitPdf.java
License:Open Source License
/** * handles the letter header//from w w w . ja v a2 s .c o m */ PdfPTable getHeader() { // String str = ""; String spacer = " "; // PdfPTable headTable = null; try { // // for http url use // Image image = Image.getInstance(url + "js/images/city_logo3.jpg"); Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); float[] widths = { 25f, 40f, 35f }; // percentages headTable = new PdfPTable(widths); headTable.setWidthPercentage(100); headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // image.setWidthPercentage(33.0f); image.scalePercent(15f); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headTable.addCell(cell); // float[] width = { 33f }; PdfPTable midTable = new PdfPTable(width); midTable.setWidthPercentage(33); midTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); midTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); Phrase phrase = new Phrase(); Chunk ch = new Chunk("City of Bloomington ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Planning and Transportation Department ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("bloomington.in.gov", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // headTable.addCell(midTable); // PdfPTable rightTable = new PdfPTable(width); rightTable.setWidthPercentage(33); rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); rightTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); phrase = new Phrase(); ch = new Chunk("401 N Morton St Suite 130 ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("PO Box 100 \nBloomington, IN 47404", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("\n Phone: (812) 349-3423\nFax (812) 349-3520\nEmail: planning@bloomington.in.gov", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); headTable.addCell(rightTable); } catch (Exception ex) { logger.error(ex); } return headTable; }
From source file:ppro.contoller.ExportController.java
public void preProcessPDF(Object document) throws IOException, DocumentException { final Document pdf = (Document) document; pdf.setPageSize(PageSize.A4.rotate()); pdf.open();/*from w w w . ja v a2s.co m*/ String logo = getAbsolutePath("logo_1663576_web.jpg"); pdf.add(Image.getInstance(logo)); }
From source file:ppro.contoller.ExportController.java
private Image getImage(String imageName) throws IOException, BadElementException { final Image image = Image.getInstance(getAbsolutePath(imageName)); image.scalePercent(90f);// ww w . j ava2 s .c o m return image; }
From source file:questions.compression.CompressionLevelsImage.java
public static void createPdf(int compressionLevel) { try {//from w w w .j a va2 s.c o m Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT[compressionLevel + 1])); writer.setCompressionLevel(compressionLevel); document.open(); Image img = Image.getInstance(RESOURCE); img.setCompressionLevel(compressionLevel); document.add(img); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.graphics2D.SplitCanvas.java
public static void main(String[] args) { Document document = new Document(); try {/* w w w .j a v a 2s. c o m*/ document.setPageSize(new Rectangle(100, 100)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); // create the canvas for the complete drawing: PdfContentByte directContent = writer.getDirectContentUnder(); PdfTemplate canvas = directContent.createTemplate(200, 200); Graphics2D g2d = canvas.createGraphicsShapes(200, 200); // draw to the complete drawing to the canvas: g2d.setPaint(new Color(150, 150, 255)); g2d.setStroke(new BasicStroke(10.0f)); g2d.drawArc(50, 50, 100, 100, 0, 360); g2d.dispose(); // wrap the canvas inside an image: Image img = Image.getInstance(canvas); // distribute the image over 4 pages: img.setAbsolutePosition(0, -100); document.add(img); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(25, 25, 25, 100); g2d.drawLine(25, 25, 100, 25); g2d.dispose(); document.newPage(); img.setAbsolutePosition(-100, -100); document.add(img); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(0, 25, 75, 25); g2d.drawLine(75, 25, 75, 100); g2d.dispose(); document.newPage(); img.setAbsolutePosition(0, 0); document.add(img); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(25, 0, 25, 75); g2d.drawLine(25, 75, 100, 75); g2d.dispose(); document.newPage(); img.setAbsolutePosition(-100, 0); document.add(img); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(0, 75, 75, 75); g2d.drawLine(75, 0, 75, 75); g2d.dispose(); } catch (DocumentException de) { de.printStackTrace(); return; } catch (IOException ioe) { ioe.printStackTrace(); return; } document.close(); }
From source file:questions.graphics2D.SplitCanvasEasy.java
public static void main(String[] args) { Document document = new Document(); try {//from ww w. j a v a2 s . com document.setPageSize(new Rectangle(100, 100)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); // create the canvas for the complete drawing: PdfContentByte directContent = writer.getDirectContentUnder(); PdfTemplate canvas = directContent.createTemplate(200, 200); Graphics2D g2d = canvas.createGraphicsShapes(200, 200); // draw to the complete drawing to the canvas: g2d.setPaint(new Color(150, 150, 255)); g2d.setStroke(new BasicStroke(10.0f)); g2d.drawArc(50, 50, 100, 100, 0, 360); g2d.dispose(); // wrap the canvas inside an image: Image img = Image.getInstance(canvas); // distribute the image over 4 pages: img.setAbsolutePosition(0, -100); document.add(img); document.newPage(); img.setAbsolutePosition(-100, -100); document.add(img); document.newPage(); img.setAbsolutePosition(0, 0); document.add(img); document.newPage(); img.setAbsolutePosition(-100, 0); document.add(img); } catch (DocumentException de) { de.printStackTrace(); return; } catch (IOException ioe) { ioe.printStackTrace(); return; } document.close(); }
From source file:questions.images.CustomizedTitleBar.java
public static void main(String[] args) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setInitialLeading(18);//from w ww . j ava 2 s. c om document.open(); Image button = Image.getInstance(RESOURCE); document.add(getTitleBar(writer, button, "My first title")); for (int i = 0; i < 20; i++) document.add(new Paragraph("Some text: " + i)); document.add(getTitleBar(writer, button, "My second title")); for (int i = 0; i < 10; i++) document.add(new Paragraph("Some text: " + i)); document.newPage(); document.add(getTitleBar(writer, button, "My third title")); for (int i = 0; i < 10; i++) document.add(new Paragraph("Some text: " + i)); document.close(); }
From source file:questions.images.CustomizedTitleBar.java
public static Image getTitleBar(PdfWriter writer, Image background, String title) throws DocumentException, IOException { float width = background.getWidth(); float height = background.getHeight(); PdfTemplate tmp = writer.getDirectContent().createTemplate(width, height); tmp.addImage(background, width, 0, 0, height, 0, 0); BaseFont font = BaseFont.createFont(); tmp.beginText();//from w w w. j a va 2s.co m tmp.setGrayFill(1); tmp.setFontAndSize(font, 18); tmp.showTextAligned(Element.ALIGN_CENTER, title, width / 2, 4, 0); tmp.endText(); return Image.getInstance(tmp); }
From source file:questions.images.MakingImageTransparent.java
public static void main(String args[]) { try {//from w ww. j a v a 2 s . co m Rectangle rect; // GIF Image Image gif = Image.getInstance(GIF); gif.setAbsolutePosition(0, 0); gif.setTransparency(new int[] { 0x5B, 0x5D }); rect = new Rectangle(gif.getScaledWidth(), gif.getScaledHeight()); rect.setBackgroundColor(Color.YELLOW); Document document = new Document(rect); PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); document.add(gif); // JPEG Image java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(JPG); Image jpg = Image.getInstance(awtImage, null, true); jpg.setTransparency(new int[] { 0xF0, 0xFF }); jpg.setAbsolutePosition(0, 0); rect = new Rectangle(jpg.getScaledWidth(), jpg.getScaledHeight()); rect.setBackgroundColor(Color.YELLOW); document.setPageSize(rect); document.newPage(); document.add(jpg); document.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }