List of usage examples for com.lowagie.text Rectangle getWidth
public float getWidth()
From source file:net.laubenberger.wichtel.helper.HelperPdf.java
License:Open Source License
/** * Writes a PDF from multiple image files to a {@link File}. * //from w w w . j a va 2s. co m * @param pageSize * of the PDF * @param scale * images to fit the page size * @param file * output as PDF * @param files * for the PDF * @throws DocumentException * @throws IOException * @see File * @see Rectangle * @since 0.0.1 */ public static void writePdfFromImages(final Rectangle pageSize, final boolean scale, final File file, final File... files) throws DocumentException, IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(pageSize, scale, file, files)); if (null == pageSize) { throw new RuntimeExceptionIsNull("pageSize"); //$NON-NLS-1$ } if (null == file) { throw new RuntimeExceptionIsNull("file"); //$NON-NLS-1$ } if (null == files) { throw new RuntimeExceptionIsNull("files"); //$NON-NLS-1$ } if (!HelperArray.isValid(files)) { throw new RuntimeExceptionIsEmpty("files"); //$NON-NLS-1$ } final Document document = new Document(pageSize); document.setMargins(0.0F, 0.0F, 0.0F, 0.0F); try (FilterOutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) { PdfWriter.getInstance(document, fos); document.open(); for (final File inputFile : files) { if (null == inputFile) { throw new RuntimeExceptionIsNull("inputFile"); //$NON-NLS-1$ } final Image image = Image.getInstance(inputFile.getAbsolutePath()); if (scale) { image.scaleToFit(pageSize.getWidth(), pageSize.getHeight()); } document.add(image); document.newPage(); } document.close(); } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.laubenberger.wichtel.helper.HelperPdf.java
License:Open Source License
/** * Writes a PDF from multiple {@link java.awt.Image} to a {@link File}. * //from w w w. j a va2s.c o m * @param pageSize * of the PDF * @param scale * images to fit the page size * @param file * output as PDF * @param images * for the PDF * @throws DocumentException * @throws IOException * @see File * @see java.awt.Image * @see Rectangle * @since 0.0.1 */ public static void writePdfFromImages(final Rectangle pageSize, final boolean scale, final File file, final java.awt.Image... images) throws DocumentException, IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(pageSize, scale, file, images)); if (null == pageSize) { throw new RuntimeExceptionIsNull("pageSize"); //$NON-NLS-1$ } if (null == file) { throw new RuntimeExceptionIsNull("file"); //$NON-NLS-1$ } if (null == images) { throw new RuntimeExceptionIsNull("images"); //$NON-NLS-1$ } if (!HelperArray.isValid(images)) { throw new RuntimeExceptionIsEmpty("images"); //$NON-NLS-1$ } final Document document = new Document(pageSize); document.setMargins(0.0F, 0.0F, 0.0F, 0.0F); try (FilterOutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) { PdfWriter.getInstance(document, fos); document.open(); for (final java.awt.Image tempImage : images) { if (null == tempImage) { throw new RuntimeExceptionIsNull("tempImage"); //$NON-NLS-1$ } final Image image = Image.getInstance(tempImage, null); if (scale) { image.scaleToFit(pageSize.getWidth(), pageSize.getHeight()); } document.add(image); document.newPage(); } } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.refractions.udig.printing.ui.internal.PdfPrintingEngine.java
License:Open Source License
public boolean printToPdf() { Dimension paperSize = page.getPaperSize(); Dimension pageSize = page.getSize(); float xScale = (float) paperSize.width / (float) pageSize.width; float yScale = (float) paperSize.height / (float) pageSize.height; Rectangle paperRectangle = new Rectangle(paperSize.width, paperSize.height); Document document = new Document(paperRectangle, 0f, 0f, 0f, 0f); try {/* w ww .j av a2s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputPdfFile)); document.open(); PdfContentByte cb = writer.getDirectContent(); Graphics2D graphics = cb.createGraphics(paperRectangle.getWidth(), paperRectangle.getHeight()); // BufferedImage bI = new BufferedImage((int) paperRectangle.width(), (int) // paperRectangle // .height(), BufferedImage.TYPE_INT_ARGB); // Graphics graphics2 = bI.getGraphics(); List<Box> boxes = page.getBoxes(); for (Box box : boxes) { String id = box.getID(); System.out.println(id); Point boxLocation = box.getLocation(); if (boxLocation == null) continue; int x = boxLocation.x; int y = boxLocation.y; Dimension size = box.getSize(); if (size == null) continue; int w = size.width; int h = size.height; float newX = xScale * (float) x; float newY = yScale * (float) y; float newW = xScale * (float) w; float newH = yScale * (float) h; box.setSize(new Dimension((int) newW, (int) newH)); box.setLocation(new Point((int) newX, (int) newY)); Graphics2D boxGraphics = (Graphics2D) graphics.create((int) newX, (int) newY, (int) newW, (int) newH); BoxPrinter boxPrinter = box.getBoxPrinter(); boxPrinter.draw(boxGraphics, monitor); } graphics.dispose(); // ImageIO.write(bI, "png", new File("c:\\Users\\moovida\\Desktop\\test.png")); // graphics.drawImage(bI, null, 0, 0); document.newPage(); document.close(); writer.close(); } catch (DocumentException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return true; }
From source file:net.refractions.udig.printing.ui.internal.template.A0LandscapeTemplate.java
License:Open Source License
protected Rectangle getPaperSize() { Rectangle a0 = PageSize.A0; Rectangle a0Landscape = new Rectangle(0f, 0f, a0.getHeight(), a0.getWidth()); return a0Landscape; }
From source file:net.refractions.udig.printing.ui.internal.template.A1LandscapeTemplate.java
License:Open Source License
protected Rectangle getPaperSize() { Rectangle a1 = PageSize.A1; Rectangle a1Landscape = new Rectangle(0f, 0f, a1.getHeight(), a1.getWidth()); return a1Landscape; }
From source file:net.refractions.udig.printing.ui.internal.template.A2LandscapeTemplate.java
License:Open Source License
protected Rectangle getPaperSize() { Rectangle a2 = PageSize.A2; Rectangle a2Landscape = new Rectangle(0f, 0f, a2.getHeight(), a2.getWidth()); return a2Landscape; }
From source file:net.refractions.udig.printing.ui.internal.template.A3LandscapeTemplate.java
License:Open Source License
protected Rectangle getPaperSize() { Rectangle a3 = PageSize.A3; Rectangle a3Landscape = new Rectangle(0f, 0f, a3.getHeight(), a3.getWidth()); return a3Landscape; }
From source file:net.refractions.udig.printing.ui.internal.template.A4LandscapeTemplate.java
License:Open Source License
protected Rectangle getPaperSize() { Rectangle a4 = PageSize.A4; Rectangle a4Landscape = new Rectangle(0f, 0f, a4.getHeight(), a4.getWidth()); return a4Landscape; }
From source file:net.refractions.udig.printing.ui.internal.template.LegalLandscapeTemplate.java
License:Open Source License
protected Rectangle getPaperSize() { Rectangle legal = PageSize.LEGAL; Rectangle legalLandscape = new Rectangle(0f, 0f, legal.getHeight(), legal.getWidth()); return legalLandscape; }
From source file:net.refractions.udig.printing.ui.internal.template.LetterLandscapeTemplate.java
License:Open Source License
protected Rectangle getPaperSize() { Rectangle letter = PageSize.LETTER; Rectangle letterLandscape = new Rectangle(0f, 0f, letter.getHeight(), letter.getWidth()); return letterLandscape; }