Java 类com.itextpdf.text.Phrase 实例源码

项目:NICON    文件:ExporOnlyViagemPdf.java   
private PdfPTable cellRodape(String value, boolean l,boolean r,int align)
{
    Font fontCorpoTableO= FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED ,7.5f);
    PdfPTable pTable = new PdfPTable(1);
    pTable.setWidthPercentage(100f);
    PdfPCell cellValue = new PdfPCell(new Phrase(value,fontCorpoTableO));
    if(l){cellValue.setBorderWidthLeft(0);}
    if(r){cellValue.setBorderWidthRight(0);}
   switch (align) 
   {
       case Element.ALIGN_RIGHT:cellValue.setHorizontalAlignment(Element.ALIGN_RIGHT);break;
       case Element.ALIGN_LEFT:cellValue.setHorizontalAlignment(Element.ALIGN_LEFT);break;
       case Element.ALIGN_CENTER:cellValue.setHorizontalAlignment(Element.ALIGN_CENTER);break;
       default:break;
   }
    pTable.addCell(cellValue);
    return pTable;
}
项目:NICON    文件:ExporOnlyViagemPdf.java   
private Phrase funcaoTitulo(int i) {
        String txt;
        Font fontcabecatable = new Font(Font.FontFamily.COURIER, 8, Font.BOLD);
       switch (i) 
       {
           case 0:txt="S/N";break;
           case 1:txt="DATA";break;
           case 2:txt="APOLICE";break;
           case 3:txt="DATA INICIO";break;
           case 4:txt="DATA FIM";break;
           case 5:txt="NO. DIAS";break;
           case 6:txt="NOME";break;
           case 7:txt="RECEIPT NO.";break;
           case 8:txt="EA PREM";break;
           case 9:txt="NICON COMISSÃO";break;
           case 10:txt="5% IMPOSTO";break;
           case 11:txt="0.60% SELO";break;
//           case 12:txt="NET OUT OF TAX";break;
           default:txt="TOTAL"/*"NET OUT OF TAX"*/;break;
       }

        Phrase rt = new Phrase(txt,fontcabecatable);
        return rt; 
    }
项目:NICON    文件:ExportMapaProducao__.java   
private Phrase funcaoTitulo(int i) {
    String txt;
    Font fontcabecatable =  FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED ,10f );
    switch (i)
    {
        case 0:txt="Nr. Factura";break;
        case 1:txt="Nome do Segurado"; break;
        case 2:txt="Prémio";break;
        case 3:txt="Imposto 6%";break;
        case 4:txt="Imposto 5%";break;
        case 5:txt="FGA 2.6%";break;
        default:txt="TOTAL";break;
    }

    a=com.itextpdf.text.Element.ALIGN_CENTER;
    Phrase rt = new Phrase(txt,fontcabecatable);
    return rt; 
}
项目:NICON    文件:ExporOnlyViagemPdf.java   
private Phrase funcaoTitulo(int i) {
        String txt;
        Font fontcabecatable = new Font(Font.FontFamily.COURIER, 8, Font.BOLD);
       switch (i) 
       {
           case 0:txt="S/N";break;
           case 1:txt="DATA";break;
           case 2:txt="APOLICE";break;
           case 3:txt="DATA INICIO";break;
           case 4:txt="DATA FIM";break;
           case 5:txt="NO. DIAS";break;
           case 6:txt="NOME";break;
           case 7:txt="RECEIPT NO.";break;
           case 8:txt="EA PREM";break;
           case 9:txt="NICON COMISSÃO";break;
           case 10:txt="5% IMPOSTO";break;
           case 11:txt="0.60% SELO";break;
//           case 12:txt="NET OUT OF TAX";break;
           default:txt="TOTAL"/*"NET OUT OF TAX"*/;break;
       }

        Phrase rt = new Phrase(txt,fontcabecatable);
        return rt; 
    }
项目:NICON    文件:ExporOnlyViagemPdf.java   
private PdfPTable cellRodape(String value, boolean l,boolean r,int align)
{
    Font fontCorpoTableO= FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED ,7.5f);
    PdfPTable pTable = new PdfPTable(1);
    pTable.setWidthPercentage(100f);
    PdfPCell cellValue = new PdfPCell(new Phrase(value,fontCorpoTableO));
    if(l){cellValue.setBorderWidthLeft(0);}
    if(r){cellValue.setBorderWidthRight(0);}
   switch (align) 
   {
       case Element.ALIGN_RIGHT:cellValue.setHorizontalAlignment(Element.ALIGN_RIGHT);break;
       case Element.ALIGN_LEFT:cellValue.setHorizontalAlignment(Element.ALIGN_LEFT);break;
       case Element.ALIGN_CENTER:cellValue.setHorizontalAlignment(Element.ALIGN_CENTER);break;
       default:break;
   }
    pTable.addCell(cellValue);
    return pTable;
}
项目:NICON    文件:ExportMapaProducao__.java   
private Phrase funcaoTitulo(int i) {
    String txt;
    Font fontcabecatable =  FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED ,10f );
    switch (i)
    {
        case 0:txt="Nr. Factura";break;
        case 1:txt="Nome do Segurado"; break;
        case 2:txt="Prémio";break;
        case 3:txt="Imposto 6%";break;
        case 4:txt="Imposto 5%";break;
        case 5:txt="FGA 2.6%";break;
        default:txt="TOTAL";break;
    }

    a=com.itextpdf.text.Element.ALIGN_CENTER;
    Phrase rt = new Phrase(txt,fontcabecatable);
    return rt; 
}
项目:ArasuiteIta    文件:HeaderFooter.java   
/**
      * Increase the page number.
      * @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(
      *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
      */
     @Override
