本文整理匯總了Java中com.itextpdf.text.Phrase.add方法的典型用法代碼示例。如果您正苦於以下問題:Java Phrase.add方法的具體用法?Java Phrase.add怎麽用?Java Phrase.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.Phrase
的用法示例。
在下文中一共展示了Phrase.add方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: createHeader
import com.itextpdf.text.Phrase; //導入方法依賴的package包/類
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;
}
示例5: onEndPage
import com.itextpdf.text.Phrase; //導入方法依賴的package包/類
@Override
// initialization of the header table
public void onEndPage(final PdfWriter writer,
final Document document) {
final PdfPTable header = new PdfPTable(2);
final Phrase p = new Phrase();
final Chunk ck = new Chunk(String.format("%s%n %s Finalist Schedule - Award Group: %s", //
mChallengeTitle, //
mShowPrivate ? "Private" : "", mDivision), HEADER_FONT);
p.add(ck);
header.getDefaultCell().setBorderWidth(0);
header.addCell(p);
header.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);
header.addCell(new Phrase(new Chunk(String.format("Tournament: %s %nDate: %s", mTournament, mFormattedDate),
HEADER_FONT)));
final PdfPCell blankCell = new PdfPCell();
blankCell.setBorder(0);
blankCell.setBorderWidthTop(1.0f);
blankCell.setColspan(2);
header.addCell(blankCell);
final PdfContentByte cb = writer.getDirectContent();
cb.saveState();
header.setTotalWidth(document.right()
- document.left());
header.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 10, cb);
cb.restoreState();
}
示例6: onEndPage
import com.itextpdf.text.Phrase; //導入方法依賴的package包/類
@Override
// initialization of the header table
public void onEndPage(final PdfWriter writer,
final Document document) {
final PdfPTable header = new PdfPTable(2);
final Phrase p = new Phrase();
final Chunk ck = new Chunk(_challengeTitle
+ "\n" + _reportTitle, _font);
p.add(ck);
header.getDefaultCell().setBorderWidth(0);
header.addCell(p);
header.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);
header.addCell(new Phrase(new Chunk("Tournament: "
+ _tournament + "\nDate: " + _formattedDate, _font)));
final PdfPCell blankCell = new PdfPCell();
blankCell.setBorder(0);
blankCell.setBorderWidthTop(1.0f);
blankCell.setColspan(2);
header.addCell(blankCell);
final PdfContentByte cb = writer.getDirectContent();
cb.saveState();
header.setTotalWidth(document.right()
- document.left());
header.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 10, cb);
cb.restoreState();
}
示例7: createBlueBlock
import com.itextpdf.text.Phrase; //導入方法依賴的package包/類
private void createBlueBlock(PdfContentByte cb, int treeCount) throws DocumentException {
cb.saveState();
cb.setRGBColorFill(0x64, 0xA7, 0xBD);
cb.rectangle(0.0f, 375.0f, 595.0f, 200.0f);
cb.fill();
cb.stroke();
cb.restoreState();
Font textFont = new Font(FontFamily.TIMES_ROMAN, 14, Font.ITALIC, BaseColor.WHITE);
Font textBlack = new Font(FontFamily.TIMES_ROMAN, 14, Font.ITALIC, BaseColor.BLACK);
Font textFontTreeCount = new Font(FontFamily.HELVETICA, 30, Font.BOLD, BaseColor.BLACK);
PdfPTable tableForTreeCount = new PdfPTable(1);
float[] rows = { 495f };
tableForTreeCount.setTotalWidth(rows);
tableForTreeCount.getDefaultCell().setBorder(Rectangle.NO_BORDER);
tableForTreeCount.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
tableForTreeCount.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
tableForTreeCount.getDefaultCell().setFixedHeight(40);
Integer treeCountAsObject = treeCount;
tableForTreeCount.addCell(new Phrase(new Chunk(treeCountAsObject.toString(), textFontTreeCount)));
tableForTreeCount.writeSelectedRows(0, 1, 50f, 575f, cb);
PdfPTable tableForWhiteText = new PdfPTable(1);
tableForWhiteText.setTotalWidth(rows);
tableForWhiteText.getDefaultCell().setBorder(Rectangle.BOTTOM);
tableForWhiteText.getDefaultCell().setBorderWidth(1f);
tableForWhiteText.getDefaultCell().setBorderColor(BaseColor.WHITE);
tableForWhiteText.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
tableForWhiteText.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
tableForWhiteText.getDefaultCell().setFixedHeight(40);
Phrase phraseForTreesPlantForYou = new Phrase();
if (treeCount == 1) {
phraseForTreesPlantForYou.add(new Chunk("Baum wurde für Sie gepflanzt!", textFont));
} else {
phraseForTreesPlantForYou.add(new Chunk("Bäume wurden für Sie gepflanzt!", textFont));
}
PdfPCell longTextCell = new PdfPCell();
longTextCell.setHorizontalAlignment(Element.ALIGN_LEFT);
longTextCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
longTextCell.setBorder(Rectangle.BOTTOM);
longTextCell.setBorderWidth(1f);
longTextCell.setBorderColor(BaseColor.WHITE);
longTextCell.setFixedHeight(65);
Paragraph longText = new Paragraph(new Chunk(
"Mit diesem Gutschein können sie Ihre Pflanzung in Augenschein nehmen und mehr über die naturnahen Aufforstungsprojekte bei \"I Plant A Tree\" erfahren. Ihre Bäume wachsen auf ehemals brachliegenden Flächen und sind Teil neu entstehender Wälder.",
textFont));
longText.setLeading(15f);
longTextCell.addElement(longText);
tableForWhiteText.addCell(phraseForTreesPlantForYou);
tableForWhiteText.addCell(longTextCell);
tableForWhiteText.writeSelectedRows(0, 2, 50f, 535f, cb);
PdfPTable tableForHowItWorks = new PdfPTable(1);
tableForHowItWorks.setTotalWidth(rows);
tableForHowItWorks.getDefaultCell().setBorder(Rectangle.NO_BORDER);
tableForHowItWorks.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
tableForHowItWorks.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
tableForHowItWorks.getDefaultCell().setFixedHeight(40);
tableForHowItWorks.addCell(new Phrase(new Chunk("Und so einfach funktioniert's:", textBlack)));
tableForHowItWorks.writeSelectedRows(0, 2, 50f, 425f, cb);
}
示例8: createLawTextDateAndSignatureBlock
import com.itextpdf.text.Phrase; //導入方法依賴的package包/類
private void createLawTextDateAndSignatureBlock(PdfContentByte cb, String number, String date) throws DocumentException, MalformedURLException, IOException {
Font textFont = new Font(FontFamily.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK);
Font textFontBold = new Font(FontFamily.HELVETICA, 10, Font.BOLD, BaseColor.BLACK);
Font textFontSmall = new Font(FontFamily.HELVETICA, 6, Font.NORMAL, BaseColor.BLACK);
PdfPTable table = new PdfPTable(2);
float[] rows = { 247.5f, 247.5f };
table.setTotalWidth(rows);
table.getDefaultCell().setBorder(Rectangle.BOTTOM);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
table.getDefaultCell().setFixedHeight(75);
Phrase leftPhrase = new Phrase();
leftPhrase.add(new Chunk(
"Hiermit wird die Pflanzung dieser Bäume bescheinigt. Die Pflanzung erfolgt durch die Wald 1.1 gGmbH und kann im Internet unter www.iplantatree.org über die Zertifikat-Nummer #",
textFont));
leftPhrase.add(new Chunk(number, textFontBold));
leftPhrase.add(new Chunk(" abgerufen bzw. nachvollzogen werden.", textFont));
Phrase rightPhrase = new Phrase(10f);
rightPhrase.add(new Chunk(
"Dieses Zertifikat ist keine Bestätigung über Geldzuwendungen im Sinne des § 10 b des Einkommensteuergesetzes an eine der in § 5 Abs. 1 Nr. 9 des Körperschaftsteuergesetzes bezeichneten Körperschaften, Personenvereinigungen oder Vermögensmassen.",
textFont));
PdfPCell rightCell = new PdfPCell();
rightCell.setPaddingLeft(10.0f);
rightCell.setBorder(Rectangle.BOTTOM);
rightCell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
rightCell.setVerticalAlignment(Element.ALIGN_TOP);
rightCell.addElement(rightPhrase);
PdfPCell dateCell = new PdfPCell();
dateCell.setPaddingTop(10.0f);
dateCell.setBorder(Rectangle.NO_BORDER);
dateCell.addElement(new Phrase(new Chunk("Datum der Ausstellung: " + date, textFont)));
PdfPCell emptyCell = new PdfPCell();
emptyCell.setBorder(Rectangle.NO_BORDER);
final Image signatureImage = Image.getInstance(getClass().getResource(_imagePath + "/Unterschrift150.jpg"));
PdfPCell underSignatureCell = new PdfPCell();
underSignatureCell.setBorder(Rectangle.NO_BORDER);
underSignatureCell.setPadding(0f);
Phrase underSignaturePhrase = new Phrase(10f);
underSignaturePhrase.add(new Chunk("Unterschrift / Stempel des ausstellenden Unternehmens / der ausstellenden Person", textFontSmall));
underSignatureCell.addElement(underSignaturePhrase);
underSignatureCell.setVerticalAlignment(Element.ALIGN_TOP);
table.addCell(leftPhrase);
table.addCell(rightCell);
table.addCell(dateCell);
table.addCell(emptyCell);
table.addCell(signatureImage);
table.addCell(emptyCell);
table.addCell(underSignatureCell);
table.addCell(emptyCell);
table.writeSelectedRows(0, 4, 50, 305, cb);
}
示例9: onEndPage
import com.itextpdf.text.Phrase; //導入方法依賴的package包/類
@Override
// initialization of the header table
public void onEndPage(final PdfWriter writer,
final Document document) {
final PdfPTable header = new PdfPTable(2);
final Phrase p = new Phrase();
final Chunk ck = new Chunk(_challengeTitle
+ "\n"
+ _reportTitle, _font);
p.add(ck);
header.getDefaultCell().setBorderWidth(0);
header.addCell(p);
header.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);
header.addCell(new Phrase(new Chunk("Tournament: "
+ _tournament
+ "\nDate: "
+ _formattedDate, _font)));
// horizontal line
final PdfPCell blankCell = new PdfPCell();
blankCell.setBorder(0);
blankCell.setBorderWidthTop(1.0f);
blankCell.setColspan(2);
header.addCell(blankCell);
if (null != _team) {
// team information
final Paragraph para = new Paragraph();
para.add(new Chunk("Team #"
+ _team.getTeamNumber()
+ " "
+ _team.getTeamName()
+ " / "
+ _team.getOrganization(), TITLE_FONT));
para.add(Chunk.NEWLINE);
para.add(new Chunk("Award Group: "
+ _team.getAwardGroup(), TITLE_FONT));
para.add(Chunk.NEWLINE);
final PdfPCell teamInformation = new PdfPCell(para);
teamInformation.setBorder(0);
teamInformation.setColspan(2);
header.addCell(teamInformation);
}
header.setTotalWidth(document.right()
- document.left());
final PdfContentByte cb = writer.getDirectContent();
cb.saveState();
header.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight()
- 10, cb);
cb.restoreState();
}