Example usage for com.itextpdf.text Document right

List of usage examples for com.itextpdf.text Document right

Introduction

In this page you can find the example usage for com.itextpdf.text Document right.

Prototype


public float right() 

Source Link

Document

Returns the upper right x-coordinate.

Usage

From source file:co.com.realtech.mariner.util.files.PDFUtils.java

public static File agregarTexto(byte[] bytes, String text) {
    File temp = null;//ww w . j  a v a2s.  c  o  m
    try {
        temp = File.createTempFile("archivo", ".pdf");
        OutputStream oos = new FileOutputStream(temp);
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, oos);
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        //InputStream targetStream = new FileInputStream(initialFile);
        // Load existing PDF
        PdfReader reader = new PdfReader(bis);
        PdfImportedPage page = writer.getImportedPage(reader, 1);
        // Copy first page of existing PDF into output PDF
        document.setPageSize(reader.getPageSize(1));
        document.newPage();
        cb.addTemplate(page, 0, 0);

        ColumnText ct = new ColumnText(cb);
        Phrase myText = new Phrase(text);
        Font fuente = new Font();
        fuente.setSize(6);
        myText.setFont(fuente);
        ct.setSimpleColumn(myText, 0, -1, document.right(), document.top(), -10, Element.ALIGN_RIGHT);
        ct.go();

        ColumnText ct2 = new ColumnText(cb);
        Phrase myText2 = new Phrase(text);
        Font fuente2 = new Font();
        fuente2.setSize(6);
        myText2.setFont(fuente);
        ct2.setSimpleColumn(myText, 0, -1, document.right(), document.top(), 248, Element.ALIGN_RIGHT);
        ct2.go();

        ColumnText ct3 = new ColumnText(cb);
        Phrase myText3 = new Phrase(text);
        Font fuente3 = new Font();
        fuente3.setSize(6);
        myText3.setFont(fuente);
        ct3.setSimpleColumn(myText, 0, -1, document.right(), document.top(), 505, Element.ALIGN_RIGHT);
        ct3.go();

        document.close();
    } catch (Exception e) {
        System.out.println("e = " + e);
    }
    return temp;
}

From source file:com.afrisoftech.lib.HeaderFooterHelper.java

public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    // Phrase header = new Phrase("this is a header", ffont);
    // Phrase footer = new Phrase("this is a footer", ffont);
    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, header,
            (document.right() - document.left()) / 2 + document.leftMargin(), document.top() + 10, 0);
    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER,
            new Phrase(footer.getContent() + " " + String.valueOf(writer.getPageNumber())),
            (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 10, 0);
}

From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java

License:Apache License

/**
 * chapter write  /*from   w ww .  j  a  v a2s.  com*/
 */
public void onChapter(PdfWriter writer, Document document, float position, Paragraph title) {

    titles.add(
            getTocParagraph(title.getContent(), writer.getPageNumber(), 0, document.left(), document.right()));

}

From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java

License:Apache License

/**
 * Section write  /*from w w  w. ja v  a 2  s .c om*/
 */
public void onSection(PdfWriter writer, Document document, float position, int depth, Paragraph title) {
    title = getTocParagraph(title.getContent(), writer.getPageNumber(), depth, document.left(),
            document.right());
    title.setIndentationLeft(12 * depth);
    titles.add(title);
}

From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java

License:Open Source License

