List of usage examples for com.lowagie.text Rectangle Rectangle
public Rectangle(float urx, float ury)
Rectangle
-object starting from the origin (0, 0). From source file:questions.graphics2D.SplitCanvasDifficult.java
public static void main(String[] args) { Document document = new Document(); try {/*from w w w. j a v a 2 s. c om*/ 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(); Graphics2D g2d; // distribute the image over 4 pages: 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(); 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(); 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(); 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 w ww .j a v a2s. 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); 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.graphics2D.SwingForceArialUni.java
public static void main(String[] args) { Document document = new Document(new Rectangle(210, 25)); try {/*from ww w .j a v a 2 s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); PdfContentByte cb = writer.getDirectContent(); FontMapper arialuni = new FontMapper() { public BaseFont awtToPdf(Font font) { try { return BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } public Font pdfToAwt(BaseFont font, int size) { return null; } }; Graphics2D g2 = cb.createGraphics(200, 50, arialuni); g2.setFont(null); g2.drawString("Greek mu: \u03bc - \u039c; degree symbol: \u00b0", 0, 40); g2.dispose(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); }
From source file:questions.images.MakingImageTransparent.java
public static void main(String args[]) { try {//from ww w . jav a 2s . c o 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(); } }
From source file:questions.importpages.NameCard.java
public static void createOneCard() throws DocumentException, IOException { Rectangle rect = new Rectangle(Utilities.millimetersToPoints(86.5f), Utilities.millimetersToPoints(55)); Document document = new Document(rect); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(CARD)); writer.setViewerPreferences(PdfWriter.PrintScalingNone); document.open();/* w w w.j a va2 s. c om*/ PdfReader reader = new PdfReader(LOGO); Image img = Image.getInstance(writer.getImportedPage(reader, 1)); img.scaleToFit(rect.getWidth() / 1.5f, rect.getHeight() / 1.5f); img.setAbsolutePosition((rect.getWidth() - img.getScaledWidth()) / 2, (rect.getHeight() - img.getScaledHeight()) / 2); document.add(img); document.newPage(); BaseFont bf = BaseFont.createFont(FONT, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); Font font = new Font(bf, 12); font.setColor(new CMYKColor(1, 0.5f, 0, 0.467f)); ColumnText column = new ColumnText(writer.getDirectContent()); Paragraph p; p = new Paragraph("Bruno Lowagie\n1T3XT\nbruno@1t3xt.com", font); p.setAlignment(Element.ALIGN_CENTER); column.addElement(p); column.setSimpleColumn(0, 0, rect.getWidth(), rect.getHeight() * 0.75f); column.go(); document.close(); }
From source file:ro.cs.om.utils.organigram.OrganigramUtils.java
License:Open Source License
/** * Creates the PDF file containing a JPEG Picture representing our Organigram. * It then writes this PDF File in an OutputStream. * Particular the OutputStream it's ServletOutputStream. * @author dan.damian //from w w w .j av a2s . c o m */ public void createPDFOrganigram(OutputStream os, OrgTree tree) throws Exception { //The PDF Document Document document = new Document(); //Organigram dimensions int height = calculateOrganigramHeight(tree); int width = calculateOrganigramWidth(tree); //Setting Document's dimensions document.setPageSize(new Rectangle(width + 200, height + 200)); PdfWriter.getInstance(document, os); document.open(); // Retrieving the Organization Organisation org = BLOrganisation.getInstance().get(tree.getRoot().getOrganizationId()); document.add(new Paragraph(org.getName())); // Create an Image BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // Get the Image's Graphics, and draw. Graphics2D g = img.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, width, height); //Start drawing the Organigram with one node, it's root... g.setColor(LINE_COLOR); String themeCode = ((UserAuth) SecurityContextHolder.getContext().getAuthentication().getPrincipal()) .getThemeCode(); String orgPicLocation = ORGANISATION_NODE_PICTURE_LOCATION.replace(REPLACE_THEME, themeCode); String deptPicLocation = DEPARTMENT_NODE_PICTURE_LOCATION.replace(REPLACE_THEME, themeCode); logger.debug("Org = " + ORGANISATION_NODE_PICTURE_LOCATION + ", " + orgPicLocation); logger.debug("Dept = " + DEPARTMENT_NODE_PICTURE_LOCATION + ", " + deptPicLocation); //Location of the Image file that will represent an Organization Box String nodeOrgImage = FileUtils.getInstance().getRealPathForResource(orgPicLocation); //Location of the Image file that will represent a Department Box String nodeDeptImage = FileUtils.getInstance().getRealPathForResource(deptPicLocation); logger.debug("nodeOrgImage = " + nodeOrgImage); logger.debug("nodeDeptImage = " + nodeDeptImage); drawNode(g, tree.getRoot(), nodeOrgImage, nodeDeptImage, true); //Add the Image to PDF com.lowagie.text.Image image = com.lowagie.text.Image .getInstance(ImageUtils.getInstance().bufferedImageToByteArray(img)); document.add(image); //Close the Document document.close(); }
From source file:ro.nextreports.engine.exporter.RtfExporter.java
License:Apache License
protected void initExport() throws QueryException { if (!bean.isSubreport()) { Padding margins = bean.getReportLayout().getPagePadding(); Rectangle rectangle;/* w w w . ja va 2 s. c o m*/ if (ReportLayout.CUSTOM.equals(bean.getReportLayout().getPageFormat())) { PaperSize customSize = bean.getReportLayout().getPaperSize(); rectangle = new Rectangle(customSize.getWidthPoints(), customSize.getHeightPoints()); } else { rectangle = PageSize.getRectangle(getPageFormat()); } document = new Document(rectangle, getPoints(margins.getLeft()), getPoints(margins.getRight()), getPoints(margins.getTop()), getPoints(margins.getBottom())); if (bean.getReportLayout().getOrientation() == LANDSCAPE) { document.setPageSize(rectangle.rotate()); } RtfWriter2 writer2 = RtfWriter2.getInstance(document, getOut()); } try { if (!bean.isSubreport()) { buildHeader(); buildFooter(); addMetaData(); document.open(); } table = buildRtfTable(PRINT_DOCUMENT); } catch (DocumentException e) { e.printStackTrace(); throw new QueryException(e); } }
From source file:wikitopdf.pdf.PdfTitleWrapper.java
License:Open Source License
/** * * @param num//w w w. j av a2s.c om * @param startPage * @throws FileNotFoundException * @throws DocumentException */ public PdfTitleWrapper(int num, int startPage, String firstLine, String lastLine) throws FileNotFoundException, DocumentException { //Read settings System.out.println("line in pdftitlewrap " + firstLine); int curPage = startPage; startPage = 0; PdfTitleWrapper.lastLine = lastLine; if (PdfTitleWrapper.lastLine != "") { new File("temp/tocVol-" + PdfTitleWrapper.num + "-" + PdfTitleWrapper.firstLine + ".pdf") .renameTo(new File("temp/" + String.format("%04d", PdfTitleWrapper.num) + "&&&" + PdfTitleWrapper.firstLine + "&&&" + PdfTitleWrapper.lastLine + "&&&.pdf")); } firstLine = firstLine.replaceAll("[_]", " "); firstLine = firstLine.replace("/", "\\");//gets confused on filenames with / as is supposed to be directory separator String outputFileName = "temp/tocVol-" + num + "-" + firstLine + ".pdf"; pdfDocument = new Document(new Rectangle(432, 648)); //(l,r,t,b) //going to switch the margins here because in the lulu printout it seems to have the margins going the opposite sides //originally 27f, 67.5f pdfDocument.setMargins(67.5f, 27f, 5.5f, 62.5f); pdfWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(outputFileName)); headerFooter = new TitlesFooter(startPage); pdfWriter.setPageEvent(headerFooter); pdfDocument.open(); pdfDocument.setMarginMirroring(false); wikiFontSelector = new WikiFontSelector(); //HeaderFooter hf = new HeaderFooter(new Phrase("head1"), new Phrase("head2")); //pdfDocument.setHeader(hf); //openMultiColumn(); // TitlesFooter.setCurrentLine(firstLine); PdfTitleWrapper.firstLine = firstLine; PdfTitleWrapper.num = num; PdfContentByte cb = pdfWriter.getDirectContent(); ct = new ColumnText(cb); //ct.setIndent(20); // addPrologue(); // newPage(); }