Example usage for com.lowagie.text Rectangle getHeight

List of usage examples for com.lowagie.text Rectangle getHeight

Introduction

In this page you can find the example usage for com.lowagie.text Rectangle getHeight.

Prototype

public float getHeight() 

Source Link

Document

Returns the height of the rectangle.

Usage

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;
}

From source file:net.sourceforge.fenixedu.util.report.ReportsUtils.java

License:Open Source License

static public byte[] stampPdfAt(byte[] originalPdf, byte[] toStampPdf, int positionX, int positionY) {
    try {/*  w  ww . ja v  a  2  s. c  o  m*/
        PdfReader originalPdfReader = new PdfReader(originalPdf);
        PdfReader toStampPdfReader = new PdfReader(toStampPdf);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        PdfStamper stamper = new PdfStamper(originalPdfReader, stream);

        PdfImportedPage importedPage = stamper.getImportedPage(toStampPdfReader, 1);

        PdfContentByte overContent = stamper.getOverContent(1);

        Rectangle pageSizeWithRotation = originalPdfReader.getPageSizeWithRotation(1);
        Rectangle pageSizeWithRotationStamper = toStampPdfReader.getPageSizeWithRotation(1);

        logger.info(
                String.format("[ %s, %s]", pageSizeWithRotation.getWidth(), pageSizeWithRotation.getHeight()));
        logger.info(String.format("[ %s, %s]", pageSizeWithRotationStamper.getWidth(),
                pageSizeWithRotationStamper.getHeight()));

        Image image = Image.getInstance(importedPage);

        overContent.addImage(image, image.getWidth(), 0f, 0f, image.getHeight(), positionX, positionY);

        stamper.close();

        originalPdfReader.close();
        toStampPdfReader.close();

        return stream.toByteArray();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}

From source file:org.alchemy.core.AlcSession.java

License:Open Source License

/** Adds a pdfReadPage to an existing pdf file
 * //from w w  w  .  j a v a  2 s .  c om
 * @param mainPdf   The main pdf with multiple pages.
 *                  Also used as the destination file.
 * @param tempPdf   The 'new' pdf with one pdfReadPage to be added to the main pdf
 * @return
 */
boolean addPageToPdf(File mainPdf, File tempPdf) {
    try {
        // Destination file created in the temp dir then we will move it
        File dest = new File(DIR_TEMP, "Alchemy.pdf");
        OutputStream output = new FileOutputStream(dest);

        PdfReader reader = new PdfReader(mainPdf.getPath());
        PdfReader newPdf = new PdfReader(tempPdf.getPath());

        // See if the size of the canvas has increased
        // Size of the most recent temp PDF
        com.lowagie.text.Rectangle currentSize = newPdf.getPageSizeWithRotation(1);
        // Size of the session pdf at present
        com.lowagie.text.Rectangle oldSize = reader.getPageSizeWithRotation(1);
        // Sizes to be used from now on
        float pdfWidth = oldSize.getWidth();
        float pdfHeight = oldSize.getHeight();
        if (currentSize.getWidth() > pdfWidth) {
            pdfWidth = currentSize.getWidth();
        }
        if (currentSize.getHeight() > pdfHeight) {
            pdfHeight = currentSize.getHeight();
        }

        // Use the new bigger canvas size if required
        com.lowagie.text.Document document = new com.lowagie.text.Document(
                new com.lowagie.text.Rectangle(pdfWidth, pdfHeight), 0, 0, 0, 0);
        PdfCopy copy = new PdfCopy(document, output);

        // Copy the meta data
        document.addTitle("Alchemy Session");
        document.addAuthor(USER_NAME);
        document.addCreator("Alchemy <http://al.chemy.org>");
        copy.setXmpMetadata(reader.getMetadata());
        document.open();

        // Holds the PDF
        PdfContentByte cb = copy.getDirectContent();

        // Add each page from the main PDF
        for (int i = 0; i < reader.getNumberOfPages();) {
            ++i;
            document.newPage();
            cb.setDefaultColorspace(PdfName.CS, PdfName.DEVICERGB);
            PdfImportedPage page = copy.getImportedPage(reader, i);
            copy.addPage(page);
        }
        // Add the last (new) page
        document.newPage();
        PdfImportedPage lastPage = copy.getImportedPage(newPdf, 1);
        copy.addPage(lastPage);
        output.flush();
        document.close();
        output.close();

        if (dest.exists()) {
            // Save the location of the main pdf
            String mainPdfPath = mainPdf.getPath();
            // Delete the old file
            if (mainPdf.exists()) {
                mainPdf.delete();
            }
            // The final joined up pdf file
            File joinPdf = new File(mainPdfPath);
            // Rename the file
            boolean success = dest.renameTo(joinPdf);
            if (!success) {
                System.err.println("Error moving Pdf");
                return false;
            }

        } else {
            System.err.println("File does not exist?!: " + dest.getAbsolutePath());
            return false;
        }
        return true;

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.cyberoam.iview.charts.Chart.java

License:Open Source License

/**
 * This Event handler Method adds Header and Footer in PDF File
 *///  w ww  .  j av  a2  s  .c om
public void onEndPage(PdfWriter writer, Document document) {
    try {
        if (document.getPageNumber() > 1) {
            String seperator = System.getProperty("file.separator");
            //String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator;
            String path = InitServlet.contextPath + seperator + "images" + seperator;
            Image imgHead = Image.getInstance(path + "iViewPDFHeader.JPG");
            Image imgFoot = Image.getInstance(path + "iViewPDFFooter.JPG");
            Rectangle page = document.getPageSize();

            PdfPTable head = new PdfPTable(1);
            head.addCell(imgHead);
            head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin() - 10,
                    page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

            PdfPTable foot = new PdfPTable(1);
            foot.addCell(imgFoot);
            foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            foot.writeSelectedRows(0, -1, document.leftMargin() - 10, document.bottomMargin() + 24,
                    writer.getDirectContent());
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}