本文整理匯總了Java中com.itextpdf.text.Phrase類的典型用法代碼示例。如果您正苦於以下問題:Java Phrase類的具體用法?Java Phrase怎麽用?Java Phrase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Phrase類屬於com.itextpdf.text包,在下文中一共展示了Phrase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cellRodape
import com.itextpdf.text.Phrase; //導入依賴的package包/類
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;
}
示例2: onEndPage
import com.itextpdf.text.Phrase; //導入依賴的package包/類
@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);
}
示例3: funcaoTitulo
import com.itextpdf.text.Phrase; //導入依賴的package包/類
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;
}
示例4: testShowTextAlignedVsSimpleColumnTopAlignment
import com.itextpdf.text.Phrase; //導入依賴的package包/類
/**
* <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();
}
示例5: createLawTable
import com.itextpdf.text.Phrase; //導入依賴的package包/類
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;
}
示例6: funcaoTitulo
import com.itextpdf.text.Phrase; //導入依賴的package包/類
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;
}
示例7: onStartPage
import com.itextpdf.text.Phrase; //導入依賴的package包/類
/**
* 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);
}
}
示例8: addColumnItemContent
import com.itextpdf.text.Phrase; //導入依賴的package包/類
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);
}
}
示例9: buildComponent
import com.itextpdf.text.Phrase; //導入依賴的package包/類
@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();
}
示例10: testAddUnicodeStampSampleOriginal
import com.itextpdf.text.Phrase; //導入依賴的package包/類
/**
* <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();
}
}
示例11: testAddUnicodeStampEg_01
import com.itextpdf.text.Phrase; //導入依賴的package包/類
/**
* <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();
}
}
示例12: testCreateUnicodePdf
import com.itextpdf.text.Phrase; //導入依賴的package包/類
/**
* <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();
}
}
示例13: testDoubleSpace
import com.itextpdf.text.Phrase; //導入依賴的package包/類
/**
* <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();
}
}
示例14: addCellToTableCzech
import com.itextpdf.text.Phrase; //導入依賴的package包/類
/**
* <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);
}
示例15: createSimpleTextPdf
import com.itextpdf.text.Phrase; //導入依賴的package包/類
/**
* 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();
}