public void onStartPage(PdfWriter writer, Document document) {
         pagenumber++;
         System.out.println("ON Start Page PDF");
Rectangle rect = writer.getBoxSize("art");

         /* header     
         ColumnText.showTextAligned(writer.getDirectContent(),                      
                    com.itextpdf.text.Element.ALIGN_RIGHT, header[0],
                     rect.getRight(), rect.getTop(), 0);
          */  
          Font font = new Font();
          font.setSize(8);
         if (G.licensePDF) {
          ColumnText.showTextAligned(writer.getDirectContent(),
                com.itextpdf.text.Element.ALIGN_CENTER, new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA")),font),
                  (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0);
          ColumnText.showTextAligned(writer.getDirectContent(),
                    com.itextpdf.text.Element.ALIGN_CENTER, new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA2")),font),
                      (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 9, 0);
         }


     }
项目:FOXopen    文件:MultiOptionSelectWidget.java   
private void addColumnItemContent(PDFSerialiser pSerialiser, LayoutFieldValueMappingItemColumn pColumnItem, boolean pHideField) {
  if (!pColumnItem.isFiller()) {
    Phrase lPhrase = pSerialiser.getElementFactory().getPhrase();
    FieldSelectOption lSelectOption = pColumnItem.getFieldSelectOption();

    pSerialiser.startContainer(ElementContainerFactory.getContainer(lPhrase));

    if (!pHideField) {
      String lFieldText = lSelectOption.isSelected() ? mSelectedFieldText : mDeselectedFieldText;
      pSerialiser.addText(lFieldText);
      lPhrase.getChunks().stream().findFirst().ifPresent(pFieldChunk -> pFieldChunk.setCharacterSpacing(FIELD_TEXT_SPACING));
    }

    pSerialiser.addText(lSelectOption.getDisplayKey());
    pSerialiser.endContainer();
    pSerialiser.add(lPhrase);
  }
}
项目:FOXopen    文件:PageNumberComponent.java   
@Override
public void buildComponent(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EPN pEvalNode) {
  if (pEvalNode.getClosestAncestor(EvaluatedHeaderFooterPresentationNode.class) == null) {
    throw new ExInternal("Page number output is only valid within a header or footer");
  }

  ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes();
  pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, PAGE_NUMBER_TAG,
                                             Collections.singletonList(pEvalNode.getClasses()),
                                             Collections.singletonList(pEvalNode.getStyles()));
  pSerialiser.pushElementAttributes(lElementAttributes);

  // Add a placeholder for the page number. The page number will be added as text to the phrase during header/footer
  // rendering. The current font selector is provided so that the page number text may be processed with all the
  // current font attributes later during rendering.
  Phrase lPageNumberPhrase = pSerialiser.getElementFactory().getPhrase();
  PageNumberPlaceholder lPageNumberPlaceholder = mPageNumberPlaceholderSupplier.getPlaceholder(lPageNumberPhrase,
                                                                                               pSerialiser.getFontSelector());
  pSerialiser.addPageNumberPlaceholder(lPageNumberPlaceholder);

  // The element itself is wrapped so that iText will not attempt to extract the chunks from the phrase and discard
  // the phrase itself - the element wrapper tells iText the type of the element is not one with chunks
  pSerialiser.add(new ElementWrapper(lPageNumberPhrase));
  pSerialiser.popElementAttributes();
}
项目:testarea-itext5    文件:StampUnicodeText.java   
/**
 * <a href="http://stackoverflow.com/questions/35082653/adobe-reader-cant-display-unicode-font-of-pdf-added-with-itext">
 * Adobe Reader can't display unicode font of pdf added with iText
 * </a>
 * <br/>
 * <a href="https://www.dropbox.com/s/erkv9wot9d460dg/sampleOriginal.pdf?dl=0">
 * sampleOriginal.pdf
 * </a>
 * <p>
 * Indeed, just like in the iTextSharp version of the code, the resulting file has
 * issues in Adobe Reader. With a different starting file, though, it doesn't, cf.
 * {@link #testAddUnicodeStampEg_01()}.
 * </p>
 * <p>
 * As it eventually turns out, Adobe Reader treats PDF files with composite fonts
 * differently if they claim to be PDF-1.2 like the OP's sample file.
 * </p>
 */
@Test
public void testAddUnicodeStampSampleOriginal() throws DocumentException, IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("sampleOriginal.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "sampleOriginal-unicodeStamp.pdf"))  )
    {
        PdfReader reader = new PdfReader(resource);
        PdfStamper stamper = new PdfStamper(reader, result);
        BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        PdfContentByte cb = stamper.getOverContent(1);

        Phrase p = new Phrase();
        p.setFont(new Font(bf, 25, Font.NORMAL, BaseColor.BLUE));
        p.add("Sample Text");

        ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_LEFT, p, 200, 200, 0);

        stamper.close();
    }
}
项目:testarea-itext5    文件:StampUnicodeText.java   
/**
 * <a href="http://stackoverflow.com/questions/35082653/adobe-reader-cant-display-unicode-font-of-pdf-added-with-itext">
 * Adobe Reader can't display unicode font of pdf added with iText
 * </a>
 * <br/>
 * <a href="https://www.dropbox.com/s/erkv9wot9d460dg/sampleOriginal.pdf?dl=0">
 * sampleOriginal.pdf
 * </a>
 * <p>
 * Indeed, just like in the iTextSharp version of the code, the resulting file has
 * issues in Adobe Reader, cf. {@link #testAddUnicodeStampSampleOriginal()}. With
 * a different starting file, though, it doesn't as this test shows.
 * </p>
 * <p>
 * As it eventually turns out, Adobe Reader treats PDF files with composite fonts
 * differently if they claim to be PDF-1.2 like the OP's sample file.
 * </p>
 */
