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:de.alpharogroup.swing.img.ImageExtensions.java

License:Open Source License

/**
 * Factory method for create a new {@link PdfPTable} with the given count of columns and the
 * column header names//  w w w .ja v a  2 s.  c om
 *
 * @param numColumns
 *            the count of columns of the table
 * @param headerNames
 *            the column header names
 * @return the new {@link PdfPTable}
 */
public static PdfPTable newPdfPTable(int numColumns, List<String> headerNames) {
    PdfPTable table = new PdfPTable(numColumns);
    headerNames.stream().forEach(columnHeaderName -> {
        PdfPCell header = new PdfPCell();
        header.setBackgroundColor(BaseColor.LIGHT_GRAY);
        header.setBorderWidth(2);
        header.setPhrase(new Phrase(columnHeaderName));
        table.addCell(header);
    });
    return table;
}

From source file:de.aw.awlib.pdf.PDFDocument.java

License:Open Source License

/**
 * Erstellt eine Tabelle im pdf//from   w w w  . j a va  2  s  .co  m
 *
 * @param columnHeaders
 *         Header der Tabellenspalten
 * @param rowCount
 *         Anzahl der Tabellenzeilen
 * @throws DocumentException
 *         wenn das Document nicht erstellt werden kann.
 */
public void createTable(@NonNull String[] columnHeaders, @Nullable String summary, int rowCount,
        CellCreator creator) throws DocumentException {
    if (summary != null) {
        addTableTitle(summary);
    }
    PdfPTable table = new PdfPTable(columnHeaders.length);
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    for (String columnHeader : columnHeaders) {
        PdfPCell c1 = new PdfPCell(new Phrase(columnHeader));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }
    table.setHeaderRows(1);
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnHeaders.length; column++) {
            table.addCell(creator.getCellContent(row, column));
        }
    }
    mDocument.add(table);
}

From source file:de.aw.awlib.pdf.PDFDocument.java

License:Open Source License

/**
 * Erstellt eine Tabelle im pdf//  w w w . ja va  2 s  .c  o  m
 *
 * @param columnHeaders
 *         Header der Tabellenspalten
 * @param cellcontent
 *         Inhalte der Tabellenzeilen
 * @throws DocumentException
 *         wenn das Document nicht erstellt werden kann.
 */
public void createTable(@NonNull String[] columnHeaders, @NonNull List<List<String>> cellcontent)
        throws DocumentException {
    PdfPTable table = new PdfPTable(columnHeaders.length);
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    for (String columnHeader : columnHeaders) {
        PdfPCell c1 = new PdfPCell(new Phrase(columnHeader));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }
    table.setHeaderRows(1);
    for (List<String> cells : cellcontent) {
        for (String cell : cells) {
            table.addCell(cell);
        }
    }
    mDocument.add(table);
}

From source file:de.aw.awlib.pdf.PDFDocument.java

License:Open Source License

/**
 * Erstellt eine Tabelle im pdf/*  w w w .  j  av  a  2 s .c  o m*/
 *
 * @param columnHeaders
 *         Header der Tabellenspalten
 * @param cellcontent
 *         Inhalte der Tabellenzeilen
 * @throws DocumentException
 *         wenn das Document nicht erstellt werden kann.
 */
public void createTable(@NonNull String[] columnHeaders, @Nullable String summary,
        @NonNull String[][] cellcontent) throws DocumentException {
    if (summary != null) {
        addTableTitle(summary);
    }
    PdfPTable table = new PdfPTable(columnHeaders.length);
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    for (String columnHeader : columnHeaders) {
        PdfPCell c1 = new PdfPCell(new Phrase(columnHeader));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }
    table.setHeaderRows(1);
    for (String[] cells : cellcontent) {
        for (String cell : cells) {
            table.addCell(cell);
        }
    }
    mDocument.add(table);
}

From source file:de.drippinger.cytricHelper.CytricHelper.java

License:Open Source License

public void manipulatePdf(String sourceFile, String expenseID) throws IOException, DocumentException {
    PdfReader reader = new PdfReader(sourceFile);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(getOutputName(sourceFile)));

    PdfContentByte over = stamper.getOverContent(1);
    Phrase p = new Phrase(String.format("Cytric ID: %s", expenseID));
    ColumnText.showTextAligned(over, Element.ALIGN_CENTER, p, 500, reader.getPageSize(1).getHeight() - 30, 0);
    over.saveState();//w  ww .j a v a  2 s. c  om

    stamper.close();
    reader.close();
}

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

