Example usage for com.itextpdf.text Phrase Phrase

List of usage examples for com.itextpdf.text Phrase Phrase

Introduction

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

Prototype

public Phrase(final float leading, final String string) 

Source Link

Document

Constructs a Phrase with a certain leading and a certain String.

Usage

From source file:client.welcome1.java

/**
 * insert single cells to the PDF file ad fills them with text 
 * @param table//w  w  w .ja  va  2 s . co  m
 * @param text
 * @param align
 * @param colspan
 * @param font 
 */
private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) {

    //create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));
    //set the cell alignment
    cell.setHorizontalAlignment(align);
    //set the cell column span in case you want to merge two or more cells
    cell.setColspan(colspan);
    //in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }
    //add the call to the table
    table.addCell(cell);

}

From source file:cn.afterturn.easypoi.pdf.export.PdfExportServer.java

License:Apache License

private void createHeaderRow(PdfExportParams entity, PdfPTable table, int feildLength) {
    PdfPCell iCell = new PdfPCell(new Phrase(entity.getTitle(), styler.getFont(null, entity.getTitle())));
    iCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    iCell.setVerticalAlignment(Element.ALIGN_CENTER);
    iCell.setFixedHeight(entity.getTitleHeight());
    iCell.setColspan(feildLength + 1);//  w  w  w  .  ja va2s  . co  m
    table.addCell(iCell);
    if (entity.getSecondTitle() != null) {
        iCell = new PdfPCell(
                new Phrase(entity.getSecondTitle(), styler.getFont(null, entity.getSecondTitle())));
        iCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        iCell.setVerticalAlignment(Element.ALIGN_CENTER);
        iCell.setFixedHeight(entity.getSecondTitleHeight());
        iCell.setColspan(feildLength + 1);
        table.addCell(iCell);
    }
}

From source file:cn.afterturn.easypoi.pdf.export.PdfExportServer.java

License:Apache License

private PdfPCell createStringCell(PdfPTable table, String text, ExcelExportEntity entity, int rowHeight,
        int colspan, int rowspan) {
    PdfPCell iCell = new PdfPCell(new Phrase(text, styler.getFont(entity, text)));
    styler.setCellStyler(iCell, entity, text);
    iCell.setFixedHeight((int) (rowHeight * 2.5));
    if (colspan > 1) {
        iCell.setColspan(colspan);//from   w  w w  .ja va  2s .  c  o  m
    }
    if (rowspan > 1) {
        iCell.setRowspan(rowspan);
    }
    table.addCell(iCell);
    return iCell;
}

From source file:cn.afterturn.easypoi.pdf.export.PdfExportServer.java

License:Apache License

private PdfPCell createStringCell(PdfPTable table, String text, ExcelExportEntity entity, int rowHeight) {
    PdfPCell iCell = new PdfPCell(new Phrase(text, styler.getFont(entity, text)));
    styler.setCellStyler(iCell, entity, text);
    iCell.setFixedHeight((int) (rowHeight * 2.5));
    table.addCell(iCell);/*from  w  w  w  . j  a va2s  .  c o m*/
    return iCell;
}

From source file:com.alokomkar.aliensonearth.report.AbstractPdfReport.java

