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

private Phrase(final boolean dummy) 

Source Link

Document

Constructs a Phrase that can be used in the static getInstance() method.

Usage

From source file:alessandrafx.VentanaEgresoController.java

private void generarReporteOtroGasto(int cantidad, String motivo) throws DatoFaltante {
    try {/*w  ww.  j a v  a 2s .  com*/
        FileChooser fileChooser = new FileChooser();
        fileChooser.setInitialFileName("facturaHecha.pdf");
        File file = fileChooser.showSaveDialog(null);
        file.getParentFile().mkdir();

        Document document = new Document();
        try {
            try {
                PdfWriter.getInstance(document, new FileOutputStream(file));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }

        document.open();
        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date()));
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        //Agrega el monto pagado
        cell = new PdfPCell(new Phrase("Pago realizado"));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(String.valueOf(cantidad)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);

        //Agrega el motivo del pago
        cell = new PdfPCell(new Phrase("Motivo: \n" + motivo));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setColspan(3);
        table.addCell(cell);
        try {
            document.add(table);
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.close();

    } catch (Exception e) {
        throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida");
    }

}

From source file:alessandrafx.VentanaIngresoController.java

public void generarReportePago(String pagoSugerido, String pagoRealizado) throws DatoFaltante {

    try {/*from   w  ww.  j ava  2 s  . c  om*/
        FileChooser fileChooser = new FileChooser();
        fileChooser.setInitialFileName("facturaNueva.pdf");
        File file = fileChooser.showSaveDialog(null);
        file.getParentFile().mkdir();

        Document document = new Document();
        try {
            try {
                PdfWriter.getInstance(document, new FileOutputStream(file));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }

        document.open();
        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date()));
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        //Agrega el pago IDEAL
        cell = new PdfPCell(new Phrase("Pago sugerido recibido"));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(pagoSugerido));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);

        //Agrega el pago realizado
        cell = new PdfPCell(new Phrase("Pago realizado"));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(String.valueOf(pagoRealizado)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);
        try {
            document.add(table);
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.close();

    } catch (Exception e) {
        throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida");
    }
}

From source file:araword.classes.HeaderFooter.java