/**
 * Erzeugt das Inhaltsverzeichnis aus den bereits vorhandenen Elementen in
 * der Liste <code>listEntries</code>.
 * /*  ww w .j ava  2  s . co m*/
 * @param docPdf
 *            Zieldokument, falls Inhaltsverzeichnis nicht temporr erzeugt
 *            wird
 * @param temp
 *            Gibt an, ob das Inhaltsverzeichnis temporr in einer neuen
 *            Datei/Dokument erzeugt werden soll
 * @return Anzahl der Seiten
 * @throws DocumentException
 * @throws IOException
 */
private int erzeugeInhaltsverzeichnis(Document docPdf, boolean temp) throws DocumentException, IOException {

    int anzPages = 0;
    Document docInhalt = docPdf;
    String filePathTempInhaltString = "";

    if (temp) {
        // temp. Dateinamen bestimmen
        File fileDokuFile = new File(dateiname);
        filePathTempInhaltString = fileDokuFile.getParent() + "/tmp_inhalt.pdf";
        // Neues Dokument erzeugen
        docInhalt = initPdfWriterAndDocument(filePathTempInhaltString, false);
    }

    // berschrift
    Chapter currChapter = new Chapter(getParagraphChapter("Inhaltsverzeichnis"), 0);
    // 0, damit keine Nummerierung
    currChapter.setNumberDepth(0);
    docInhalt.add(currChapter);
    // eine Zeile Abstand
    docInhalt.add(getEmptyLineTextHalf());

    for (ContPdfEntry currEntry : listEntries) {

        // Eintrag erzeugen inkl. Abstand
        String strEintrag = currEntry.getBezeichnung() + "  ";
        Chunk chunkBezeichnung;
        Chunk chunkSeitenzahlChunk;
        if (currEntry.getParentEntry() == null) {
            // 1. Ebene => fett, Abstand davor einfgen
            docInhalt.add(getEmptyLineTextHalf());
            chunkBezeichnung = getChunkTextBold(strEintrag);
            chunkSeitenzahlChunk = getChunkTextBold("" + currEntry.getPageNumber());
        } else {
            // 2. Ebene
            chunkBezeichnung = getChunkText(strEintrag);
            chunkSeitenzahlChunk = getChunkText("" + currEntry.getPageNumber());
        }
        // Referenz setzen
        chunkBezeichnung.setLocalGoto(currEntry.getDestination());
        chunkSeitenzahlChunk.setLocalGoto(currEntry.getDestination());
        // Abstandzeichen generieren, Breite auffllen
        float widthAbstand = docInhalt.getPageSize().getWidth() * 0.81f;
        ;
        while (chunkBezeichnung.getWidthPoint() <= widthAbstand) {
            chunkBezeichnung.append(".");
        }

        // Tabelle erzeugen und formatieren
        PdfPTable currTable = new PdfPTable(2);
        currTable.setWidthPercentage(100f);
        currTable.setWidths(new int[] { 96, 4 });

        // Inhalte einfgen
        // Zelle Bezeichnung
        PdfPCell currCellBezeichnung = new PdfPCell(new Phrase(chunkBezeichnung));
        currCellBezeichnung.setBorder(0);
        currCellBezeichnung.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);

        // Zelle Seitennummer
        PdfPCell currCellPageNumberCell = new PdfPCell(new Phrase(chunkSeitenzahlChunk));
        currCellPageNumberCell.setBorder(0);
        currCellPageNumberCell.setHorizontalAlignment(Element.ALIGN_RIGHT);

        // Zellen zur Tabelle hinzufgen
        currTable.addCell(currCellBezeichnung);
        currTable.addCell(currCellPageNumberCell);

        docInhalt.add(currTable);
    }

    if (temp) {
        // Dokument schlieen
        docInhalt.close();

        // Anzahl der Seitenzahlen bestimmen
        PdfReader reader = new PdfReader(filePathTempInhaltString);
        anzPages = reader.getNumberOfPages();
        reader.close();

        // temp. Datei lschen
        File currFileInhaltFile = new File(filePathTempInhaltString);
        currFileInhaltFile.delete();
    }
    return anzPages;
}

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

