Example usage for com.itextpdf.text Paragraph add

List of usage examples for com.itextpdf.text Paragraph add

Introduction

In this page you can find the example usage for com.itextpdf.text Paragraph add.

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:PDFmaker.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from w  w w . j ava2 s .  co  m
    // Lets write a big header
    preface.add(new Paragraph("Productielijst", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(
            new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + LocalDate.now(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    smallBold));
    //        addEmptyLine(preface, 3);
    //        preface.add(new Paragraph(
    //                "This document describes something which is very important ",
    //                smallBold));
    //
    //        addEmptyLine(preface, 8);
    //
    //        preface.add(new Paragraph(
    //                "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //                redFont));    
    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:PDFmaker.java

private static void addEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }//from w  w w  .j  ava2  s  . c om
}

From source file:Pdfsave.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from  www  . j av  a 2 s.c  o  m*/
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:pdf_demo2.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph paragraph = new Paragraph();
    // We add one empty line
    addEmptyLine(paragraph, 1);/*  w w w  .  j a va2 s .  co m*/
    // Lets write a big header
    paragraph.add(new Paragraph("Title of the document", titleFont));

    addEmptyLine(paragraph, 1);
    // Will create: Report generated by: _name, _date
    paragraph.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(),
            smallBold));
    addEmptyLine(paragraph, 3);
    paragraph.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(paragraph, 8);
    paragraph.add(
            new Paragraph("This document is a preliminary version and not subject to your license agreement "
                    + "or any other agreement with vogella.com ;-).", redFont));

    document.add(paragraph);
    // Start a new page
    document.newPage();
}

From source file:ApplicationClasses.Reservation.ReservationInvoice.java

public void generatePDFinvoice(ReservationCustomer cus) throws Exception {

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_YEAR, 0);
    String date2 = dateFormat.format(c.getTime());

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream(this.invoiceNo + ".pdf"));
    doc.open();/*w  ww  .j av  a2 s .com*/
    doc.add(new Paragraph("CREATE TOURS PVT LTD",
            FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD, BaseColor.RED)));

    Paragraph p = new Paragraph();

    p.add("Reservation Invoice");
    p.add("\n INVOICE DATE : " + date2);

    p.setAlignment(Paragraph.ALIGN_CENTER);
    doc.add(p);
    doc.add(new Paragraph(cus.getCustomerName()));
    doc.add(new Paragraph(
            "-------------------------------------------------------------------------------------------------------------------------------"));
    //doc.add(new Paragraph("Deposit : " + this.deposit.toString() + "\t Resvation Start Date : " + this.reservationEndDate + "\t Reservation End Date : "+this.reservationEndDate  ));
    PdfPTable table = new PdfPTable(4);
    table.addCell("No");
    table.addCell("Description");
    table.addCell("VehicalRegNo");
    table.addCell("Price");
    for (int i = 0; i < invoiceDataArray.size(); i++) {
        Integer no = i + 1;

        table.addCell(no.toString());
        table.addCell(invoiceDataArray.get(i).getDescription());
        table.addCell(invoiceDataArray.get(i).getRegNo());
        table.addCell(invoiceDataArray.get(i).getPrice().toString());
    }
    doc.add(table);

    doc.add(new Paragraph("Total Cost :" + this.totalPrice.toString()));
    doc.add(new Paragraph("Deposit : " + this.deposit.toString()));
    doc.add(new Paragraph("Resvation Start Date : " + this.reservationStartDate));
    doc.add(new Paragraph("Reservation End Date : " + this.reservationEndDate));

    doc.close();
}

From source file:avalonscrollmaker20.AnothakScribe.java

License:Open Source License