@Test
public void testAddUnicodeStampEg_01() throws DocumentException, IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("eg_01.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "eg_01-unicodeStamp.pdf"))  )
    {
        PdfReader reader = new PdfReader(resource);
        PdfStamper stamper = new PdfStamper(reader, result);

        BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        PdfContentByte cb = stamper.getOverContent(1);

        Phrase p = new Phrase();
        p.setFont(new Font(bf, 25, Font.NORMAL, BaseColor.BLUE));
        p.add("Sample Text");

        ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_LEFT, p, 200, 200, 0);

        stamper.close();
    }
}
项目:testarea-itext5    文件:StampUnicodeText.java   
/**
 * <a href="http://stackoverflow.com/questions/35082653/adobe-reader-cant-display-unicode-font-of-pdf-added-with-itext">
 * Adobe Reader can't display unicode font of pdf added with iText
 * </a>
 * <p>
 * Indeed, just like in the iTextSharp version of the code, the resulting file has
 * issues in Adobe Reader, cf. {@link #testAddUnicodeStampSampleOriginal()}. With
 * a different starting file, though, it doesn't, cf.
 * {@link #testAddUnicodeStampEg_01()}. This test creates a new PDF with the same
 * font and chunk as stamped by the OP. Adobe Reader has no problem with it either.
 * </p>
 * <p>
 * As it eventually turns out, Adobe Reader treats PDF files with composite fonts
 * differently if they claim to be PDF-1.2 like the OP's sample file.
 * </p>
 */
@Test
public void testCreateUnicodePdf() throws DocumentException, IOException
{
    Document document = new Document();
    try (   OutputStream result  = new FileOutputStream(new File(RESULT_FOLDER, "unicodePdf.pdf")) )
    {
        PdfWriter.getInstance(document, result);
        BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

        document.open();

        Phrase p = new Phrase();
        p.setFont(new Font(bf, 25, Font.NORMAL, BaseColor.BLUE));
        p.add("Sample Text");

        document.add(p);

        document.close();
    }
}
项目:testarea-itext5    文件:UseColumnText.java   
/**
 * <a href="http://stackoverflow.com/questions/32162759/columntext-showtextaligned-vs-columntext-setsimplecolumn-top-alignment">
 * ColumnText.ShowTextAligned vs ColumnText.SetSimpleColumn Top Alignment
 * </a>
 * <p>
 * Indeed, the coordinates do not line up. The y coordinate of 
 * {@link ColumnText#showTextAligned(PdfContentByte, int, Phrase, float, float, float)}
 * denotes the baseline while {@link ColumnText#setSimpleColumn(Rectangle)} surrounds
 * the text to come.
 * </p>
 */