private void writeDocument(Document document, File targetFile) {
    boolean frame = detailTabfolder.getSelectionIndex() == 1;
    try (FileOutputStream out = new FileOutputStream(targetFile)) {
        PdfWriter writer = PdfWriter.getInstance(document, out);
        document.open();//from  w  ww.ja va 2 s. co m
        writer.setPageEvent(new PdfPageEventHelper() {
            int pageNo = 0;
            com.itextpdf.text.Font ffont = new com.itextpdf.text.Font(
                    com.itextpdf.text.Font.FontFamily.HELVETICA, 9, com.itextpdf.text.Font.NORMAL,
                    BaseColor.DARK_GRAY);

            @Override
            public void onEndPage(PdfWriter w, Document d) {
                PdfContentByte cb = w.getDirectContent();
                Phrase footer = new Phrase(String.valueOf(++pageNo), ffont);
                ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer,
                        (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom(), 0);
            }
        });
        String tit = NLS.bind(Messages.ExhibitionEditDialog_exhibition_name, nameField.getText());
        Paragraph p = new Paragraph(tit,
                FontFactory.getFont(FontFactory.HELVETICA, 14, com.itextpdf.text.Font.BOLD, BaseColor.BLACK));
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(8);
        document.add(p);
        String subtitle = NLS.bind(Messages.ExhibitionEditDialog_image_list, Constants.DFDT.format(new Date()),
                frame ? Messages.ExhibitionEditDialog_image_sizes : Messages.ExhibitionEditDialog_frame_sizes);
        p = new Paragraph(subtitle,
                FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK));
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(14);
        document.add(p);
        p = new Paragraph(descriptionField.getText(),
                FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK));
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(10);
        document.add(p);
        p = new Paragraph(infoField.getText(),
                FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK));
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(10);
        document.add(p);
        IDbManager db = Core.getCore().getDbManager();
        List<Wall> walls = current.getWall();
        Wall[] sortedWalls = walls.toArray(new Wall[walls.size()]);
        Arrays.sort(sortedWalls, new Comparator<Wall>() {
            public int compare(Wall o1, Wall o2) {
                return o1.getLocation().compareToIgnoreCase(o2.getLocation());
            }
        });
        for (Wall wall : sortedWalls) {
            p = new Paragraph(wall.getLocation(), FontFactory.getFont(FontFactory.HELVETICA, 12,
                    com.itextpdf.text.Font.BOLD, BaseColor.BLACK));
            p.setAlignment(Element.ALIGN_LEFT);
            p.setSpacingAfter(12);
            document.add(p);
            PdfPTable table = new PdfPTable(7);
            // table.setBorderWidth(1);
            // table.setBorderColor(new Color(224, 224, 224));
            // table.setPadding(5);
            // table.setSpacing(0);
            table.setWidths(new int[] { 8, 33, 13, 13, 20, 13, 20 });
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_No, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_title, Element.ALIGN_LEFT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_xpos, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_height, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_size, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader(Messages.ExhibitionEditDialog_dpi, Element.ALIGN_RIGHT));
            table.addCell(createTableHeader("", Element.ALIGN_LEFT)); //$NON-NLS-1$
            // table.endHeaders();
            List<ExhibitImpl> exhibits = new ArrayList<ExhibitImpl>();
            for (String exhibitId : wall.getExhibit()) {
                ExhibitImpl exhibit = db.obtainById(ExhibitImpl.class, exhibitId);
                if (exhibit != null)
                    exhibits.add(exhibit);
            }
            Collections.sort(exhibits, new Comparator<ExhibitImpl>() {
                public int compare(ExhibitImpl e1, ExhibitImpl e2) {
                    return ((Exhibit) e1).getX() - ((Exhibit) e2).getX();
                }
            });
            int no = 1;
            for (ExhibitImpl exhibit : exhibits) {
                int tara = computeTara(frame, exhibit);
                table.addCell(createTableCell(String.valueOf(no++), Element.ALIGN_RIGHT));
                table.addCell(createTableCell(exhibit.getTitle(), Element.ALIGN_LEFT));
                af.setMaximumFractionDigits(2);
                af.setMinimumFractionDigits(2);
                String x = af.format((exhibit.getX() - tara) / 1000d);
                table.addCell(createTableCell(NLS.bind("{0} m", x), Element.ALIGN_RIGHT)); //$NON-NLS-1$
                String y = af.format((exhibit.getY() + tara) / 1000d);
                table.addCell(createTableCell(NLS.bind("{0} m", y), Element.ALIGN_RIGHT)); //$NON-NLS-1$
                af.setMaximumFractionDigits(1);
                af.setMinimumFractionDigits(1);
                String h = af.format((exhibit.getHeight() + 2 * tara) / 10d);
                int width = exhibit.getWidth();
                String w = af.format((width + 2 * tara) / 10d);
                table.addCell(createTableCell(NLS.bind("{0} x {1} cm", w, h), Element.ALIGN_RIGHT)); //$NON-NLS-1$
                AssetImpl asset = dbManager.obtainAsset(exhibit.getAsset());
                if (asset != null) {
                    int pixels = asset.getWidth();
                    double dpi = pixels * 25.4d / width;
                    table.addCell(createTableCell(String.valueOf((int) dpi), Element.ALIGN_RIGHT));
                } else
                    table.addCell(""); //$NON-NLS-1$
                table.addCell(createTableCell(exhibit.getSold() ? Messages.ExhibitionEditDialog_sold : "", //$NON-NLS-1$
                        Element.ALIGN_LEFT));
            }
            document.add(table);
        }
        document.close();
    } catch (DocumentException e) {
        UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_internal_error_writing_pdf, e);
    } catch (IOException e) {
        UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_io_error_writing_pdf, e);
    }
}