public void writeToDoc(ArrayList<AnothakScroll> spellList, boolean simpleMode) {
    // Format content for inserting into a PDF
    for (int i = 0; i < spellList.size(); i++) {
        Paragraph spellCode = new Paragraph(spellList.get(i).spellCode, f_code);
        spellCode.setAlignment(ElementTags.ALIGN_RIGHT);
        spellCode.setMultipliedLeading(0.5f);
        spellCode.setIndentationRight(15f);

        Paragraph spellTitle = new Paragraph(spellList.get(i).spellTitle + "\n", f_title);
        spellTitle.setAlignment(ElementTags.ALIGN_CENTER);
        spellTitle.setMultipliedLeading(0.5f);
        spellTitle.setSpacingAfter(36f);

        Paragraph spellCircleSchool;// w  w w.  ja  va  2  s  .c  om
        if (spellList.get(i).isPure())
            spellCircleSchool = new Paragraph(spellList.get(i).spellCircle.toString() + " Circle\n    of "
                    + spellList.get(i).spellOldSchool.toString(), f_schoolPure);
        else // !spellList.get( i ).isPure()
            spellCircleSchool = new Paragraph(spellList.get(i).spellCircle.toString() + " Circle\n    of "
                    + spellList.get(i).spellOldSchool.toString(), f_school);
        spellCircleSchool.setAlignment(ElementTags.ALIGN_LEFT);
        spellCircleSchool.setIndentationLeft(18f);
        spellCircleSchool.setMultipliedLeading(1.75f);

        Paragraph sourceKeu = new Paragraph(spellList.get(i).sourceKeu.toString() + "|~", f_keu);
        sourceKeu.setAlignment(ElementTags.ALIGN_RIGHT);
        sourceKeu.setIndentationRight(36f);
        sourceKeu.setMultipliedLeading(1f);

        Paragraph directionKeu = new Paragraph("", f_keu);
        directionKeu.setAlignment(ElementTags.ALIGN_RIGHT);
        directionKeu.setIndentationRight(90f);
        directionKeu.setMultipliedLeading(0.875f);

        Paragraph destinationKeu = new Paragraph(spellList.get(i).destinationKeu.toString() + "|~", f_keu);
        destinationKeu.setAlignment(ElementTags.ALIGN_RIGHT);
        destinationKeu.setIndentationRight(36f);
        destinationKeu.setMultipliedLeading(0.625f);

        Paragraph phraseCommon;
        Paragraph phraseSymbol;

        if (spellList.get(i).spellCircle != Circle.SEVENTH
                && spellList.get(i).spellCircle != Circle.PURE_SEVENTH) {
            phraseCommon = new Paragraph("", f_phraseCommon);
            phraseCommon.setSpacingAfter(27f);
            phraseSymbol = new Paragraph("", f_phraseSymbol);
            if ((i % 2) <= 0)
                phraseSymbol.setSpacingAfter(90f);
            else // ( (i % 2) > 0 )
                phraseSymbol.setSpacingAfter(0f);
        } else {
            phraseCommon = new Paragraph("", f_phraseCommonBreath);
            phraseCommon.setSpacingAfter(36f);
            phraseSymbol = new Paragraph("", f_phraseSymbolBreath);
            if ((i % 2) <= 0)
                phraseSymbol.setSpacingAfter(103.5f);
            else // ( (i % 2) > 0 )
                phraseSymbol.setSpacingAfter(0f);
        }

        phraseCommon.setAlignment(ElementTags.ALIGN_CENTER);
        phraseCommon.setMultipliedLeading(1.5f);
        for (AnothakScroll.Word w : spellList.get(i).liersethPhrase_Common)
            phraseCommon.add(w.toString() + " ");

        if (simpleMode) {
            phraseSymbol.setAlignment(ElementTags.ALIGN_CENTER);
            phraseSymbol.setSpacingBefore(36f);
            phraseSymbol.setSpacingAfter(0f);
            phraseSymbol.setMultipliedLeading(0.75f);
        } else // not simpleMode
        {
            phraseSymbol.setAlignment(ElementTags.ALIGN_CENTER);
            phraseSymbol.setMultipliedLeading(0.5f);
        }

        for (AnothakScroll.Symbol s : spellList.get(i).liersethPhrase_Symbol) {
            phraseSymbol.add(s.toString());
        }

        // Add content to the document
        try {
            if (simpleMode)
                doc_scrolls.add(phraseSymbol);
            else {
                Image tmpImage = null;
                tmpImage = spellList.get(i).backgroundImageFull;

                if (tmpImage != null) {
                    if ((i % 2) <= 0)
                        tmpImage.setAbsolutePosition(9f, 405f);
                    else // (i % 2) >= 0
                        tmpImage.setAbsolutePosition(9f, 9f);

                    doc_scrolls.add(tmpImage);
                }

                //doc_scrolls.add( Chunk.NEWLINE );
                doc_scrolls.add(spellCode);
                doc_scrolls.add(spellTitle);

                // Crap, I hate formatting
                MultiColumnText mct = new MultiColumnText(108f);
                mct.addRegularColumns(doc_scrolls.left(), doc_scrolls.right(), 54f, 2);
                mct.addElement(spellCircleSchool);
                mct.addElement(sourceKeu);
                mct.addElement(directionKeu);
                mct.addElement(destinationKeu);

                doc_scrolls.add(mct);

                doc_scrolls.add(new Chunk("\n", new Font(Font.FontFamily.COURIER, 18f, Font.NORMAL)));

                doc_scrolls.add(phraseCommon);
                doc_scrolls.add(phraseSymbol);

                if ((i % 2) > 0)
                    doc_scrolls.newPage();
            }

        } catch (Exception ex) {
            System.err.println(ex + "\nProgram closing.");
            System.exit(4);
        }
    }

    // Close the Document
    doc_scrolls.close();

    JOptionPane.showMessageDialog(null, doc_name + " was printed successfully!", "Print Status",
            JOptionPane.INFORMATION_MESSAGE);
}