/**
 * Initialize one of the headers.//from  www  .j a v a2 s .com
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onOpenDocument(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
@Override
public void onOpenDocument(PdfWriter writer, Document document) {
    header[0] = new Phrase("Movie history");
    pagenumber = 1;
    System.out.println("ON OPEN PDF");
}

From source file:basiclayout.ReportFrame.java

public ReportFrame(DefaultTableModel subtotal_model, String st1_date, String e1_date)
        throws DocumentException, IOException {

    this();//from   w  w  w  .  ja  v  a2 s  . c  om
    report_model = (DefaultTableModel) reportTable.getModel();
    reportTable.setRowSelectionAllowed(true);
    reportTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    document = new Document();

    try {

        initialize_connection();

        PdfWriter.getInstance((com.itextpdf.text.Document) document,
                new FileOutputStream("C:\\Users\\jaina_000\\Desktop\\test.pdf"));
        document.open();

        table = new PdfPTable(5);
        table.setWidthPercentage(300 / 3f);
        table.setWidths(new int[] { 3, 3, 3, 3, 3 });

        PdfPCell cell;
        cell = new PdfPCell(new Phrase("Category"));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Title"));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Date"));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Amount"));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Details"));
        table.addCell(cell);

        cell.setRowspan(5);

        final_total = 0;

        for (int i = 0; i < subtotal_model.getRowCount(); i++) {

            String subt_cat = subtotal_model.getValueAt(i, 0).toString();

            resultset1 = statement1
                    .executeQuery("Select * from " + tableC + " WHERE CategoryName='" + subt_cat + "'");
            resultset1.next();

            resultset2 = statement2
                    .executeQuery("Select * from " + tableE + " WHERE CategoryId= '" + resultset1.getString(1)
                            + "' " + "AND (Date BETWEEN '" + st1_date + "' AND '" + e1_date + "')");

            sub_amt = 0;

            System.out.print("\n\nCategory: " + resultset1.getString(2));
            rep_row[0] = resultset1.getString(2);

            for (int z = 1; z < 5; z++) {
                rep_row[z] = null;
            }

            report_model.addRow(rep_row);

            table.addCell(new PdfPCell(new Phrase((String) rep_row[0])));
            table.addCell(new PdfPCell(new Phrase("")));
            table.addCell(new PdfPCell(new Phrase("")));
            table.addCell(new PdfPCell(new Phrase("")));
            table.addCell(new PdfPCell(new Phrase("")));

            cell.setRowspan(5);

            while (resultset2.next()) {

                rep_row[0] = null;
                System.out.print("\nTitle : " + resultset2.getString(5)); // Title
                rep_row[1] = resultset2.getString(5);

                System.out.print("\tDate : " + resultset2.getString(2)); // Date
                rep_row[2] = resultset2.getString(2);

                System.out.print("\tAmount: " + Math.abs(Integer.parseInt(resultset2.getString(4))));
                rep_row[3] = Math.abs(Integer.parseInt(resultset2.getString(4)));

                System.out.print("\tDescription : " + resultset2.getString(6)); // Description
                rep_row[4] = resultset2.getString(6);

                table.addCell(new PdfPCell(new Phrase((String) rep_row[0])));
                table.addCell(new PdfPCell(new Phrase((String) rep_row[1])));
                table.addCell(new PdfPCell(new Phrase((String) rep_row[2])));
                table.addCell(new PdfPCell(new Phrase(String.valueOf(rep_row[3]))));
                table.addCell(new PdfPCell(new Phrase((String) rep_row[4])));

                sub_amt += Integer.parseInt(resultset2.getString(4));

                report_model.addRow(rep_row);

                cell.setRowspan(5);
            }

            final_total += sub_amt;
            for (int z = 0; z < 5; z++) {
                rep_row[z] = null;
            }

            rep_row[2] = "Subtotal";
            rep_row[3] = Math.abs(sub_amt);
            System.out.println("\nCategory Subtotal : " + Math.abs(sub_amt));

            table.addCell(new PdfPCell(new Phrase((String) rep_row[0])));
            table.addCell(new PdfPCell(new Phrase((String) rep_row[1])));
            table.addCell(new PdfPCell(new Phrase((String) rep_row[2])));
            table.addCell(new PdfPCell(new Phrase(String.valueOf(rep_row[3]))));
            table.addCell(new PdfPCell(new Phrase((String) rep_row[4])));

            report_model.addRow(rep_row);

            cell.setRowspan(5);
        }

        for (int z = 0; z < 5; z++) {
            rep_row[z] = null;
        }
        report_model.addRow(rep_row);
        report_model.addRow(rep_row);

        System.out.print("\n\nFinal total: " + Math.abs(final_total));
        rep_row[2] = "Final Total";
        rep_row[3] = Math.abs(final_total);

        if (final_total < 0) {
            System.out.println("  (Expense)");
            rep_row[4] = "(Expense)";
        }

        else {
            System.out.println("  (Income)");
            rep_row[4] = "(Income)";
        }

        table.addCell(new PdfPCell(new Phrase((String) rep_row[0])));
        table.addCell(new PdfPCell(new Phrase((String) rep_row[1])));
        table.addCell(new PdfPCell(new Phrase((String) rep_row[2])));
        table.addCell(new PdfPCell(new Phrase(String.valueOf(rep_row[3]))));
        table.addCell(new PdfPCell(new Phrase((String) rep_row[4])));

        report_model.addRow(rep_row);

        cell.setRowspan(5);

    } catch (ClassNotFoundException | SQLException e) {

    } catch (FileNotFoundException ex) {
        Logger.getLogger(ReportFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    finally {

        close_connection();

    }

}

From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java

License:Open Source License

protected PdfPTable getBout(String player1, String player2) {
    PdfPTable table = new PdfPTable(2);
    table.setTotalWidth(configuration.getSquareCellSize() * 2);
    PdfPCell player1Name = new PdfPCell(new Phrase(player1));
    player1Name.setBorder(Rectangle.BOTTOM);
    player1Name.setHorizontalAlignment(Element.ALIGN_CENTER);
    player1Name.setFixedHeight(configuration.getSquareCellSize());
    PdfPCell player2Name = new PdfPCell(new Phrase(player2));
    player2Name.setBorder(Rectangle.BOTTOM);
    player2Name.setHorizontalAlignment(Element.ALIGN_CENTER);
    player2Name.setFixedHeight(configuration.getSquareCellSize());
    PdfPCell player1Score = new PdfPCell(new Phrase(" "));
    player1Score.setBorder(Rectangle.RIGHT);
    player1Score.setFixedHeight(configuration.getSquareCellSize());
    PdfPCell player2Score = new PdfPCell(new Phrase(" "));
    player2Score.setBorder(Rectangle.LEFT);
    player2Score.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(player1Name);/*from   ww w .  j av a2 s.  co m*/
    table.addCell(player2Name);
    table.addCell(player1Score);
    table.addCell(player2Score);
    table.setSpacingBefore(10);
    return table;
}

From source file:be.rheynaerde.poolsheets.AbstractPufPoolSheet.java

License:Open Source License

protected PdfPCell getNameCell(String text) {
    PdfPCell nameCell = text == null ? new PdfPCell() : new PdfPCell(new Phrase(text));
    nameCell.setBorder(Rectangle.BOTTOM);
    nameCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    nameCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    nameCell.setFixedHeight(configuration.getSquareCellSize());
    return nameCell;
}

From source file:be.rheynaerde.poolsheets.ClubPoolSheet.java