public void addTableColumns(String[] cols, PdfPTable table) {

    if (cols != null) {

        for (String colName : cols) {

            PdfPCell cell = new PdfPCell(new Phrase(colName, smallerBoldFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidth(0.8f);/*from  www.  j ava2  s  .com*/
            table.addCell(cell);
        }
    }

}

From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java

private void addSignature(Document document) throws DocumentException, MalformedURLException, IOException {
    Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12f, Font.BOLD);
    Phrase p = new Phrase("" + getSpace(120) + "Signature", headerFont);
    document.add(p);//ww w.  j  av a  2s. c  o m
}

From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java

private void addCustomerDetails(Document document)
        throws DocumentException, MalformedURLException, IOException {
    Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD);
    Font shopNameFont = new Font(Font.FontFamily.TIMES_ROMAN, 18f, Font.BOLD);
    Font normalTextFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.NORMAL);
    Phrase p = null;/*from   w w w  .j av a2  s .com*/
    String customerName = "";
    String doctorName = "";
    String doctorAddr = "";
    String customerAddr = "";
    String billNo = "";
    String billDate = "";
    if (totalRecords != null && totalRecords.size() > 0) {
        for (InvoiceBean iBean : totalRecords) {
            if (iBean.getDoctorName() != null)
                doctorName = iBean.getDoctorName();
            if (iBean.getDoctorAddr1() != null)
                doctorAddr = iBean.getDoctorAddr1();
            customerName = iBean.getCustomerName();
            customerAddr = iBean.getCustomerAddr1();
            billNo = String.valueOf(iBean.getBillNo());
            billDate = iBean.getBillDate();
        }
        p = new Phrase("Bill No:" + billNo + getSpace(120), headerFont);
        document.add(p);
        p = new Phrase("Date:" + billDate + "\n", headerFont);
        document.add(p);
        addBlankLine(document);
        addImage(document);
        addBlankLine(document);
        String shopName = myaccountBean.getShopName();
        p = new Phrase(shopName, shopNameFont);
        document.add(p);
        addBlankLine(document);
        // Add store details
        String address = myaccountBean.getOwnerAddr1() + "," + myaccountBean.getOwnerAddr2() + ","
                + myaccountBean.getState() + ",PIN-" + myaccountBean.getPin();
        p = new Phrase("Shop No - " + myaccountBean.getShopNo() + "," + address, normalTextFont);
        document.add(p);

        String contactNo = myaccountBean.getMob1() + "/" + myaccountBean.getPhone1();
        p = new Phrase(",Contact:" + contactNo, normalTextFont);
        document.add(p);
        addBlankLine(document);

        p = new Phrase("Licence No:" + myaccountBean.getLicenceNo() + getSpace(20), normalTextFont);
        document.add(p);
        p = new Phrase("Baby Food Licence No:" + myaccountBean.getBabyFoodLcNo(), normalTextFont);
        document.add(p);
        addBlankLine(document);

        addEmptyLine(document, 25);
        p = new Phrase("Name:", headerFont);
        document.add(p);
        p = new Phrase(customerName + getSpace(5), normalTextFont);
        document.add(p);
        p = new Phrase("Address:", headerFont);
        document.add(p);
        p = new Phrase(customerAddr + "\n", normalTextFont);
        document.add(p);
        p = new Phrase("Doctor's Name:", headerFont);
        document.add(p);
        p = new Phrase(doctorName + getSpace(5), normalTextFont);
        document.add(p);
        p = new Phrase("Doctor's Address:", headerFont);
        document.add(p);
        p = new Phrase(doctorAddr, normalTextFont);
        document.add(p);
    }
}

From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java

private void createTable(Document document) throws DocumentException, MalformedURLException, IOException {

    PdfPTable table = new PdfPTable(8);
    table.setWidths(new int[] { 5, 10, 30, 15, 15, 15, 25, 20 });
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    //       addLogo(table);
    String[] headerTitle = { "Sl", "Qty", "Medicine Name", "Mfg Date", "Batch", "Exp Date", "Schedule",
            "Price" };
    Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD);
    for (String header : headerTitle) {
        Phrase p = new Phrase(header, headerFont);
        PdfPCell c1 = new PdfPCell(p);
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setLeading(0f, 1.5f);/* w ww.  j  a v a2s .co  m*/
        c1.setBackgroundColor(BaseColor.GRAY);
        table.addCell(c1);
    }

    Font contentFont = new Font(Font.FontFamily.TIMES_ROMAN, 9f);
    MedicineUtility mUtil = new MedicineUtility();
    //       table.setSpacingAfter(20);
    double vat = 0.0;
    double discount = 0.0;
    int count = 1;
    double totalAmt = 0.0;
    if (totalRecords != null && totalRecords.size() > 0) {
        for (InvoiceBean iBean : totalRecords) {
            //              replaceDoctor = iBean.getDoctorName();
            //              replaceCustomer = iBean.getCustomerName();
            //              replaceCustAddr1 = iBean.getCustomerAddr1();
            //              replaceBillNo = iBean.getBillNo();
            //              replaceBillDate = iBean.getPurchaseDate();
            vat = iBean.getVat();
            discount = iBean.getDiscount();
            PdfPCell c = new PdfPCell(new Phrase(count++ + "", contentFont));
            table.addCell(c);
            c = new PdfPCell(new Phrase(iBean.getSoldoutStock() + "", contentFont));
            table.addCell(c);
            table.addCell(new PdfPCell(new Phrase(iBean.getMedicineName(), contentFont)));
            table.addCell(new PdfPCell(new Phrase(iBean.getMfgDate(), contentFont)));
            table.addCell(new PdfPCell(new Phrase(iBean.getBatchName(), contentFont)));
            table.addCell(new PdfPCell(new Phrase(iBean.getExpDate(), contentFont)));
            table.addCell(new PdfPCell(new Phrase(iBean.getSchedule(), contentFont)));
            totalAmt = totalAmt + (iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice());
            table.addCell(new PdfPCell(new Phrase(
                    mUtil.getFormattedAmount((iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice())),
                    contentFont)));
        }
    }
    double grandTotal = 0.0;

    // Total
    PdfPCell c1 = new PdfPCell(new Phrase("Total"));
    c1.setColspan(7);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(totalAmt)));
    c1.setColspan(1);
    table.addCell(c1);

    // Vat
    c1 = new PdfPCell(new Phrase("Vat(" + vat + "%)"));
    c1.setColspan(7);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    double vatAmt = totalAmt * vat / 100;
    c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(vatAmt)));
    c1.setColspan(1);
    table.addCell(c1);

    // Discount
    c1 = new PdfPCell(new Phrase("Discount(" + discount + "%)"));
    c1.setColspan(7);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    double discountAmt = totalAmt * discount / 100;
    c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(discountAmt)));
    c1.setColspan(1);
    table.addCell(c1);

    // Grand Total
    c1 = new PdfPCell(new Phrase("Grand Total"));
    c1.setColspan(7);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    grandTotal = (totalAmt + vatAmt - discountAmt);
    c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(grandTotal)));
    c1.setColspan(1);
    table.addCell(c1);

    document.add(table);
}

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

