Java Code Examples for com.lowagie.text.Image#setRotationDegrees()
The following examples show how to use
com.lowagie.text.Image#setRotationDegrees() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellEventsTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * General example using cell events. * */ @Test public void main() throws Exception { // step1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CellEvents.pdf")); // step3 document.open(); // step4 CellEventsTest event = new CellEventsTest(); Image im = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg"); im.setRotationDegrees(30); PdfPTable table = new PdfPTable(4); table.addCell("text 1"); PdfPCell cell = new PdfPCell(im, true); cell.setCellEvent(event); table.addCell(cell); table.addCell("text 3"); im.setRotationDegrees(0); table.addCell(im); table.setTotalWidth(300); PdfContentByte cb = writer.getDirectContent(); table.writeSelectedRows(0, -1, 50, 600, cb); table.setHeaderRows(3); document.add(table); // step5 document.close(); }
Example 2
Source File: PdfTimetableGridTable.java From unitime with Apache License 2.0 | 5 votes |
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception { if (text==null) return; if (text.indexOf("<span")>=0) text = text.replaceAll("</span>","").replaceAll("<span .*>", ""); Font font = PdfFont.getFont(bold); BaseFont bf = font.getBaseFont(); float width = bf.getWidthPoint(text, font.getSize()); PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width); template.beginText(); template.setColorFill(Color.BLACK); template.setFontAndSize(bf, font.getSize()); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(font.getSize() + 2); //make an Image object from the template Image img = Image.getInstance(template); img.setRotationDegrees(270); //embed the image in a Chunk Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { cell.getPhrase().add(ck); } }
Example 3
Source File: TemplateImagesTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * PdfTemplates can be wrapped in an Image. */ @Test public void main() throws Exception { // step 1: creation of a document-object Rectangle rect = new Rectangle(PageSize.A4); rect.setBackgroundColor(new Color(238, 221, 88)); Document document = new Document(rect, 50, 50, 50, 50); // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templateImages.pdf")); // step 3: we open the document document.open(); // step 4: PdfTemplate template = writer.getDirectContent().createTemplate(20, 20); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); String text = "Vertical"; float size = 16; float width = bf.getWidthPoint(text, size); template.beginText(); template.setRGBColorFillF(1, 1, 1); template.setFontAndSize(bf, size); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(size + 2); template.sanityCheck(); Image img = Image.getInstance(template); img.setRotationDegrees(90); Chunk ck = new Chunk(img, 0, 0); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell = new PdfPCell(img); cell.setPadding(4); cell.setBackgroundColor(new Color(0, 0, 255)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell("I see a template on my right"); table.addCell(cell); table.addCell("I see a template on my left"); table.addCell(cell); table.addCell("I see a template everywhere"); table.addCell(cell); table.addCell("I see a template on my right"); table.addCell(cell); table.addCell("I see a template on my left"); Paragraph p1 = new Paragraph("This is a template "); p1.add(ck); p1.add(" just here."); p1.setLeading(img.getScaledHeight() * 1.1f); document.add(p1); document.add(table); Paragraph p2 = new Paragraph("More templates "); p2.setLeading(img.getScaledHeight() * 1.1f); p2.setAlignment(Element.ALIGN_JUSTIFIED); img.scalePercent(70); for (int k = 0; k < 20; ++k) p2.add(ck); document.add(p2); // step 5: we close the document document.close(); }
Example 4
Source File: StudentCardTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Generates a StudentCard */ @Test public void main() throws Exception { // step 1: creation of a document-object Rectangle rect = new Rectangle(243, 153); rect.setBackgroundColor(new Color(0xFF, 0xFF, 0xCC)); Document document = new Document(rect, 10, 10, 10, 10); // step 2: PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("studentcard.pdf")); // step 3: we open the document document.open(); // step 4: Font font = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, Color.BLUE); Paragraph p = new Paragraph("Ghent University", font); p.setAlignment(Element.ALIGN_CENTER); document.add(p); PdfContentByte cb = writer.getDirectContent(); Font f = FontFactory.getFont(FontFactory.HELVETICA, 8); PdfPTable outertable = new PdfPTable(3); outertable.setTotalWidth(200); outertable.getDefaultCell().setBorder(Rectangle.NO_BORDER); float[] outer = { 60, 25, 15 }; outertable.setWidths(outer); PdfPTable innertable = new PdfPTable(2); float[] inner = { 35, 65 }; innertable.setWidths(inner); innertable.addCell(new Paragraph("name:", f)); innertable.addCell(new Paragraph("Bruno Lowagie", f)); innertable.addCell(new Paragraph("date of birth:", f)); innertable.addCell(new Paragraph("June 10th, 1970", f)); innertable.addCell(new Paragraph("Study Program:", f)); innertable.addCell(new Paragraph("master in civil engineering", f)); innertable.addCell(new Paragraph("option:", f)); innertable.addCell(new Paragraph("architecture", f)); outertable.addCell(innertable); outertable.getDefaultCell().setBackgroundColor(new Color(0xFF, 0xDE, 0xAD)); outertable.addCell(Image.getInstance(PdfTestBase.RESOURCES_DIR + "bruno.jpg")); BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCodeType(Barcode.EAN13); codeEAN.setCode("8010012529736"); Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null); imageEAN.setRotationDegrees(90); outertable.getDefaultCell().setBackgroundColor(Color.WHITE); outertable.addCell(imageEAN); outertable.writeSelectedRows(0, -1, 20, 100, writer.getDirectContent()); // step 5: we close the document document.close(); }
Example 5
Source File: VerticalTextInCellsTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Example with vertical text in Cells. */ @Test public void main() throws Exception { // step1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("VerticalText.pdf")); // step3 document.open(); // step4 // make a PdfTemplate with the vertical text PdfTemplate template = writer.getDirectContent().createTemplate(20, 20); BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false); String text = "Vertical"; float size = 16; float width = bf.getWidthPoint(text, size); template.beginText(); template.setRGBColorFillF(1, 1, 1); template.setFontAndSize(bf, size); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(size + 2); // make an Image object from the template Image img = Image.getInstance(template); img.setRotationDegrees(90); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell = new PdfPCell(img); cell.setPadding(4); cell.setBackgroundColor(new Color(0, 0, 255)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell("I see a template on my right"); table.addCell(cell); table.addCell("I see a template on my left"); table.addCell(cell); table.addCell("I see a template everywhere"); table.addCell(cell); table.addCell("I see a template on my right"); table.addCell(cell); table.addCell("I see a template on my left"); document.add(table); // step5 document.close(); }
Example 6
Source File: JRPdfExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
private InternalImageProcessorResult processImageFillFrame(String rendererId, DataRenderable renderer) throws JRException { Image image = null; if (printImage.isUsingCache() && loadedImagesMap.containsKey(rendererId)) { image = loadedImagesMap.get(rendererId); } else { try { image = Image.getInstance(renderer.getData(jasperReportsContext)); imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0); } catch (Exception e) { throw new JRException(e); } if (printImage.isUsingCache()) { loadedImagesMap.put(rendererId, image); } } switch (printImage.getRotation()) { case LEFT : { image.scaleAbsolute(availableImageHeight, availableImageWidth); image.setRotationDegrees(90); break; } case RIGHT : { image.scaleAbsolute(availableImageHeight, availableImageWidth); image.setRotationDegrees(-90); break; } case UPSIDE_DOWN : { image.scaleAbsolute(availableImageWidth, availableImageHeight); image.setRotationDegrees(180); break; } case NONE : default : { image.scaleAbsolute(availableImageWidth, availableImageHeight); } } return new InternalImageProcessorResult( new Chunk(image, 0, 0), image.getScaledWidth(), image.getScaledHeight(), 0, 0 ); }
Example 7
Source File: JRPdfExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
private InternalImageProcessorResult processImageRetainShape(String rendererId, DataRenderable renderer) throws JRException { Image image = null; if (printImage.isUsingCache() && loadedImagesMap.containsKey(rendererId)) { image = loadedImagesMap.get(rendererId); } else { try { image = Image.getInstance(renderer.getData(jasperReportsContext)); imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0); } catch (Exception e) { throw new JRException(e); } if (printImage.isUsingCache()) { loadedImagesMap.put(rendererId, image); } } int xoffset = 0; int yoffset = 0; image.setRotationDegrees(0); // reset in case the image is from cache switch (printImage.getRotation()) { case LEFT : { image.scaleToFit(availableImageHeight, availableImageWidth); image.setRotationDegrees(90); xoffset = (int)(ImageUtil.getYAlignFactor(printImage) * (availableImageWidth - image.getPlainHeight())); yoffset = (int)((1f - ImageUtil.getXAlignFactor(printImage)) * (availableImageHeight - image.getPlainWidth())); break; } case RIGHT : { image.scaleToFit(availableImageHeight, availableImageWidth); image.setRotationDegrees(-90); xoffset = (int)((1f - ImageUtil.getYAlignFactor(printImage)) * (availableImageWidth - image.getPlainHeight())); yoffset = (int)(ImageUtil.getXAlignFactor(printImage) * (availableImageHeight - image.getPlainWidth())); break; } case UPSIDE_DOWN : { image.scaleToFit(availableImageWidth, availableImageHeight); image.setRotationDegrees(180); xoffset = (int)((1f - ImageUtil.getXAlignFactor(printImage)) * (availableImageWidth - image.getPlainWidth())); yoffset = (int)((1f - ImageUtil.getYAlignFactor(printImage)) * (availableImageHeight - image.getPlainHeight())); break; } case NONE : default : { image.scaleToFit(availableImageWidth, availableImageHeight); xoffset = (int)(ImageUtil.getXAlignFactor(printImage) * (availableImageWidth - image.getPlainWidth())); yoffset = (int)(ImageUtil.getYAlignFactor(printImage) * (availableImageHeight - image.getPlainHeight())); } } xoffset = (xoffset < 0 ? 0 : xoffset); yoffset = (yoffset < 0 ? 0 : yoffset); return new InternalImageProcessorResult( new Chunk(image, 0, 0), image.getScaledWidth(), image.getScaledHeight(), xoffset, yoffset ); }