License:Open Source License

@Override
protected void buildTable(Document document) throws DocumentException {
    int columnCount = configuration.getNrOfPlayers() + configuration.getSummaryColumnCount() + 3;
    int nameCellWidth = 5;

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setTotalWidth(// www.  j a v  a  2 s  .c o m
            (configuration.getNrOfPlayers() + 1 + nameCellWidth + 0.1f + configuration.getSummaryColumnCount())
                    * configuration.getSquareCellSize());
    table.setLockedWidth(true);
    float[] widths = new float[columnCount];
    widths[0] = 1f * nameCellWidth;
    for (int i = 1; i < widths.length; i++) {
        widths[i] = 1f;
    }
    widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f;
    table.setWidths(widths);

    PdfPCell cell = new PdfPCell(new Paragraph(configuration.getTitle(), configuration.getTitleFont()));
    cell.setColspan(columnCount);
    cell.setPaddingBottom(configuration.getSquareCellSize() / 2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    {
        table.addCell(getHeaderCell(bundle.getString("name")));
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int i = 0; i < configuration.getSummaryColumnCount(); i++) {
            table.addCell(getHeaderCell(configuration.getSummaryColumnName(i)));
        }
    }

    for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
        table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1));
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < i; j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result));
            resultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(resultCell);
        }
        table.addCell(getSolidCell());
        for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result));
            resultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(resultCell);
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int j = 0; j < configuration.getSummaryColumnCount(); j++) {
            String result = configuration.getSummaryColumnValue(i + 1, j);
            PdfPCell summaryCell = new PdfPCell(new Phrase(result == null ? "" : result));
            summaryCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            summaryCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(summaryCell);
        }
    }

    document.add(table);
}

From source file:be.rheynaerde.poolsheets.StandardPoolSheet.java

License:Open Source License

protected void buildTable(Document document) throws DocumentException {
    int columnCount = 1 + 1 + configuration.getNrOfPlayers() + 1 + configuration.getSummaryColumnCount();
    // name + number + scores + spacer 
    //    + summary
    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);

    table.setTotalWidth((configuration.getNrOfPlayers() + 7 //the name column + extra space between grid and summary
                                                            //currently the name column just gets a width that is
                                                            //a multiple of the width of the other cells. Better
                                                            //would be to let this cell take up the remaining space.
            + configuration.getSummaryColumnCount()) * configuration.getSquareCellSize());
    table.setLockedWidth(true);//from ww  w .j  av a  2s.  com
    float[] widths = new float[columnCount];
    widths[0] = 5f;
    for (int i = 1; i < widths.length; i++) {
        widths[i] = 1f;
    }
    widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f;
    table.setWidths(widths);

    {
        table.addCell(getHeaderCell(bundle.getString("name")));
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int i = 0; i < configuration.getSummaryColumnCount(); i++) {
            table.addCell(getHeaderCell(configuration.getSummaryColumnName(i)));
        }
    }

    for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
        table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1));
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < i; j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }
        table.addCell(getSolidCell());
        for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int j = 0; j < configuration.getSummaryColumnCount(); j++) {
            String result = configuration.getSummaryColumnValue(i + 1, j);
            PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }
    }
    document.add(table);
}

From source file:be.rheynaerde.pufmanager.gui.workers.ExportFullPdfWorker.java

License:Open Source License

private void addPdfToDocument(ByteArrayOutputStream baos, PdfCopy copy, String stampText)
        throws IOException, BadPdfFormatException {
    PdfReader reader = new PdfReader(new ByteArrayInputStream(baos.toByteArray()));
    int n = reader.getNumberOfPages();
    for (int page = 1; page <= n; page++) {
        PdfImportedPage importedPage = copy.getImportedPage(reader, page);
        PdfCopy.PageStamp stamp = copy.createPageStamp(importedPage);
        Rectangle rectangle = importedPage.getBoundingBox();
        ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(stampText),
                rectangle.getRight() - 20f, rectangle.getTop() - 20f, 0);
        stamp.alterContents();/* w w  w. j  ava  2  s .  c o m*/
        copy.addPage(importedPage);
    }
}

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

License:Open Source License

private PdfPTable buildModelPricingTables(Contact contact, Model model) {

    final PdfPTable table = new PdfPTable(1);

    final List<Pricing> validPricings = model.validPricings(contact);

    if (CollectionUtils.isEmpty(validPricings)) {
        final Chunk chunk = new Chunk("Contact us for pricing on this model", iTextUtil.getFontContactUs());
        chunk.setAction(new PdfAction(contactUsUrl));
        table.addCell(cell(new Phrase(chunk)));
    } else {//from w  ww. j  a v a2s .  c om
        for (Pricing pricing : validPricings) {
            table.addCell(cell(buildModelPricingTable(pricing)));
        }
    }

    return table;

}