Example usage for com.itextpdf.text.pdf PdfContentByte showTextAligned

List of usage examples for com.itextpdf.text.pdf PdfContentByte showTextAligned

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfContentByte showTextAligned.

Prototype

public void showTextAligned(final int alignment, final String text, final float x, final float y,
        final float rotation) 

Source Link

Document

Shows text right, left or center aligned with rotation.

Usage

From source file:Registration_Transient.java

private void saveToPdf() {
    try {/*  w ww  .  j  a va 2  s  .  co m*/

        com.itextpdf.text.Document doc = new com.itextpdf.text.Document();
        BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt"));
        String path = "";
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            path = sb.toString().trim();
        } finally {
            br.close();
        }
        FileOutputStream fos = new FileOutputStream(path + "\\transient\\" + lastNameTextField.getText().trim()
                + ", " + firstNameTextField.getText().trim() + "TransientForm.pdf");
        PdfWriter.getInstance(doc, fos);

        PdfReader pdfReader = new PdfReader("TransientForm.pdf");

        PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);
        //doc.open();
        //doc.add(new Paragraph(contents.getText().trim() + "-markram"));
        float varPosition = 0;
        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
            PdfContentByte content = pdfStamper.getOverContent(i);
            //Text over the existing page
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
            content.beginText();
            content.setFontAndSize(bf, 10);
            varPosition = 15;
            //last name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    lastNameTextField.getText().trim() + ", " + firstNameTextField.getText().trim(), 100,
                    661 + varPosition, 0);
            //first name 
            content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    new SimpleDateFormat("MM/dd/yyyy").format(Calendar.getInstance().getTime()), 400,
                    661 + varPosition, 0);

            if (residentNameCheckBox.isSelected()) {
                content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        residentComboBox.getSelectedItem().toString(), 125, 633 + varPosition, 0);
                content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        residentComboBox.getSelectedItem().toString(), 470, 633 + varPosition, 0);
            } else {
                content.showTextAligned(PdfContentByte.ALIGN_LEFT, "N / A", 125, 633 + varPosition, 0);
                content.showTextAligned(PdfContentByte.ALIGN_LEFT, "N / A", 470, 633 + varPosition, 0);
            }

            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mobileNoTextField.getText(), 135,
                    590 + varPosition, 0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, emailTextField.getText(), 400, 590 + varPosition,
                    0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, addressTextField.getText(), 175,
                    577 + varPosition, 0);
            varPosition = 35;
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, roomReservedTextField.getText(), 135,
                    507 + varPosition, 0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, dateArrivalChooserCombo.getText(), 135,
                    493 + varPosition, 0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, dateDepartureChooserCombo.getText(), 435,
                    493 + varPosition, 0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestSpinner.getValue().toString(), 180,
                    478 + varPosition, 0);
            for (int count = 0; count < guestTable.getRowCount(); count++) {
                float x = 50;
                if (count <= 3) {
                    content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                            guestTable.getValueAt(count, 0).toString(), x, 435 + varPosition, 0);
                    varPosition -= 13;
                    if (count == 3) {
                        varPosition = 35;
                    }
                } else if (count >= 4 & count <= 7) {
                    content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                            guestTable.getValueAt(count, 0).toString(), x + 200, 435 + varPosition, 0);
                    varPosition -= 13;
                    if (count == 7) {
                        varPosition = 35;
                    }
                } else {
                    content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                            guestTable.getValueAt(count, 0).toString(), x + 400, 435 + varPosition, 0);
                    varPosition -= 13;
                }

            }
            content.endText();

        }
        pdfStamper.close();
        pdfReader.close();
    } catch (DocumentException ex) {
        //            Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    } catch (FileNotFoundException ex) {
        //            Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    } catch (IOException ex) {
        //            Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:Billing_v2.java

public boolean saveStatementOfAccountToPDF(ArrayList<String> info) {
    try {/*www .  jav  a2 s. c  o m*/
        BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt"));
        String path = "";
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            path = sb.toString().trim();
        } finally {
            br.close();
        }

        com.itextpdf.text.Document doc = new com.itextpdf.text.Document();
        FileOutputStream fos = new FileOutputStream(
                path + "\\residentStatementOfAccount\\" + info.get(0) + "statementOfAccounts.pdf");
        PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos);

        PdfReader pdfReader = new PdfReader("statementOfAccounts.pdf");

        PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);

        java.util.Date date = new SimpleDateFormat("yyyy-MM-dd").parse(info.get(6));

        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
            PdfContentByte content = pdfStamper.getOverContent(i);
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
            content.beginText();
            content.setFontAndSize(bf, 10);
            //month
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, new SimpleDateFormat("MMMM").format(date), 205,
                    625, 0);
            //name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(0), 125, 610, 0);
            //roomNumber
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(1), 130, 598, 0);
            //monthly rate
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(2), 205, 560, 0);
            //Shuttle rate
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(3), 205, 545, 0);
            //gadget rate
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(4), 205, 530, 0);
            //additional fee
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(5), 205, 518, 0);
            //total amount
            Double totalAmount = Double.parseDouble(info.get(2)) + Double.parseDouble(info.get(3))
                    + Double.parseDouble(info.get(4));
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, totalAmount + "", 205, 490, 0);
            //due date

            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.MONTH, Calendar.MONTH - 1);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(7), 130, 463, 0);

            content.endText();

        }
        pdfStamper.close();
        pdfReader.close();
        fos.close();
        pdfWriter.close();

        return true;
    } catch (DocumentException | ParseException ex) {
        //            Logger.getLogger(Billing_v2.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
        return false;
    } catch (FileNotFoundException ex) {
        //            Logger.getLogger(Billing_v2.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
        return false;
    } catch (IOException ex) {
        //            Logger.getLogger(Billing_v2.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
        return false;
    }
}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private byte[] personalize(byte[] pdf, Contact contact, Toc tableOfContents)
        throws IOException, DocumentException {

    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {

        final PdfReader reader = new PdfReader(pdf);
        final PdfStamper stamper = new PdfStamper(reader, bos);

        // stamp some text on first page
        PdfContentByte text = stamper.getOverContent(1);

        text.beginText();//from  www.  j  a v  a 2s .c  o m

        text.setColorFill(iTextUtil.getFontCoverText().getColor());
        text.setFontAndSize(iTextUtil.getFontCoverText().getBaseFont(), iTextUtil.getFontCoverText().getSize());
        text.showTextAligned(Element.ALIGN_RIGHT, coverTitle1,
                text.getPdfDocument().getPageSize().getWidth() - 15, 195, 0);
        text.showTextAligned(Element.ALIGN_RIGHT, coverTitle2,
                text.getPdfDocument().getPageSize().getWidth() - 15, 175, 0);
        text.showTextAligned(Element.ALIGN_RIGHT, contact.getCurrency().getTitlePageDescription(),
                text.getPdfDocument().getPageSize().getWidth() - 15, 80, 0);

        text.setColorFill(iTextUtil.getFontCoverPricingguide().getColor());
        text.setFontAndSize(iTextUtil.getFontCoverPricingguide().getBaseFont(),
                iTextUtil.getFontCoverPricingguide().getSize());
        text.showTextAligned(Element.ALIGN_RIGHT, coverTitle3,
                text.getPdfDocument().getPageSize().getWidth() - 15, 145, 0);

        text.setColorFill(iTextUtil.getFontCoverYear().getColor());
        text.setFontAndSize(iTextUtil.getFontCoverYear().getBaseFont(), iTextUtil.getFontCoverYear().getSize());
        text.showTextAligned(Element.ALIGN_RIGHT, coverTitle4,
                text.getPdfDocument().getPageSize().getWidth() - 15, 105, 0);

        text.endText();

        // stamp some text on first page of the table of contents page
        final Image logoImage = iTextUtil.getImageFromByteArray(HttpUtil.readByteArray(
                pdfTemplate.getLogo().getUrl(), defaultService.getUserName(), defaultService.getPassword()));
        final PdfContentByte tocContent = stamper.getOverContent(tableOfContents.getFirstPageOfToc());
        final float resizeRatio = logoImage.getHeight() / 85; // define the desired height of the log
        tocContent.addImage(logoImage, logoImage.getWidth() / resizeRatio, 0, 0,
                logoImage.getHeight() / resizeRatio, 59, 615);

        text = stamper.getOverContent(tableOfContents.getFirstPageOfToc());

        text.beginText();

        text.setColorFill(iTextUtil.getFontPersonalization().getColor());
        text.setFontAndSize(iTextUtil.getFontPersonalization().getBaseFont(),
                iTextUtil.getFontPersonalization().getSize());
        text.showTextAligned(Element.ALIGN_LEFT, "Prepared for:", 355, 681, 0);
        text.showTextAligned(Element.ALIGN_LEFT, contact.getFullName(), 355, 662, 0);

        // set company name
        if (!StringUtils.isEmpty(contact.getCompany())) {
            text.showTextAligned(Element.ALIGN_LEFT, contact.getCompany(), 355, 643, 0);
            text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355,
                    624, 0);
        } else {
            text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355,
                    643, 0);
        }

        text.endText();

        final ColumnText ct = new ColumnText(tocContent);
        ct.setSimpleColumn(new Rectangle(55, 517, iTextUtil.PAGE_SIZE.getWidth() - 45, 575));
        final List<Element> elements = HTMLWorker.parseToList(new StringReader(disclaimer), null);
        final Paragraph p = new Paragraph();
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        for (Element element : elements) {
            for (Chunk chunk : element.getChunks()) {
                chunk.setFont(iTextUtil.getFontDisclaimer());
            }
            p.add(element);
        }
        ct.addElement(p);
        ct.go();

        stamper.close();
        reader.close();
        return bos.toByteArray();

    }

}