@Test
public void testShowTextAlignedVsSimpleColumnTopAlignment() throws DocumentException, IOException
{
    Document document = new Document(PageSize.A4);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "ColumnTextTopAligned.pdf")));
    document.open();

    Font fontQouteItems = new Font(BaseFont.createFont(), 12);
    PdfContentByte canvas = writer.getDirectContent();

    // Item Number
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("36222-0", fontQouteItems), 60, 450, 0);

    // Estimated Qty
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("47", fontQouteItems), 143, 450, 0);

    // Item Description
    ColumnText ct = new ColumnText(canvas); // Uses a simple column box to provide proper text wrapping
    ct.setSimpleColumn(new Rectangle(193, 070, 390, 450));
    ct.setText(new Phrase("In-Situ : Poly Cable - 100'\nPoly vented rugged black gable 100ft\nThis is an additional description. It can wrap an extra line if it needs to so this text is long.", fontQouteItems));
    ct.go();

    document.close();
}
项目:testarea-itext5    文件:DoubleSpace.java   
/**
 * <a href="http://stackoverflow.com/questions/35699167/double-space-not-being-preserved-in-pdf">
 * Double space not being preserved in PDF
 * </a>
 * <p>
 * Indeed, the double space collapses into a single one when copying&pasting from the
 * generated PDF displayed in Adobe Reader. On the other hand the gap for the double
 * space is twice as wide as for the single space. So this essentially is a quirk of
 * copy&paste of Adobe Reader (and some other PDF viewers, too).
 * </p>
 */
@Test
public void testDoubleSpace() throws DocumentException, IOException
{
    try (   OutputStream pdfStream = new FileOutputStream(new File(RESULT_FOLDER, "DoubleSpace.pdf")))
    {
        PdfPTable table = new PdfPTable(1);
        table.getDefaultCell().setBorderWidth(0.5f);
        table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY);

        table.addCell(new Phrase("SINGLE SPACED", new Font(BaseFont.createFont(), 36)));
        table.addCell(new Phrase("DOUBLE  SPACED", new Font(BaseFont.createFont(), 36)));
        table.addCell(new Phrase("TRIPLE   SPACED", new Font(BaseFont.createFont(), 36)));

        Document pdfDocument = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter.getInstance(pdfDocument, pdfStream);
        pdfDocument.open();
        pdfDocument.add(table);
        pdfDocument.close();
    }
}
项目:testarea-itext5    文件:UseRowspan.java   
/**
 * <a href="http://stackoverflow.com/questions/44005834/changing-rowspans">
 * Changing rowspans
 * </a>
 * <p>
 * Helper method of the OP.
 * </p>
 * @see #testUseRowspanLikeUser7968180()
 * @see #testUseRowspanLikeUser7968180Fixed()
 * @see #createPdf(String)
 * @see #createPdfFixed(String)
 */
private static void addCellToTableCzech(PdfPTable table, int horizontalAlignment,
        int verticalAlignment, String value, int colspan, int rowspan,
        String fontType, float fontSize) {
    BaseFont base = null;
    try {
        base = BaseFont.createFont(fontType, BaseFont.CP1250, BaseFont.EMBEDDED);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Font font = new Font(base, fontSize);
    PdfPCell cell = new PdfPCell(new Phrase(value, font));
    cell.setColspan(colspan);
    cell.setRowspan(rowspan);
    cell.setHorizontalAlignment(horizontalAlignment);
    cell.setVerticalAlignment(verticalAlignment);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);
}
项目:testarea-itext5    文件:ImportPageWithoutFreeSpace.java   
/**
 * This method creates a PDF with a single styled paragraph.
 */