From source file:com.dandymadeproductions.ajqvue.io.PDFDataTableDumpThread.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb;/* ww w. ja  v a 2s.c  o m*/
    String text;
    float textSize;
    float textBase;
    float adjust;

    cb = writer.getDirectContent();
    textBase = document.bottom() - 20;

    cb.beginText();
    cb.setFontAndSize(BASE_FONT, 12);
    adjust = BASE_FONT.getWidthPoint("000", 12);

    cb.setTextMatrix(document.bottom(), textBase);
    cb.showText("Produced by iTextpdf");

    text = "Page " + writer.getPageNumber() + " of ";
    textSize = BASE_FONT.getWidthPoint(text, 12);
    cb.setTextMatrix(document.right() - textSize - adjust, textBase);
    cb.showText(text);

    cb.endText();

    if (pdfTemplate != null)
        cb.addTemplate(pdfTemplate, document.right() - adjust, textBase);
}

From source file:com.dandymadeproductions.myjsqlview.io.PDFDataTableDumpThread.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    String text = "Page " + writer.getPageNumber() + " of ";
    float textSize = BASE_FONT.getWidthPoint(text, 12);
    float textBase = document.bottom() - 20;
    cb.beginText();/*from   w  w  w  . j a  v a2s  . co m*/
    cb.setFontAndSize(BASE_FONT, 12);
    float adjust = BASE_FONT.getWidthPoint("000", 12);
    cb.setTextMatrix(document.right() - textSize - adjust, textBase);
    cb.showText(text);
    cb.endText();
    cb.addTemplate(pdfTemplate, document.right() - adjust, textBase);
}

From source file:com.softwaremagico.tm.pdf.complete.events.FooterEvent.java

License:Open Source License

/**
 * Adds a footer to every page//from  w  w  w.j a  va 2  s . co m
 *
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(com.itextpdf.text.pdf.PdfWriter,
 *      com.itextpdf.text.Document)
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {
    if (writer.getPageNumber() % 2 == 0) {
        PdfContentByte cb = writer.getDirectContent();
        Phrase footer = new Phrase(
                "Created using 'Think Machine'"
                        + (Version.getVersion() != null ? " v" + Version.getVersion() : ""),
                new Font(FadingSunsTheme.getFooterFont(), FadingSunsTheme.FOOTER_FONT_SIZE));
        ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer,
                (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() + 20, 0);
    }
}

From source file:com.softwaremagico.tm.pdf.complete.events.PartyFooterEvent.java

License:Open Source License

/**
 * Adds a footer to every page/*from   w ww . j  a  va  2  s.  co m*/
 *
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(com.itextpdf.text.pdf.PdfWriter,
 *      com.itextpdf.text.Document)
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    Phrase footer = new Phrase(
            party.getPartyName() + " - Created using 'Think Machine'"
                    + (Version.getVersion() != null ? " v" + Version.getVersion() : ""),
            new Font(FadingSunsTheme.getFooterFont(), FadingSunsTheme.FOOTER_FONT_SIZE));
    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer,
            (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() + bottomMargin,
            0);
}

From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java

public static void printToPDF(ArrayList<Person> workers, EventGig event) throws IOException, DocumentException {
    String filename = event.getName() + ".pdf";
    String path = event.getData() + " " + event.getName() + "//";

    Document document = new Document();
    // step 2//from  www  .j a va 2  s. c o m
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + filename));
    // step 3
    document.open();
    // step 4
    ColumnText column = new ColumnText(writer.getDirectContent());

    float[][] x = { { document.left(), document.left() + 230 }, { document.right() - 230, document.right() } };
    for (Person person : workers) {
        column.addElement(MakerPDF.createTable(person, event));
    }
    int count = 0;
    float height = 0;
    int status = ColumnText.START_COLUMN;
    while (ColumnText.hasMoreText(status)) {
        column.setSimpleColumn(x[count][0], document.bottom(), x[count][1], document.top() - height - 10);
        // render as much content as possible
        status = column.go();
        // go to a new page if you've reached the last column
        if (++count > 1) {
            count = 0;
            document.newPage();
        }
    }
    document.newPage();
    document.close();
}