From source file:be.kcbj.placemat.Placemat.java

License:Open Source License

private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException {
    int numLines = 0;
    Paragraph p = new Paragraph();

    if (sponsor.image != null) {
        Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image));
        if (sponsor.imageWidth != 0) {
            image.scaleToFit(sponsor.imageWidth, 1000);
        } else if (sponsor.imageHeight != 0) {
            image.scaleToFit(1000, sponsor.imageHeight);
        }//from  w  ww.  ja  va 2 s . co  m
        Chunk imageChunk = new Chunk(image, 0, 0, true);
        p.add(imageChunk);
    }

    if (sponsor.twoColumns) {
        StringBuilder sb = new StringBuilder();
        if (sponsor.name != null) {
            sb.append(sponsor.name);
        }
        if (sponsor.name2 != null) {
            if (sb.length() > 0) {
                sb.append(" - ");
            }
            sb.append(sponsor.name2);
        }
        if (sponsor.address != null) {
            if (sb.length() > 0) {
                sb.append(" - ");
            }
            sb.append(sponsor.address);
        }
        if (sponsor.address2 != null) {
            if (sb.length() > 0) {
                sb.append(" - ");
            }
            sb.append(sponsor.address2);
        }
        p.add(Chunk.NEWLINE);
        p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL)));
        numLines++;
    } else {
        if (sponsor.twoRows && sponsor.image != null) {
            p.add(Chunk.NEWLINE);
        }
        if (sponsor.name != null) {
            p.add(generateFittedChunk(sponsor.name, Font.BOLD));
            numLines++;
        }
        if (sponsor.name2 != null) {
            p.add(Chunk.NEWLINE);
            p.add(generateFittedChunk(sponsor.name2, Font.BOLD));
            numLines++;
        }
        if (sponsor.address != null) {
            p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL)));
            p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
            numLines++;
        }
        if (sponsor.address2 != null) {
            p.add(Chunk.NEWLINE);
            p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
            numLines++;
        }
    }
    p.setPaddingTop(0);
    p.setSpacingBefore(0);
    p.setAlignment(Element.ALIGN_CENTER);
    p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f);

    PdfPCell cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setFixedHeight(cellHeight);
    if (sponsor.twoColumns) {
        cell.setColspan(2);
    }
    if (sponsor.twoRows) {
        cell.setRowspan(2);
        if (sponsor.image == null) {
            p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f);
        }
    }
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setCellEvent(CELL_EVENT);
    cell.setPaddingBottom(4);
    cell.addElement(p);
    if (sponsor.isTodo()) {
        cell.setBackgroundColor(BaseColor.ORANGE);
    }

    return cell;
}