static byte[] createSimpleTextPdf() throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();

    Paragraph paragraph = new Paragraph();
    paragraph.add(new Phrase("Beware: ", new Font(FontFamily.HELVETICA, 12, Font.BOLDITALIC)));
    paragraph.add(new Phrase("The implementation of ", new Font(FontFamily.HELVETICA, 12, Font.ITALIC)));
    paragraph.add(new Phrase("MarginFinder", new Font(FontFamily.COURIER, 12, Font.ITALIC)));
    paragraph.add(new Phrase(" is far from optimal. It is not even correct as it includes all curve control points which is too much. Furthermore it ignores stuff like line width or wedge types. It actually merely is a proof-of-concept.", new Font(FontFamily.HELVETICA, 12, Font.ITALIC)));
    document.add(paragraph);

    document.close();

    return baos.toByteArray();
}
项目:weplantaforest    文件:PdfReceiptView.java   
private void createReceiptHeaderAndTextBelow(PdfContentByte cb) throws DocumentException {
    PdfPTable headerTable = new PdfPTable(1);
    float[] rows = { 450f };
    headerTable.setTotalWidth(rows);
    headerTable.getDefaultCell()
               .setBorder(Rectangle.NO_BORDER);

    headerTable.addCell(new Phrase(new Chunk("Bestätigung über Geldzuwendungen", textFontForReceiptHeader)));

    headerTable.writeSelectedRows(0, 1, 75f, 625, cb);

    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(rows);
    table.getDefaultCell()
         .setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell()
         .setLeading(8f, 0);

    table.addCell(new Phrase(new Chunk("im Sinne des §10b des Einkommensteuergesetzes", textFont)));
    table.addCell(new Phrase(new Chunk("an eine der in §5 Abs. 1 Nr. 9 des Körperschaftsteuergesetzes bezeichneten", textFont)));
    table.addCell(new Phrase(new Chunk("Körperschaften, Personenvereinigungen oder Vermögensmassen", textFont)));

    table.writeSelectedRows(0, 3, 75f, 590, cb);
}
项目:weplantaforest    文件:PdfReceiptView.java   
private PdfPTable createPriceTable(PdfContentByte cb, Receipt receipt) throws DocumentException {
    PdfPTable tableForPrices = new PdfPTable(1);
    float[] rowForTotalPrice = { 250f };
    tableForPrices.setTotalWidth(rowForTotalPrice);
    tableForPrices.getDefaultCell()
                  .setBorder(Rectangle.NO_BORDER);

    tableForPrices.addCell(new Phrase(new Chunk("Betrag der Zuwendung in Ziffern:", textFont)));
    tableForPrices.addCell(new Phrase(new Chunk(" ", textFont)));
    Double totalPrice = 0.0;
    for (final Cart cart : receipt.getCarts()) {
        tableForPrices.addCell(new Phrase(new Chunk(cart.getTotalPrice()
                                                        .toString()
                + " €", textFontUserData)));
        totalPrice += cart.getTotalPrice()
                          .doubleValue();
    }
    String formattedPrice = priceFormat.format(totalPrice)
                                       .toString();
    tableForPrices.addCell(new Phrase(new Chunk("Gesamt: " + formattedPrice + " €", textFontUserData)));
    return tableForPrices;
}
项目:weplantaforest    文件:PdfReceiptView.java   
private PdfPTable createDateTable(PdfContentByte cb, Receipt receipt) throws DocumentException {
    PdfPTable tableForDate = new PdfPTable(1);
    float[] rowForDate = { 110f };
    tableForDate.setTotalWidth(rowForDate);
    tableForDate.getDefaultCell()
                .setBorder(Rectangle.NO_BORDER);

    tableForDate.addCell(new Phrase(new Chunk("Datum der Zuwendung:", textFont)));
    tableForDate.addCell(new Phrase(new Chunk(" ", textFont)));
    final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+2"), Locale.GERMAN);
    for (final Cart cart : receipt.getCarts()) {
        cal.setTimeInMillis(cart.getTimeStamp());
        final String date = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "." + cal.get(Calendar.YEAR);
        PdfPCell cell = new PdfPCell(new Phrase(new Chunk(date, textFontUserData)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setBorder(PdfPCell.NO_BORDER);
        tableForDate.addCell(cell);
    }
    return tableForDate;
}
项目:weplantaforest    文件:PdfReceiptView.java   
private PdfPTable createLawTable(PdfContentByte cb) throws DocumentException {
    PdfPTable table = new PdfPTable(1);
    float[] rows = { 445f };
    table.setTotalWidth(rows);
    table.getDefaultCell()
         .setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell()
         .setLeading(8f, 0);

    table.addCell(new Phrase(new Chunk("Es handelt sich nicht um den Verzicht auf Erstattung von Aufwendungen.", textFontLawText)));
    table.addCell(new Phrase(new Chunk("Die Gesellschaft ist wegen Förderung (begünstigter Zweck: Umweltschutz (§52 (2) S. 1 Nr.(n) 8 AO)) durch", textFontLawText)));
    table.addCell(new Phrase(new Chunk("Bescheinigung des Finanzamt Halle (Saale)-Nord, StNr. 110/108/91169, vom 19.11.2008 ab 01.01.2009", textFontLawText)));
    table.addCell(new Phrase(new Chunk("als gemeinnützig anerkannt. Letzter Freistellungsbescheid datiert auf den 20.06.2013.", textFontLawText)));
    table.addCell(new Phrase(new Chunk("Es wird bestätigt, dass die Zuwendung nur zur Förderung des Umweltschutzes verwendet wird.", textFontLawText)));

    PdfPCell emptyCell = new PdfPCell();
    emptyCell.setBorder(Rectangle.BOTTOM);
    emptyCell.setFixedHeight(15f);
    table.addCell(emptyCell);

    return table;
}
项目:weplantaforest    文件:PdfHelper.java   
public static void createCircleAndText(PdfContentByte cb, String text, float xCoord, float yCoord, float radius, Font textFont, int circleColorRed, int circleColorGreen, int circleColorBlue)
        throws DocumentException, IOException {
    cb.saveState();
    cb.setRGBColorFill(circleColorRed, circleColorGreen, circleColorBlue);
    cb.circle(xCoord, yCoord, radius);
    cb.fill();
    cb.stroke();
    cb.restoreState();

    PdfPTable table = new PdfPTable(1);
    float[] rows = { 595f };
    table.setTotalWidth(rows);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.getDefaultCell().setFixedHeight(radius * 2);
    table.addCell(new Phrase(new Chunk(text, textFont)));
    table.writeSelectedRows(0, 1, 0, yCoord + radius, cb);
}
项目:rolp    文件:LebPageHelper.java   
@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(2);
    table.setTotalWidth(527);
    table.setWidthPercentage(100);
    table.setLockedWidth(true);
    table.getDefaultCell().setFixedHeight(105f);
    table.getDefaultCell().setBorderWidth(0);
    table.addCell("");          
    table.addCell(csmLogoImage);
    table.writeSelectedRows(0, -1, 100, 840, writer.getDirectContent());
    ColumnText.showTextAligned(writer.getDirectContent(),
                   Element.ALIGN_LEFT, 
                   new Phrase(lebData.getSchuelername() + " " + lebData.getSchuljahr() + " " + lebData.getSchulhalbjahr().getId() + " Seite " + document.getPageNumber(), fusszeilenFont),
                   100, 75, 0);
}
项目:rolp    文件:PdfFormatHelper.java   
public static PdfPTable buildHeaderNameLine(String schuelername, Font headerFont) throws DocumentException {
    PdfPCell labelCell = new PdfPCell(new Phrase("Name", headerFont));
    labelCell.setBorder(Rectangle.BOTTOM);
    labelCell.setBorderWidth(1f);

    PdfPCell nameCell = new PdfPCell(new Phrase(schuelername, headerFont));
    nameCell.setBorder(Rectangle.BOTTOM);
    nameCell.setBorderWidth(1f);
    nameCell.setColspan(5);

    PdfPTable table = prebuildHeaderTable();
    table.addCell(labelCell);
    table.addCell(nameCell);

    return table;
}
项目:rolp    文件:PdfFormatHelper.java   
public static PdfPTable buildFooterVersetzungsvermerkLine(String versetzungsvermerk, Font footerFont) throws DocumentException {
    PdfPCell labelCell = new PdfPCell(new Phrase("Versetzungsvermerk", footerFont));
    labelCell.setBorder(Rectangle.BOTTOM);
    labelCell.setBorderWidth(1f);

    PdfPCell nameCell = new PdfPCell(new Phrase(versetzungsvermerk, footerFont));
    nameCell.setBorder(Rectangle.BOTTOM);
    nameCell.setBorderWidth(1f);

    PdfPTable table = new PdfPTable(2);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setWidthPercentage(100f);
    table.addCell(labelCell);
    table.addCell(nameCell);
    table.setWidths(new float[] {0.3f, 0.7f});
    return table;
}
项目:rolp    文件:PdfFormatHelper.java   
public static PdfPTable buildFooterDatumLine(String datumString, Font footerFont) throws DocumentException {
    PdfPCell labelCell = new PdfPCell(new Phrase("Datum", footerFont));
    labelCell.setBorder(Rectangle.BOTTOM);
    labelCell.setBorderWidth(1f);

    PdfPCell nameCell = new PdfPCell(new Phrase(datumString, footerFont));
    nameCell.setBorder(Rectangle.BOTTOM);
    nameCell.setBorderWidth(1f);

    PdfPTable table = new PdfPTable(2);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setWidthPercentage(100f);
    table.addCell(labelCell);
    table.addCell(nameCell);
    table.setWidths(new float[] {0.3f, 0.7f});
    return table;
}
项目:rolp    文件:PdfFormatHelper.java   
public static PdfPTable buildFooterDienstsiegelLine(Font footerFont) throws DocumentException {
    PdfPCell leftCell = new PdfPCell(new Phrase("", footerFont));
    leftCell.setBorder(Rectangle.NO_BORDER);
    leftCell.setBorderWidth(1f);

    PdfPCell centerCell = new PdfPCell(new Phrase("Dienstsiegel der Schule", footerFont));
    centerCell.setBorder(Rectangle.NO_BORDER);
    centerCell.setBorderWidth(1f);
    centerCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont));
    rightCell.setBorder(Rectangle.NO_BORDER);
    rightCell.setBorderWidth(1f);

    PdfPTable table = new PdfPTable(3);
    table.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.setWidthPercentage(100f);
    table.addCell(leftCell);
    table.addCell(centerCell);
    table.addCell(rightCell);
    table.setWidths(new float[] {0.3f, 0.3f, 0.3f});
    return table;
}
项目:rolp    文件:PdfFormatHelper.java   
public static PdfPTable buildFooterUnterschriftenLine(Font footerFont) throws DocumentException {
    PdfPCell leftCell = new PdfPCell(new Phrase("Schulleiter(in)", footerFont));
    leftCell.setBorder(Rectangle.TOP);
    leftCell.setBorderWidth(1f);
    leftCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont));
    centerCell.setBorder(Rectangle.TOP);
    centerCell.setBorderWidth(1f);
    centerCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell rightCell = new PdfPCell(new Phrase("Klassenleiter(in)", footerFont));
    rightCell.setBorder(Rectangle.TOP);
    rightCell.setBorderWidth(1f);
    rightCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100f);
    table.addCell(leftCell);
    table.addCell(centerCell);
    table.addCell(rightCell);
    table.setWidths(new float[] {0.3f, 0.3f, 0.3f});
    return table;
}
项目:rolp    文件:PdfFormatHelper.java   
public static PdfPTable buildFooterHalbjahrDatumLine(String datumString, Font footerFont) throws DocumentException {
    PdfPCell leftCell = new PdfPCell(new Phrase(datumString, footerFont));
    leftCell.setBorder(Rectangle.NO_BORDER);
    leftCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont));
    centerCell.setBorder(Rectangle.NO_BORDER);
    centerCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont));
    rightCell.setBorder(Rectangle.NO_BORDER);
    rightCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100f);
    table.addCell(leftCell);
    table.addCell(centerCell);
    table.addCell(rightCell);
    table.setWidths(new float[] {0.3f, 0.3f, 0.3f});
    return table;
}
项目:rolp    文件:PdfFormatHelper.java   
public static PdfPTable buildFooterHalbjahrDatumKlassenleiterLine(Font footerFont) throws DocumentException {
    PdfPCell leftCell = new PdfPCell(new Phrase("Datum", footerFont));
    leftCell.setBorder(Rectangle.TOP);
    leftCell.setBorderWidth(1f);
    leftCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont));
    centerCell.setBorder(Rectangle.TOP);
    centerCell.setBorderWidth(1f);
    centerCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell rightCell = new PdfPCell(new Phrase("Klassenleiter(in)", footerFont));
    rightCell.setBorder(Rectangle.TOP);
    rightCell.setBorderWidth(1f);
    rightCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100f);
    table.addCell(leftCell);
    table.addCell(centerCell);
    table.addCell(rightCell);
    table.setWidths(new float[] {0.3f, 0.3f, 0.3f});
    return table;
}
项目:gutenberg    文件:HeaderFooter.java   
public void drawFooter(PdfContentByte canvas, PageInfos pageInfos) {
    if (pageInfos.getRawPageNumber() == 1 && !footerOnFirstPage)
        return;

    if (drawLine) {
        BaseColor lineColor = styles.getColorOrDefault(HEADER_LINE_COLOR);
        canvas.saveState();
        canvas.setColorStroke(lineColor);
        canvas.setLineWidth(1.2f);
        canvas.moveTo(rect.getLeft(), rect.getBottom() - 6);
        canvas.lineTo(rect.getRight(), rect.getBottom() - 6);
        canvas.stroke();
        canvas.restoreState();
    }

    float bottom = rect.getBottom() - 20;
    Phrase footer = footerText(pageInfos);
    if (footer != null) {
        showTextAligned(canvas, Element.ALIGN_LEFT, footer, rect.getLeft(), bottom, 0);
    }

    Font footerFont = styles.getFontOrDefault(FOOTER_FONT);

    Phrase page = new Phrase(pageInfos.getFormattedPageNumber(), footerFont);
    showTextAligned(canvas, Element.ALIGN_RIGHT, page, rect.getRight(), bottom, 0);
}
项目:gutenberg    文件:TableCellNodeProcessor.java   
@SuppressWarnings("unchecked")
@Override
public void process(int level, Node node, InvocationContext context) {
    TreeNavigation nav = context.treeNavigation();
    boolean isHeaderCell = nav.ancestorTreeMatches(TableCellNode.class, TableRowNode.class, TableHeaderNode.class);

    CellStyler cellStyler = context.peekCellStyler();
    context.pushFont(cellStyler.cellFont());
    List<Element> elements = context.collectChildren(level, node);
    context.popFont();

    Phrase phrase = new Phrase();
    phrase.addAll(elements);

    int colspan = ((TableCellNode) node).getColSpan();

    PdfPCell cell = isHeaderCell ? headerCell(phrase) : new PdfPCell(phrase);
    cell.setColspan(colspan);
    cellStyler.applyStyle(cell);

    context.append(cell);
}
项目:gutenberg    文件:ExpLinkNodeProcessor.java   
@Override
public void process(int level, Node node, InvocationContext context) {
    ExpLinkNode linkNode = (ExpLinkNode) node;
    String url = context.variableResolver().resolve(linkNode.url);

    Font anchorFont = new FontCopier(context.peekFont())
            .style(Font.UNDERLINE)
            .color(Colors.DARK_RED)
            .get();

    context.pushFont(anchorFont);
    List<Element> subs = context.collectChildren(level, node);
    context.popFont();

    Phrase p = new Phrase();
    p.addAll(subs);

    Anchor anchor = new Anchor(p);
    anchor.setReference(url);
    context.append(anchor);
}
项目:gutenberg    文件:FontawesomePdfTest.java   
private File generateAwesomeFontPdf() throws DocumentException, IOException {
    File fileOut = openDocument("awesomeFont");

    BaseFont bf = BaseFont.createFont("font/FontAwesome.otf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font font = new Font(bf, 12);
    FontAwesome awesome = FontAwesome.getInstance();

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(288 / 5.23f);
    table.setWidths(new int[]{2, 1});
    for (String key : awesome.keys().toSortedList(stringComparator())) {
        table.addCell(new PdfPCell(new Phrase(key)));
        table.addCell(new PdfPCell(new Phrase(awesome.get(key), font)));
    }
    document.add(table);
    closeDocument();
    return fileOut;
}
项目:Create-PDF-in-Java-    文件:createPDF.java   
/**
 * Insert New row to the table
 *
 * @param table
 * @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);
}
项目:cucumber-contrib    文件:GrammarPdfReport.java   
private void emitMethodSummary(final PdfPTable summaryTable, MethodEntry methodEntry) {
    log.debug("Emitting summary for method {}", methodEntry.signature());

    methodEntry.patterns().forEach(new Consumer<String>() {
        @Override
        public void accept(String pattern) {
            Phrase phrase = new Phrase(pattern, FontFactory.getFont("Arial", 10, BLACK));
            PdfPCell patternCell = new PdfPCell(phrase);
            patternCell.setColspan(SUMMARY_NB_COLS - 2);
            patternCell.setBorder(Rectangle.BOTTOM);
            patternCell.setBorderColor(BaseColor.LIGHT_GRAY);

            summaryTable.addCell(emptyCell(2));
            summaryTable.addCell(patternCell);
        }
    });
}
项目:iTextTutorial    文件:T03_Phrase.java   
public void createPdf(String filename) throws DocumentException, IOException {

        Document document = new Document(PageSize.LETTER);
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();

        // step 4 - add content into document
        for (int i = 0; i < 5; i++) {
            document.add(new Phrase("Hello", new Font(FontFamily.HELVETICA, 32, Font.BOLD)));
            document.add(new Phrase("World", new Font(FontFamily.COURIER, 40, Font.ITALIC)));
            document.add(new Phrase("!!!", new Font(FontFamily.TIMES_ROMAN, 40)));

            document.add(Chunk.NEWLINE);
        }

        document.close();
    }
项目:iTextTutorial    文件:T11_ColumnText.java   
public void createPdf(String filename) throws DocumentException, IOException {

        Document document = new Document(PageSize.LETTER);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();

        // TODO: 1. get direct content
        PdfContentByte canvas = writer.getDirectContent();

        Font font = new Font(FontFamily.HELVETICA, 18, Font.BOLD, BaseColor.ORANGE);
        Phrase headerText = new Phrase("PSEG DP&C", font);
        int alignLeft = Element.ALIGN_LEFT;
        float right = document.getPageSize().getRight();
        float top = document.getPageSize().getTop();

        // TODO: 2. use ColumnText
        ColumnText.showTextAligned(canvas, alignLeft, headerText, right - 180, top - 36, 0);

        document.close();
    }
项目:fll-sw    文件:FinalComputedScores.java   
private PdfPTable createHeader(final String challengeTitle,
                               final String tournamentName,
                               final String division) {
  // initialization of the header table
  final PdfPTable header = new PdfPTable(2);

  final Phrase p = new Phrase();
  p.add(new Chunk(challengeTitle, TIMES_12PT_NORMAL));
  p.add(Chunk.NEWLINE);
  p.add(new Chunk("Final Computed Scores", TIMES_12PT_NORMAL));
  header.getDefaultCell().setBorderWidth(0);
  header.addCell(p);
  header.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);

  final Phrase p2 = new Phrase();
  p2.add(new Chunk("Tournament: "
      + tournamentName, TIMES_12PT_NORMAL));
  p2.add(Chunk.NEWLINE);
  p2.add(new Chunk("Award Group: "
      + division, TIMES_12PT_NORMAL));
  header.addCell(p2);

  return header;
}
项目:txt2pdf    文件:PdfUtils.java   
public void addTitle() throws DocumentException {

        Paragraph title = new Paragraph();
        title.setAlignment(1);
        title.setFont(new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD,
                BaseColor.RED));
        title.add(new Phrase("Java Assignment"));
        document.add(title);

        addEmptyLine(title, 2);

        Paragraph name = new Paragraph();
        name.setAlignment(0);
        name.setFont(new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD,
                BaseColor.GRAY));
        name.add(new Phrase("  Name     : " + FileUtil.name + "\n"));
        name.add(new Phrase("  Enrollno : " + FileUtil.rollno
                + "\n\n"));
        document.add(name);

        addEmptyLine(title, 2);
    }
项目:IMSQTI2PDF    文件:HeaderFooter.java   
public HeaderFooter(int maximumPageNumber)
{
    _maximumPageNumber = maximumPageNumber;

    Chunk c = new Chunk("" + (char) 229);
    c.setFont(new Font(FontFamily.SYMBOL, 28));
    _sumSymbol = new Phrase(c);
}