Example usage for com.lowagie.text Rectangle getTop

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

Introduction

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

Prototype

public float getTop() 

Source Link

Document

Returns the upper right y-coordinate.

Usage

From source file:org.geomajas.plugin.print.parser.RectangleConverter.java

License:Open Source License

@Override
public String toString(Object obj) {
    Rectangle rectangle = (Rectangle) obj;
    if (obj == null) {
        return null;
    }// w w w. j av a 2 s. c  om
    return rectangle.getLeft() + "," + rectangle.getBottom() + "," + rectangle.getRight() + ","
            + rectangle.getTop();
}

From source file:org.jaffa.modules.printing.services.FormPrintEngineIText.java

License:Open Source License

/**
 * Any work to start off printing the document
 * @throws FormPrintException Thrown if there is any form processing problems
 *///www .  j  a  va2 s . c o m
protected void startDocument() throws FormPrintException {
    log.debug("startDocument:");

    Rectangle r = m_templateReader.getPageSize(getCurrentTemplatePage());
    log.debug("Page Size      : t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r="
            + r.getRight() + ", rot=" + r.getRotation());
    r = m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage());
    log.debug("Page Size w/Rot: t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r="
            + r.getRight() + ", rot=" + r.getRotation());

    m_generatedDoc = new Document(m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()));
    //m_generatedDoc = new Document(m_templateReader.getPageSize(getCurrentTemplatePage()));
    m_output = new ByteArrayOutputStream();
    try {
        m_writer = PdfWriter.getInstance(m_generatedDoc, m_output);
    } catch (DocumentException e) {
        log.error("Error Creating Writer - " + e.getMessage(), e);
        throw new EngineProcessingException("Error Creating Writer - " + e.getMessage());
    }

    if (getDocumentProperties() != null) {
        Properties dp = (Properties) getDocumentProperties().clone();
        if (dp.getProperty(DOCUMENT_PROPERTY_TITLE) != null) {
            m_generatedDoc.addTitle(dp.getProperty(DOCUMENT_PROPERTY_TITLE));
            dp.remove(DOCUMENT_PROPERTY_TITLE);
        }
        if (dp.getProperty(DOCUMENT_PROPERTY_SUBJECT) != null) {
            m_generatedDoc.addSubject(dp.getProperty(DOCUMENT_PROPERTY_SUBJECT));
            dp.remove(DOCUMENT_PROPERTY_SUBJECT);
        }
        if (dp.getProperty(DOCUMENT_PROPERTY_KEYWORDS) != null) {
            m_generatedDoc.addKeywords(dp.getProperty(DOCUMENT_PROPERTY_KEYWORDS));
            dp.remove(DOCUMENT_PROPERTY_KEYWORDS);
        }
        if (dp.getProperty(DOCUMENT_PROPERTY_CREATOR) != null) {
            m_generatedDoc.addCreator(dp.getProperty(DOCUMENT_PROPERTY_CREATOR, "Jaffa Print Engine"));
            dp.remove(DOCUMENT_PROPERTY_CREATOR);
        }
        if (dp.getProperty(DOCUMENT_PROPERTY_AUTHOR) != null) {
            m_generatedDoc.addAuthor(dp.getProperty(DOCUMENT_PROPERTY_AUTHOR));
            dp.remove(DOCUMENT_PROPERTY_AUTHOR);
        }
        // loop through other properties and set them as header parameters
        for (Enumeration en = dp.elements(); en.hasMoreElements();) {
            Map.Entry e = (Map.Entry) en.nextElement();
            if (e.getKey() != null && e.getValue() != null)
                m_generatedDoc.addHeader(e.getKey().toString(), e.getValue().toString());
        }
    }
    m_generatedDoc.addCreationDate();

    m_generatedDoc.open();

}

From source file:org.jaffa.modules.printing.services.FormPrintEngineIText.java

License:Open Source License

/**
 * Any work to start off printing a page of the document
 * m_currentPage will contain the page being printed, and
 * m_currentTemplatePage will contain the template page number to base this
 * new page on./*  w w  w .j  a va 2 s  .com*/
 * @throws FormPrintException Thrown if there is any form processing problems
 */
protected void startPage() throws FormPrintException {
    log.debug("startPage: Page=" + getCurrentPage());

    Rectangle r = m_templateReader.getPageSize(getCurrentTemplatePage());
    log.debug("Page Size      : t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r="
            + r.getRight() + ", rot=" + r.getRotation());
    r = m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage());
    log.debug("Page Size w/Rot: t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r="
            + r.getRight() + ", rot=" + r.getRotation());

    // Get rotation quadrent 0..3
    int q = (m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()).getRotation() % 360) / 90;
    float tX = (q == 2 ? r.getTop() : 0) + (q == 3 ? r.getRight() : 0);
    float tY = (q == 1 ? r.getTop() : 0) + (q == 2 ? r.getRight() : 0);
    float sX = 1f, sY = 1f;
    double angle = -r.getRotation() * (Math.PI / 180f);
    double transformA = sX * Math.cos(angle);
    double transformB = sY * Math.sin(angle);
    double transformC = -sX * Math.sin(angle);
    double transformD = sY * Math.cos(angle);
    double transformE = tX;
    double transformF = tY;

    m_generatedDoc.setPageSize(m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()));
    //m_generatedDoc.setPageSize(m_templateReader.getPageSize(getCurrentTemplatePage()) );
    /**
     * try {
     * m_generatedDoc.newPage();
     * } catch (DocumentException e) {
     * log.error("Error Creating New Page - " + e.getMessage() ,e);
     * throw new EngineProcessingException("Error Creating New Page - " + e.getMessage());
     * }
     **/
    m_generatedDoc.newPage();

    PdfImportedPage page = m_writer.getImportedPage(m_templateReader, getCurrentTemplatePage());
    PdfContentByte cb = m_writer.getDirectContent();
    //cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
    cb.addTemplate(page, (float) transformA, (float) transformB, (float) transformC, (float) transformD,
            (float) transformE, (float) transformF);
    log.debug("Matrix = [A=" + transformA + ", B=" + transformB + ", C=" + transformC + ", D=" + transformD
            + ", E=" + transformE + ", F=" + transformF + " ]");
}