License:Apache License

/**
 * header ? footer  /*from  w w w. j a va 2s  . c  o m*/
 */
public void onEndPage(PdfWriter writer, Document document) {

    if (titleFlag)
        return;

    Font font = new Font(bfKorean, 9);
    PdfPTable hTable = new PdfPTable(1);
    PdfPTable ftable = new PdfPTable(3);
    try {

        hTable.setWidths(new int[] { 100 });
        hTable.setTotalWidth(500);
        hTable.setLockedWidth(true);
        hTable.getDefaultCell().setFixedHeight(15);
        hTable.getDefaultCell().setBorder(Rectangle.BOTTOM);
        hTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        hTable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.header.title"), font));
        hTable.writeSelectedRows(0, -1, 50, 803, writer.getDirectContent());

        ftable.setWidths(new int[] { 100, 100, 100 });
        ftable.setTotalWidth(500);
        ftable.setLockedWidth(true);
        ftable.getDefaultCell().setBorder(Rectangle.TOP);
        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        ftable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.footer.left"), font));
        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        if (pagingFlag)
            ftable.addCell(new Phrase(
                    MessageUtil.getMessage("pdf.message.footer.center", String.valueOf(writer.getPageNumber())),
                    font));
        else
            ftable.addCell("");

        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        ftable.addCell(new Phrase(String.valueOf(new SimpleDateFormat("yyyy/MM/dd").format(new Date())), font));
        ftable.writeSelectedRows(0, -1, 50, 55, writer.getDirectContent());
    } catch (Exception de) {
        throw new ExceptionConverter(de);
    }
}

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

License:Apache License

/**
 * /*from  w w  w.jav  a2  s  .c  o  m*/
 * PDF Title Page 
 *
 * @param doc
 * @param writer
 */
public static void setTitleMainPage(Document doc, PdfWriter writer, PDFCommonEventHelper event, Upload upload)
        throws Exception {

    Font fnTitle = new Font(bfKorean, 20, Font.BOLD);
    Font fnLabel = new Font(bfKorean, 11, Font.BOLD);
    Font fnText = new Font(bfKorean, 11);
    LineSeparator UNDERLINE = new LineSeparator(1, 80, null, com.itextpdf.text.Element.ALIGN_CENTER, -5);
    doc.newPage();
    doc.add(Chunk.NEWLINE);

    event.setTitleFlag(true);

    int toc = writer.getPageNumber();
    Image img = Image.getInstance(PDFDocGenerator.class.getResource("/image/title.gif"));
    img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
    img.scalePercent(80, 80);
    doc.add(img);

    Paragraph titlePh = new Paragraph(MessageUtil.getMessage("pdf.message.main.title"), fnTitle);
    titlePh.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
    titlePh.setSpacingBefore(50);
    titlePh.setSpacingAfter(30);
    doc.add(titlePh);

    doc.add(UNDERLINE);

    PdfPTable t1 = new PdfPTable(2);
    t1.setSpacingBefore(20);
    t1.setWidths(new int[] { 110, 290 });
    t1.getDefaultCell().setBorder(0);
    t1.getDefaultCell().setFixedHeight(32);

    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_name"), fnLabel));
    t1.addCell(new Phrase(upload.getProjectNm(), fnText));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.department"), fnLabel));
    t1.addCell(new Phrase(upload.getDepartment(), fnText));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.focus_name"), fnLabel));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.focus_name"), fnText));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.product"), fnLabel));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.product", upload.getBeforeWas(),
            upload.getAfterWas()), fnText));
    doc.add(t1);

    doc.add(UNDERLINE);

    Paragraph executedPh = new Paragraph(MessageUtil.getMessage("pdf.message.main.label.executed"), fnLabel);
    executedPh.setSpacingBefore(30);
    executedPh.setSpacingAfter(15);
    executedPh.setIndentationLeft(50);
    doc.add(executedPh);

    PdfPTable t2 = new PdfPTable(2);
    t2.getDefaultCell().setFixedHeight(28);
    t2.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);

    t2.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217));
    t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.owner"), fnLabel));
    t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_role"), fnLabel));
    t2.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255));
    t2.addCell(new Phrase(upload.getPerson(), fnText));
    t2.addCell(new Phrase(upload.getOrgRole(), fnText));
    doc.add(t2);

    doc.newPage();
    int total = writer.reorderPages(null);

    int[] order = new int[total];
    for (int i = 0; i < total; i++) {
        order[i] = i + toc;
        if (order[i] > total)
            order[i] -= total;
    }
    // apply the new order
    writer.reorderPages(order);

}