/**
 * Erzeugt eine Zelle der Tabelle.//  w  w w  .ja  v  a  2  s . co m
 * 
 * @param text
 *          der anzuzeigende Text.
 * @param align
 *          die Ausrichtung.
 * @param backgroundcolor
 *          die Hintergundfarbe.
 * @return die erzeugte Zelle.
 */
private PdfPCell getDetailCell(String text, int align, BaseColor backgroundcolor, boolean silbentrennung) {
    PdfPCell cell = null;
    if (silbentrennung) {
        cell = new PdfPCell(new Phrase(new Chunk(notNull(text), getFreeSans(8)).setHyphenation(hyph)));
    } else {
        cell = new PdfPCell(new Phrase(new Chunk(notNull(text), getFreeSans(8))));
    }
    cell.setHorizontalAlignment(align);
    cell.setBackgroundColor(backgroundcolor);
    return cell;
}

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

private PdfPCell getDetailCell(String text, int align, BaseColor backgroundcolor, int colspan) {
    PdfPCell cell = new PdfPCell(new Phrase(new Chunk(notNull(text), getFreeSans(8)).setHyphenation(hyph)));
    cell.setHorizontalAlignment(align);/*from  w  ww .  j  av  a  2  s  .  com*/
    cell.setBackgroundColor(backgroundcolor);
    cell.setColspan(colspan);
    return cell;
}

From source file:digiho.DigiHoInitial1.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:

    jDate1.setText("");
    Calendar timer = Calendar.getInstance();
    timer.getTime();/*from  w w  w  .  j  a v  a  2 s.c  om*/
    SimpleDateFormat Tdate = new SimpleDateFormat("dd-MMM-yyy");
    jDate1.setText(Tdate.format(timer.getTime()));
    Document doc = new Document();
    try {
        PdfWriter.getInstance(doc,
                new FileOutputStream("f:\\DiGiho\\Complaint From\\" + jCustomer1.getText() + ".pdf"));
        doc.open();
        doc.add(new Paragraph("\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY)));
        doc.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n"));
        doc.add(new Phrase("Customer ID.:         "));
        doc.add(new Phrase(jCustomer1.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("                                                    Date:          "
                + jDate1.getText() + "   \n\n"));
        doc.add(new Phrase("Name:                   "));
        doc.add(new Phrase(jName1.getText() + ". " + jName2.getText() + " " + jName3.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nFather's Name:     "));
        doc.add(new Phrase(jFatherName1.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nAddress:                "));
        doc.add(new Phrase(jAddress1.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nBlock:                    "));
        doc.add(new Phrase(jBlock1.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));

        doc.add(new Phrase("\nCity:                       "));
        doc.add(new Phrase(jCity1.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nDistrict:                  "));
        doc.add(new Phrase(jDistrict1.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nMoblie No.:           "));
        doc.add(new Phrase(jMobile1.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));

        doc.add(new Paragraph("\n\n\n\n\n\n"));
        doc.add(new Paragraph("        (1)  " + jTextField2.getText()));
        doc.add(new Paragraph("        (2)  " + jcomplain1.getText()));
        doc.add(new Paragraph("        (3)  " + jcomplain3.getText()));
        doc.add(new Paragraph("        (4)  " + jcomplain4.getText()));
        doc.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DigiHoInitial1.class.getName()).log(Level.SEVERE, null, ex);
    }
    JOptionPane.showMessageDialog(null, "File has been created", "deeps message", JOptionPane.WARNING_MESSAGE);
}

From source file:DomainToolCore.Report.PDFSubDomains.java

License:Open Source License

private static void createTable(Document document) throws BadElementException, DocumentException {
    PdfPTable table = new PdfPTable(2);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("SubDomain"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);/*  ww  w  .j  a  va  2 s . c o m*/

    c1 = new PdfPCell(new Phrase("IP Address"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    table.setHeaderRows(1);

    for (int i = 0; i < subd.size(); i++) {
        table.addCell((String) subd.elementAt(i));
        table.addCell((String) ip.elementAt(i));
    }
    document.add(table);

}