From source file:org.mapfish.print.config.layout.HeaderFooter.java

License:Open Source License

public void render(final Rectangle rectangle, PdfContentByte dc, PJsonObject params, RenderingContext context) {
    try {//from www  .  jav a2s.  com
        final PdfPTable table = PDFUtils.buildTable(items, params, context,
                1/*multiple items are arranged by lines*/, null);
        if (table != null) {
            table.setTotalWidth(rectangle.getWidth());
            table.writeSelectedRows(0, -1, rectangle.getLeft(), rectangle.getTop(), dc);
        }
    } catch (DocumentException e) {
        context.addError(e);
    }
}

From source file:org.nuxeo.ecm.platform.signature.core.sign.SignatureServiceImpl.java

License:Open Source License

/**
 * Verifies that a provided value fits within the page bounds. If it does not, a sign exception is thrown. This is
 * to verify externally configurable signature positioning.
 *
 * @param isHorizontal - if false, the current value is checked agains the vertical page dimension
 *///from   w w w.  j a  v a  2s  .  c  o m
protected void validatePageBounds(PdfReader pdfReader, int pageNo, float valueToCheck, boolean isHorizontal)
        throws SignException {
    if (valueToCheck < 0) {
        String message = "The new signature position " + valueToCheck
                + " exceeds the page bounds. The position must be a positive number.";
        log.debug(message);
        throw new SignException(message);
    }

    Rectangle pageRectangle = pdfReader.getPageSize(pageNo);
    if (isHorizontal && valueToCheck > pageRectangle.getRight()) {
        String message = "The new signature position " + valueToCheck
                + " exceeds the horizontal page bounds. The page dimensions are: (" + pageRectangle + ").";
        log.debug(message);
        throw new SignException(message);
    }
    if (!isHorizontal && valueToCheck > pageRectangle.getTop()) {
        String message = "The new signature position " + valueToCheck
                + " exceeds the vertical page bounds. The page dimensions are: (" + pageRectangle + ").";
        log.debug(message);
        throw new SignException(message);
    }
}

From source file:org.openconcerto.erp.core.finance.accounting.report.PdfGenerator.java

License:Open Source License

private void init() throws FileNotFoundException {

    // we create a reader for a certain document
    PdfReader reader = null;//from   www. ja va 2s  .c  o  m
    PdfWriter writer = null;
    try {
        reader = new PdfReader(getStreamStatic(this.fileNameIn));

        // we retrieve the total number of pages
        int n = reader.getNumberOfPages();
        // we retrieve the size of the first page
        Rectangle psize = reader.getPageSize(1);

        psize.setRight(psize.getRight() - this.templateOffsetX);
        psize.setTop(psize.getTop() - this.templateOffsetY);

        this.width = (int) psize.getWidth();
        float height = psize.getHeight();

        // step 1: creation of a document-object
        int MARGIN = 32;
        this.document = new Document(psize, MARGIN, MARGIN, MARGIN, MARGIN);
        // step 2: we create a writer that listens to the document
        if (!this.directoryOut.exists()) {
            this.directoryOut.mkdirs();
        }
        System.err.println("Directory out " + this.directoryOut.getAbsolutePath());
        File f = new File(this.directoryOut, this.fileNameOut);
        if (f.exists()) {
            f.renameTo(new File(this.directoryOut, "Old" + this.fileNameOut));
            f = new File(this.directoryOut, this.fileNameOut);
        }

        System.err.println("Creation du fichier " + f.getAbsolutePath());

        writer = PdfWriter.getInstance(this.document, new FileOutputStream(f));

        this.document.open();
        // step 4: we add content
        this.cb = writer.getDirectContent();

        System.out.println("There are " + n + " pages in the document.");

        this.document.newPage();

        PdfImportedPage page1 = writer.getImportedPage(reader, 1);

        this.cb.addTemplate(page1, -this.templateOffsetX, -this.templateOffsetY);

        this.bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
        this.bfb = BaseFont.createFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED);

    } catch (FileNotFoundException fE) {
        throw fE;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}

From source file:org.revager.export.PDFCellEventExtRef.java

License:Open Source License

@Override
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
    PdfContentByte cb = canvas[PdfPTable.LINECANVAS];

    // cb.reset();

    Rectangle attachmentRect = new Rectangle(rect.getLeft() - 25, rect.getTop() - 25,
            rect.getRight() - rect.getWidth() - 40, rect.getTop() - 10);

    String fileDesc = file.getName() + " (" + translate("File Attachment") + ")";

    try {/*www  .ja va  2s. com*/
        PdfAnnotation attachment = PdfAnnotation.createFileAttachment(writer, attachmentRect, fileDesc, null,
                file.getAbsolutePath(), file.getName());
        writer.addAnnotation(attachment);
    } catch (IOException e) {
        /*
         * just do not add a reference if the file was not found or another
         * error occured.
         */
    }

    // cb.setColorStroke(new GrayColor(0.8f));
    // cb.roundRectangle(rect.getLeft() + 4, rect.getBottom(),
    // rect.getWidth() - 8, rect.getHeight() - 4, 4);

    cb.stroke();
}