Example usage for com.lowagie.text Rectangle getRight

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

Introduction

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

Prototype

public float getRight() 

Source Link

Document

Returns the upper right x-coordinate.

Usage

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;//  w w w  . ja  v a2s .  com
    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 {/*from w ww.  j a v  a  2s  .c  o m*/
        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();
}