From source file:bouttime.report.boutsheet.BoutSheetReport.java

License:Open Source License

/**
 * Generate a bout sheet report for the given list of bouts.
 * It is assumed that the list is in the desired order (no sorting is done here).
 *
 * @param list//from  w  w w . j a v  a2s.  c  om
 * @return True if the report was generated.
 */
public boolean generateReport(Dao dao, List<Bout> list) {

    // step 1: creation of a document-object
    // rotate to make page landscape
    Document document = new Document(PageSize.A4.rotate());

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter writer = PdfWriter.getInstance(document, fos);
        writer.setPageEvent(this);

        // step 3: we open the document
        document.open();

        // step 4: we grab the ContentByte and do some stuff with it
        PdfContentByte cb = writer.getDirectContent();

        BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
        float pageWidth = cb.getPdfDocument().getPageSize().getWidth();
        float midPage = pageWidth / 2;

        setHeaderString(dao);

        int count = 0;
        for (Bout b : list) {
            boolean rightSide = false;
            if ((count++ % 2) == 0) {
                if (count > 2) {
                    // We could put this after Bout 2 is added, but
                    // that could leave a blank last page.
                    document.newPage();
                }

                // Bout 1 (Left side)
                drawBout(cb, bf, 35, midPage - 35, b);
            } else {
                // Bout 2 (Right side)
                drawBout(cb, bf, midPage + 35, pageWidth - 35, b);
                rightSide = true;
            }

            // Print the watermark, if necessary
            boolean doWatermark = false;
            String gClass = b.getGroup().getClassification();
            String wmValues = dao.getBoutsheetWatermarkValues();
            if ((wmValues != null) && !wmValues.isEmpty()) {
                String[] tokens = wmValues.split(",");
                for (String s : tokens) {
                    if (s.trim().equalsIgnoreCase(gClass)) {
                        doWatermark = true;
                        break;
                    }
                }
            }
            if (doWatermark) {
                int rotation = 45;
                PdfContentByte ucb = writer.getDirectContentUnder();
                BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
                ucb.saveState();
                ucb.setColorFill(BaseColor.LIGHT_GRAY);
                ucb.beginText();
                ucb.setFontAndSize(helv, 86);
                float centerWidth = document.getPageSize().getWidth() / 4;
                if (rightSide) {
                    centerWidth = centerWidth * 3;
                }
                ucb.showTextAligned(Element.ALIGN_CENTER, gClass, centerWidth,
                        document.getPageSize().getHeight() / 2, rotation);
                ucb.endText();
                ucb.restoreState();
            }
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    } catch (IOException ioe) {
        logger.error("IO Exception", ioe);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.bracketsheet.BracketSheetReport.java

License:Open Source License

public static boolean generateReport(Dao dao, List<Group> list, String outputFile, boolean doBoutNumbers,
        boolean doTimestamp) {

    if (list.isEmpty()) {
        return false;
    }// w  w  w .j  av  a  2  s  .c  o m

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile(outputFile);
        if (fos == null) {
            return false;
        }
        PdfWriter writer = PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: we grab the ContentByte and do some stuff with it
        PdfContentByte cb = writer.getDirectContent();

        String timestamp = "";
        if (doTimestamp) {
            timestamp = DateFormat.getInstance().format(new Date());
        }

        int rv;
        int i = 0;
        int size = list.size();
        for (Group g : list) {
            rv = addBracket(cb, dao, g, doBoutNumbers);
            if (rv != PAGE_ERROR) {
                // Print the watermark, if necessary
                boolean doWatermark = false;
                String gClass = g.getClassification();
                String wmValues = dao.getBracketsheetWatermarkValues();
                if ((wmValues != null) && !wmValues.isEmpty()) {
                    String[] tokens = wmValues.split(",");
                    for (String s : tokens) {
                        if (s.trim().equalsIgnoreCase(gClass)) {
                            doWatermark = true;
                            break;
                        }
                    }
                }

                int rotation = (rv == PAGE_ROUNDROBIN) ? 45 : 135;

                if (doWatermark) {
                    PdfContentByte ucb = writer.getDirectContentUnder();
                    BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
                    ucb.saveState();
                    ucb.setColorFill(BaseColor.LIGHT_GRAY);
                    ucb.beginText();
                    ucb.setFontAndSize(helv, 86);
                    ucb.showTextAligned(Element.ALIGN_CENTER, gClass, document.getPageSize().getWidth() / 2,
                            document.getPageSize().getHeight() / 2, rotation);
                    ucb.endText();
                    ucb.restoreState();
                }

                if (doTimestamp) {
                    rotation -= 45;
                    float width = cb.getPdfWriter().getPageSize().getWidth();
                    int x = (rv == PAGE_ROUNDROBIN) ? 15 : (int) (width - 15);
                    int y = 15;
                    BracketSheetUtil.drawTimestamp(cb, null, x, y, 10, timestamp, rotation);
                }

                // If not doing bout numbers, this is an 'award' type of
                // bracket.  So print an image/logo, if configured.
                if (!doBoutNumbers && (dao.getBracketsheetAwardImage() != null)
                        && !dao.getBracketsheetAwardImage().isEmpty()) {
                    Image image = Image.getInstance(Image.getInstance(dao.getBracketsheetAwardImage()));
                    image.setRotationDegrees((rv == PAGE_ROUNDROBIN) ? 0 : 90);
                    PositionOnPage positionOnPage = dao.getBracketsheetAwardImagePosition();
                    if (PositionOnPage.UPPER_RIGHT == positionOnPage) {
                        float x = (rv == PAGE_ROUNDROBIN)
                                ? document.getPageSize().getWidth() - 10 - image.getWidth()
                                : 10;
                        float y = document.getPageSize().getHeight() - 10 - image.getHeight();
                        image.setAbsolutePosition(x, y);
                        cb.addImage(image);
                    } else if (PositionOnPage.CENTER == positionOnPage) {
                        // put the image in the background, in the middle of the page
                        PdfContentByte ucb = writer.getDirectContentUnder();
                        float pageX = document.getPageSize().getWidth() / 2;
                        float pageY = document.getPageSize().getHeight() / 2;
                        float imageX = image.getWidth() / 2;
                        float imageY = image.getHeight() / 2;
                        image.setAbsolutePosition(pageX - imageX, pageY - imageY);
                        ucb.addImage(image);
                    }
                }

                if (++i < size) {
                    document.newPage();
                }
            }
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    } catch (IOException ioe) {
        logger.error("IO Exception", ioe);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.bracketsheet.BracketSheetUtil.java

License:Open Source License

public static void drawString(PdfContentByte cb, BaseFont bf, float mid, float y, float fontSize, String string,
        float rotation) throws DocumentException, IOException {

    if (bf == null) {
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
    }//from w ww  . jav a 2 s .  com

    cb.setFontAndSize(bf, fontSize);

    cb.beginText();
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, string, mid, y, rotation);
    cb.endText();
    cb.stroke();
}

From source file:bouttime.report.bracketsheet.BracketSheetUtil.java

License:Open Source License

public static void drawStringAligned(PdfContentByte cb, BaseFont bf, int alignment, float mid, float y,
        float fontSize, String string, float rotation) throws DocumentException, IOException {

    if (bf == null) {
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
    }//from   w  w w .j a  va  2s  .  c om

    cb.setFontAndSize(bf, fontSize);

    cb.beginText();
    cb.showTextAligned(alignment, string, mid, y, rotation);
    cb.endText();
    cb.stroke();
}

From source file:bouttime.report.bracketsheet.BracketSheetUtil.java

License:Open Source License

public static void drawStringCentered(PdfContentByte cb, BaseFont bf, float mid, float y, float fontSize,
        String string, float rotation) throws DocumentException, IOException {

    if (bf == null) {
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
    }/*from   w w  w  .j a  v a2 s  .  co m*/

    cb.setFontAndSize(bf, fontSize);

    cb.beginText();
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, (string != null) ? string : "", mid, y, rotation);
    cb.endText();
    cb.stroke();
}

From source file:com.cib.statementstamper.windows.StatementStamperMainWindow.java

License:Open Source License

protected ByteArrayOutputStream doStamper(ByteArrayOutputStream baos) throws IOException, DocumentException {

    map.clear();/*from w w  w  .  jav a2 s .  c om*/
    ByteArrayOutputStream baosFinal = new ByteArrayOutputStream();
    PdfReader reader = new PdfReader(baos.toByteArray());

    PdfContentStreamProcessor processor = new PdfContentStreamProcessor(this);
    for (int i = 1; i <= reader.getNumberOfPages(); i++) {
        actualPage = i;
        PdfDictionary pageDic = reader.getPageN(i);
        PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES);
        processor.processContent(ContentByteUtils.getContentBytesForPage(reader, i), resourcesDic);
    }

    Document newDocument = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(newDocument, baosFinal);

    newDocument.open();
    PdfContentByte canvas = writer.getDirectContent();
    //      Font myFont = FontFactory.getFont(FontFactory.COURIER, 7, Font.BOLD);
    Iterator<Entry<Integer, Map<Float, StringBuffer>>> it = map.entrySet().iterator();

    while (it.hasNext()) {
        Map.Entry<Integer, Map<Float, StringBuffer>> pairs = (Map.Entry<Integer, Map<Float, StringBuffer>>) it
                .next();

        Iterator<Entry<Float, StringBuffer>> iter = pairs.getValue().entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<Float, StringBuffer> actualEntry = iter.next();
            canvas.beginText();
            canvas.setFontAndSize(myFontBase, 7);
            canvas.showTextAligned(Element.ALIGN_LEFT, actualEntry.getValue().toString(), 25,
                    actualEntry.getKey() + 60, 0);
            canvas.endText();
        }
        newDocument.newPage();
    }
    newDocument.close();

    reader = new PdfReader(baosFinal.toByteArray());

    PdfReaderContentParser parser = new PdfReaderContentParser(reader);
    TextMarginFinder finder;
    for (int i = 1; i <= reader.getNumberOfPages(); i++) {
        finder = parser.processContent(i, new TextMarginFinder());
        if (finder.getLly() <= 68) {
            getWindow().showNotification("Hiba", "A(z) " + i + ".ik oldalon tl sok a szveg !!!",
                    Notification.TYPE_ERROR_MESSAGE);
            return null;
        }
    }

    reader = new PdfReader(baosFinal.toByteArray());
    PdfStamper stamper = new PdfStamper(reader, baosFinal);
    int n = reader.getNumberOfPages();
    for (int i = 1; i <= n; i++) {
        PdfContentByte overContent = stamper.getOverContent(i);
        overContent.addImage(logo, 131, 0, 0, 32, 44, 775);
        getFooterTable(i, n).writeSelectedRows(0, -1, 27, 68, stamper.getOverContent(i)); // ez a jo
        getIspLogoTable(i, n).writeSelectedRows(0, -1, 425, 45, stamper.getOverContent(i));
    }
    stamper.close();
    reader.close();
    return baosFinal;
}

From source file:com.cyberninjas.pdf.PdfEditor.java

License:Open Source License

/**
 * Write text to a PDF in given format./*from   w w w  . j  av  a2s. c om*/
 *
 * @param pageNum the page to write to.
 * @param text the text to write.
 * @param font to use.
 * @param size the size of font.
 * @param align the alignment.
 * @param x the x-coordinate.
 * @param y the y-coordinate.
 * @param z the rotation.
 */
protected void writeText(final int pageNum, final String text, final BaseFont font, final int size,
        final Alignment align, final float x, final float y, final float z) {
    PdfContentByte canvas = stamper.getOverContent(pageNum);

    canvas.beginText();
    canvas.setFontAndSize(font, size);
    canvas.showTextAligned(convertHorizontalAlignment(align), text, x, y, z);
    canvas.endText();
}