From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java

protected void printKeyData(SessionContainerWO sessionContainerWO) {
    try {// ww  w.  jav  a2 s. c o  m
        doc.add(new Paragraph(" "));
        table = new PdfPTable(15);
        table.setWidthPercentage(100);

        // kernel-data
        cell = new PdfPCell(new Paragraph(getTran("Web.Occup", "medwan.common.kernel-data").toUpperCase(),
                FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0),
                        Font.ITALIC)));
        cell.setColspan(15);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell);

        // row 1 : last-periodical-examination
        Paragraph par = new Paragraph(
                getTran("Web.Occup", "medwan.common.last-periodical-examination").toUpperCase() + "\n",
                FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0),
                        Font.ITALIC));
        TransactionVO tran = sessionContainerWO.getLastTransaction(IConstants_PREFIX + "TRANSACTION_TYPE_MER");
        ItemVO item;
        if (tran != null) {
            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_MER_EXAMINATION_DATE");
            if (item != null) {
                par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 8 * fontSizePercentage / 100.0), Font.BOLD)));
            }
        }
        cell = new PdfPCell(par);
        cell.setColspan(5);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(cell);

        // row 1 : next-periodical-examination
        par = new Paragraph(
                getTran("Web.Occup", "medwan.common.next-periodical-examination").toUpperCase() + "\n",
                FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0),
                        Font.ITALIC));
        if (sessionContainerWO.getFlags().getLastExaminationReport() != null && sessionContainerWO.getFlags()
                .getLastExaminationReport().getNewExaminationDueDate() != null) {
            par.add(new Chunk(
                    dateFormat.format(sessionContainerWO.getFlags().getLastExaminationReport()
                            .getNewExaminationDueDate()),
                    FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 8 * fontSizePercentage / 100.0), Font.BOLD)));
        }
        cell = new PdfPCell(par);
        cell.setColspan(5);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(cell);

        // row 1 : next-driver-examination / Volgend onderzoek medische schifting
        par = new Paragraph(getTran("Web.Occup", "medwan.common.next-driver-examination").toUpperCase() + "\n",
                FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0),
                        Font.ITALIC));
        if (sessionContainerWO.getFlags().getLastDrivingCertificate() != null) {

            // CBMT only : only display newExaminationDueDate if patient has riskcode "070" (drivinglicense)
            boolean riskCode070Found = false;

            if (riskCode070Found) {
                String newExamDueDateMinus = ScreenHelper.checkString(sessionContainerWO.getFlags()
                        .getLastDrivingCertificate().getNewExaminationDueDateMinus());
                if (newExamDueDateMinus.length() > 0) {
                    par.add(new Chunk(newExamDueDateMinus.replaceAll("-", "/"),
                            FontFactory.getFont(FontFactory.HELVETICA,
                                    Math.round((double) 8 * fontSizePercentage / 100.0), Font.BOLD)));
                }
            }
        } else {
            // no data available
            par.add(new Chunk(getTran("Web.Occup", "medwan.common.no-data"), FontFactory.getFont(
                    FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.BOLD)));
        }

        cell = new PdfPCell(par);
        cell.setColspan(5);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(cell);

        // row 2 : Biometrie
        par = new Paragraph(getTran("Web.Occup", "medwan.common.biometry").toUpperCase() + "\n",
                FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0),
                        Font.ITALIC));
        tran = sessionContainerWO.getLastTransactionTypeBiometry();
        if (tran != null) {
            // height
            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_BIOMETRY_HEIGHT");
            String sHeight = "", sWeight = "";
            if (item != null) {
                sHeight = item.getValue();
                par.add(new Chunk(getTran("Web.Occup", "medwan.common.length") + ": " + sHeight + " cm\n",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }

            // weight
            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_BIOMETRY_WEIGHT");
            if (item != null) {
                sWeight = item.getValue();
                par.add(new Chunk(getTran("Web.Occup", "medwan.common.weight") + ": " + sWeight + " kg\n",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }

            // BMI
            if (sWeight.length() > 0 && sHeight.length() > 0) {
                try {
                    DecimalFormat deci = new DecimalFormat("0.0");
                    Float bmi = new Float(Float.parseFloat(sWeight.replaceAll(",", ".")) * 10000
                            / (Float.parseFloat(sHeight.replaceAll(",", "."))
                                    * Float.parseFloat(sHeight.replaceAll(",", "."))));
                    par.add(new Chunk("BMI: " + deci.format(bmi), FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        cell = new PdfPCell(par);
        cell.setColspan(3);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(cell);

        // row 2 : Urineonderzoek
        par = new Paragraph("URINE\n", FontFactory.getFont(FontFactory.HELVETICA,
                Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC));
        tran = sessionContainerWO.getLastTransactionTypeUrineExamination();
        if (tran != null) {
            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_URINE_ALBUMINE");
            if (item != null) {
                par.add(new Chunk("Albumine: " + getTran("Web.Occup", item.getValue()) + "\n",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_URINE_GLUCOSE");
            if (item != null) {
                par.add(new Chunk("Glucose: " + getTran("Web.Occup", item.getValue()) + "\n",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_URINE_BLOOD");
            if (item != null) {
                par.add(new Chunk(
                        getTran("Web.Occup", "medwan.common.blood") + ": "
                                + getTran("Web.Occup", item.getValue()),
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
        }

        cell = new PdfPCell(par);
        cell.setColspan(3);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(cell);

        // row 2 : Audiometrie
        par = new Paragraph(getTran("Web.Occup", "medwan.common.audiometry").toUpperCase() + "\n",
                FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0),
                        Font.ITALIC));
        tran = sessionContainerWO.getLastTransactionTypeAudiometry();
        if (tran != null) {
            par.add(new Chunk(getTran("Web.Occup", "medwan.common.mean-hearing-loss").toUpperCase() + "\n",
                    FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 6 * fontSizePercentage / 100.0), Font.ITALIC)));
            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_AUDIOMETRY_RIGHT_LOSS");
            if (item != null) {
                par.add(new Chunk(
                        getTran("Web.Occup", "medwan.common.right") + ": -" + item.getValue() + " dB\n",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_AUDIOMETRY_LEFT_LOSS");
            if (item != null) {
                par.add(new Chunk(
                        getTran("Web.Occup", "medwan.common.left") + ": -" + item.getValue() + " dB\n",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
        }
        cell = new PdfPCell(par);
        cell.setColspan(3);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(cell);

        // row 2 : Visus
        par = new Paragraph(
                getTran("Web.Occup", "medwan.common.vision").toUpperCase() + " - "
                        + getTran("Web.Occup",
                                IConstants_PREFIX + "item_type_opthalmology_screen_visiotest_vision_far")
                                        .toUpperCase()
                        + "\n",
                FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0),
                        Font.ITALIC));
        tran = sessionContainerWO.getLastTransactionTypeOphtalmology();
        if (tran != null) {
            par.add(new Chunk(getTran("Web.Occup", "medwan.common.right-left-binocular").toUpperCase() + "\n",
                    FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 6 * fontSizePercentage / 100.0), Font.ITALIC)));
            par.add(new Chunk(getTran("Web.Occup", "medwan.common.without-correction") + ": ",
                    FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));

            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_OD_WITHOUT_GLASSES");
            if (item != null) {
                par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
            par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA,
                    Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));

            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_OG_WITHOUT_GLASSES");
            if (item != null) {
                par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
            par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA,
                    Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));

            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_BONI_WITHOUT_GLASSES");
            if (item != null) {
                par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
            par.add(new Chunk("\n" + getTran("Web.Occup", "medwan.common.with-correction") + ": ",
                    FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));

            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_OD_WITH_GLASSES");
            if (item != null) {
                par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
            par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA,
                    Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));

            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_OG_WITH_GLASSES");
            if (item != null) {
                par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
            par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA,
                    Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));

            item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_BONI_WITH_GLASSES");
            if (item != null) {
                par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
        }
        cell = new PdfPCell(par);
        cell.setColspan(3);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(cell);

        // row 2 : Bloeddruk
        par = new Paragraph(getTran("Web.Occup", "medwan.common.blood-pressure").toUpperCase() + "\n",
                FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0),
                        Font.ITALIC));
        tran = sessionContainerWO.getLastTransactionTypeGeneralClinicalExamination();
        if (tran != null) {
            // right
            ItemVO item1 = tran.getItem(
                    IConstants_PREFIX + "ITEM_TYPE_CARDIAL_CLINICAL_EXAMINATION_SYSTOLIC_PRESSURE_RIGHT");
            item = tran.getItem(
                    IConstants_PREFIX + "ITEM_TYPE_CARDIAL_CLINICAL_EXAMINATION_DIASTOLIC_PRESSURE_RIGHT");
            if (item1 != null || item != null) {
                par.add(new Chunk(getTran("Web.Occup", "medwan.common.right") + ": ",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
                if (item1 != null) {
                    par.add(new Chunk(item1.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
                }
                par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));
                if (item != null) {
                    par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
                }
                par.add(new Chunk(" mmHg\n", FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }

            // left
            item = tran.getItem(
                    IConstants_PREFIX + "ITEM_TYPE_CARDIAL_CLINICAL_EXAMINATION_SYSTOLIC_PRESSURE_LEFT");
            item1 = tran.getItem(
                    IConstants_PREFIX + "ITEM_TYPE_CARDIAL_CLINICAL_EXAMINATION_DIASTOLIC_PRESSURE_LEFT");
            if (item != null || item1 != null) {
                par.add(new Chunk(getTran("Web.Occup", "medwan.common.left") + ": ",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
                if (item != null) {
                    par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
                }
                par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));
                if (item1 != null) {
                    par.add(new Chunk(item1.getValue(), FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
                }
                par.add(new Chunk(" mmHg\n", FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
            }
        }

        cell = new PdfPCell(par);
        cell.setColspan(3);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(cell);

        doc.add(table);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

License:Open Source License

private PdfPCell createRow(String key, String value, String url) {
    final Paragraph paragraph = new Paragraph();
    paragraph.add(new Chunk(key, iTextUtil.getFontModelKey()));
    paragraph.add(new Chunk(": ", iTextUtil.getFontModelKey()));

    if (value == null) {
        value = "";
    }//w ww  .j  ava  2s.  c om

    final Phrase valuePhrase = processHtmlCodes(value.trim(), iTextUtil.getFontModelValue(),
            iTextUtil.getFontModelSymbol());
    if (!StringUtils.isEmpty(url)) {
        for (Chunk chunk : valuePhrase.getChunks()) {
            chunk.setAction(new PdfAction(url));
        }
    }
    for (Chunk chunk : valuePhrase.getChunks()) {
        chunk.setLineHeight(13f);
    }
    paragraph.add(valuePhrase);

    final PdfPCell cell = cell(paragraph);
    cell.setPaddingBottom(5f);
    return cell;
}

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 w w  w . jav  a  2 s  .  c om

        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();

    }

}