本文整理汇总了Java中com.itextpdf.text.pdf.PdfPCell.addElement方法的典型用法代码示例。如果您正苦于以下问题:Java PdfPCell.addElement方法的具体用法?Java PdfPCell.addElement怎么用?Java PdfPCell.addElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.itextpdf.text.pdf.PdfPCell
的用法示例。
在下文中一共展示了PdfPCell.addElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRender
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
public void onRender(PdfPCell cell ) throws PdfRenderException{
com.itextpdf.text.Paragraph pr = new com.itextpdf.text.Paragraph();
pr.setLeading( leading );
pr.setExtraParagraphSpace(0);
pr.setAlignment( HorizontalAlign.getByName(horizontalAlign).getAlignment() );
pr.setIndentationLeft( indent.getLeft() );
pr.setFirstLineIndent( indent.getFirst() );
pr.setIndentationRight( indent.getRight() );
pr.setSpacingBefore(0);
pr.setSpacingAfter(0);
if( phrases != null ){
for( AbstractPhrase phrase : phrases ){
phrase.onRender( pr );
}
}
cell.addElement( pr );
}
示例2: putSignature
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
private void putSignature(PdfPTable table, Context context) throws Exception {
String uploadOid = (String)context.get("uploadSignatureOid");
if ( StringUtils.isBlank(uploadOid) ) {
return;
}
byte[] imageBytes = UploadSupportUtils.getDataBytes( uploadOid );
if ( null == imageBytes ) {
return;
}
Image signatureImgObj = Image.getInstance( imageBytes );
signatureImgObj.setWidthPercentage(40f);
PdfPCell cell = new PdfPCell();
cell.setBorder( Rectangle.NO_BORDER );
cell.addElement(signatureImgObj);
table.addCell(cell);
}
示例3: tableWithPageNumber
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
private PdfPTable tableWithPageNumber() throws DocumentException, IOException {
PdfPTable innerTable = new PdfPTable(1);
innerTable.setWidths(new int[]{1});
innerTable.setWidthPercentage(100);
innerTable.setPaddingTop(0);
innerTable.addCell(new PageNumberCellGenerator(pageNumber, BackgroundColorGenerator.DEFAULT_BACKGROUND_COLOR)
.generateTile());
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBorder(0);
cell.setPadding(0);
cell.addElement(innerTable);
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(100f);
table.setWidths(new int[]{1});
table.setExtendLastRow(true);
table.addCell(cell);
return table;
}
示例4: generateFooter
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
private PdfPCell generateFooter() throws IOException, DocumentException, URISyntaxException {
PdfPCell cell = new PdfPCell();
cell.setColspan(12);
cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBorder(0);
cell.setPadding(0);
PdfPTable innerTable = new PdfPTable(2);
innerTable.getDefaultCell().setBorder(0);
innerTable.setWidths(new int[]{1, 1});
innerTable.setWidthPercentage(100);
innerTable.addCell(generateStamp());
innerTable.addCell(new PageNumberCellGenerator(pageNumber, backgroundColor).generateTile());
cell.addElement(innerTable);
return cell;
}
示例5: addFooter
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
/**
* Adds the footer style row for the field to the PDF table.
*
* @param table
* the table.
* @param font
* the font to use.
* @param name
* the field name.
* @param value
* the field value.
*/
private static void addFooter(PdfPTable table, Font font, String name,
Integer value) {
PdfPCell emptyCell = new PdfPCell();
emptyCell.setBorder(ReportServiceHelper.PDF_NO_BORDER);
table.addCell(emptyCell);
PdfPCell footerNameCell = new PdfPCell();
footerNameCell.setBorderColorTop(BaseColor.BLACK);
footerNameCell
.setHorizontalAlignment(ReportServiceHelper.PDF_ALIGN_LEFT);
footerNameCell.addElement(new com.itextpdf.text.Phrase(name, font));
footerNameCell.setBorder(ReportServiceHelper.PDF_BORDER_TOP);
table.addCell(footerNameCell);
PdfPCell footerValueCell = new PdfPCell();
footerValueCell.setBorderColorTop(BaseColor.BLACK);
if (value != null) {
com.itextpdf.text.Paragraph p = new com.itextpdf.text.Paragraph(
value.toString(), font);
p.setAlignment(ReportServiceHelper.PDF_ALIGN_RIGHT);
footerValueCell.addElement(p);
}
footerValueCell.setBorder(ReportServiceHelper.PDF_BORDER_TOP);
table.addCell(footerValueCell);
}
开发者ID:NASA-Tournament-Lab,项目名称:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application,代码行数:38,代码来源:AccountTypeTotalsReportService.java
示例6: writeQuestions
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
private void writeQuestions(Paragraph paragraph, Document document, boolean showCorrectAnswer,
ArrayList<Question> qlist) throws DocumentException, IOException
{
for (int i = 0; i < qlist.size(); i++)
{
Question question = qlist.get(i);
paragraph.clear();
// addQuestionNumber(paragraph, i, qlist.size());
addQuestionText(paragraph, question, i);
addAnswerTexts(paragraph, showCorrectAnswer, question);
fixFonts(paragraph);
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(100);
table.setKeepTogether(true);
PdfPCell cell = new PdfPCell();
cell.addElement(paragraph);
cell.setBorderColor(BaseColor.WHITE);
cell.setBorder(PdfPCell.NO_BORDER);
table.addCell(cell);
document.add(table);
}
}
示例7: createSignatureTable
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
private PdfPTable createSignatureTable(PdfContentByte cb, String date) throws DocumentException, MalformedURLException, IOException {
PdfPTable table = new PdfPTable(5);
float[] rows = { 95f, 10f, 35f, 10f, 110f };
table.setTotalWidth(rows);
table.getDefaultCell()
.setBorder(Rectangle.NO_BORDER);
final Image signatureImage = Image.getInstance(getClass().getResource(_imagePath + "/Unterschrift150.jpg"));
final Image stampImage = Image.getInstance(getClass().getResource(_imagePath + "/stamp.jpg"));
PdfPCell placeDateCell = new PdfPCell();
placeDateCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
placeDateCell.setBorder(Rectangle.NO_BORDER);
placeDateCell.addElement(new Phrase(new Chunk("Halle, " + date, textFontUserData)));
PdfPCell signatureCell = new PdfPCell();
signatureCell.setBorder(Rectangle.NO_BORDER);
signatureCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
signatureCell.setImage(signatureImage);
PdfPCell stampCell = new PdfPCell();
stampCell.setBorder(Rectangle.NO_BORDER);
stampCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
stampCell.setImage(stampImage);
table.addCell(placeDateCell);
table.addCell(new Phrase(new Chunk(" ", textFontUserData)));
table.addCell(signatureCell);
table.addCell(new Phrase(new Chunk(" ", textFontUserData)));
table.addCell(stampCell);
PdfPCell underSignatureCell = new PdfPCell();
underSignatureCell.setColspan(5);
underSignatureCell.setBorder(Rectangle.TOP);
underSignatureCell.addElement(new Phrase(new Chunk("Ort, Datum, Unterschrift des Zuwendungsempfängers", textFont)));
table.addCell(underSignatureCell);
return table;
}
示例8: process
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
@Override
public void process(int level, Node node, InvocationContext context) {
Font font = context.peekFont();
BaseColor color = styles.getColor(Styles.BLOCKQUOTE_COLOR).or(BaseColor.LIGHT_GRAY);
context.pushFont(new FontCopier(font).italic().color(color).get());
List<Element> subs = context.collectChildren(level, node);
context.popFont();
Paragraph p = new Paragraph();
p.addAll(subs);
PdfPCell cell = new PdfPCell();
cell.addElement(p);
cell.setBorder(Rectangle.NO_BORDER);
PdfPCell cellSymbol = new PdfPCell(
new Phrase(context.symbol("quote-left", 24, color))
);
cellSymbol.setVerticalAlignment(Element.ALIGN_TOP);
cellSymbol.setBorder(Rectangle.NO_BORDER);
cellSymbol.setBorderWidthRight(1.0f);
cellSymbol.setBorderColorRight(color);
cellSymbol.setPaddingTop(0f);
cellSymbol.setPaddingBottom(5f);
cellSymbol.setPaddingLeft(10f);
cellSymbol.setPaddingRight(0f);
PdfPTable table = new PdfPTable(new float[]{1, 10});
table.addCell(cellSymbol);
table.addCell(cell);
table.setSpacingBefore(20f);
table.setSpacingAfter(20f);
context.append(table);
}
示例9: process
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
@Override
public void process(int level, Node node, InvocationContext context) {
Attributes attrs = lookupAttributes(context);
List<Element> subs = context.collectChildren(level, node);
Paragraph p = new Paragraph();
p.addAll(subs);
PdfPCell cell = new PdfPCell();
cell.addElement(p);
cell.setBorderColor(BaseColor.LIGHT_GRAY);
cell.setBorder(Rectangle.TOP + Rectangle.BOTTOM);
cell.setPaddingTop(10f);
cell.setPaddingBottom(10f);
Styles styles = context.iTextContext().styles();
BaseColor symbolColor = symbolColor(attrs, styles);
PdfPCell cellSymbol = new PdfPCell(
new Phrase(context.symbol(symbol(attrs), 24, symbolColor))
);
cellSymbol.setVerticalAlignment(Element.ALIGN_TOP);
cellSymbol.setBorderColor(BaseColor.LIGHT_GRAY);
cellSymbol.setBorder(Rectangle.TOP + Rectangle.BOTTOM);
cellSymbol.setPaddingTop(10f);
cellSymbol.setPaddingBottom(10f);
cellSymbol.setPaddingLeft(0f);
cellSymbol.setPaddingRight(10f);
PdfPTable table = new PdfPTable(new float[]{1, 10});
table.addCell(cellSymbol);
table.addCell(cell);
table.setSpacingBefore(20f);
table.setSpacingAfter(20f);
ITextUtils.applyAttributes(table, attrs);
context.append(table);
}
示例10: createTableCell
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
/**
* Creates a cell for PDF table.
*
* @param content
* the content.
* @param font
* the font to use.
* @param backgroundColor
* the background color.
* @param alignment
* the alignment to use.
* @param border
* the border.
* @param colSpan
* how many columns the cell will span.
* @return the created cell.
*/
static PdfPCell createTableCell(Object content, Font font,
BaseColor backgroundColor, Integer alignment, Integer border,
int colSpan) {
PdfPCell cell = new PdfPCell();
if (border != null) {
cell.setBorder(border);
}
if (backgroundColor != null) {
cell.setBackgroundColor(backgroundColor);
}
cell.setColspan(colSpan);
if (content != null) {
String value;
if (content instanceof BigDecimal) {
value = Helper.getMoney((BigDecimal) content);
} else if (content instanceof Number) {
value = NumberFormat.getIntegerInstance(Locale.ENGLISH).format(content);
} else {
value = content.toString();
}
com.itextpdf.text.Paragraph p = new com.itextpdf.text.Paragraph(value, font);
if (alignment != null) {
p.setAlignment(alignment);
}
cell.addElement(p);
}
return cell;
}
开发者ID:NASA-Tournament-Lab,项目名称:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application,代码行数:46,代码来源:ReportServiceHelper.java
示例11: renderEmptyCell
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
public void renderEmptyCell(PdfPCell cell ){
Paragraph pr = new Paragraph();
Chunk chunk = new Chunk( " " );
pr.add( chunk );
cell.addElement( pr );
}
示例12: onRender
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
@Override
public void onRender( PdfPCell cell ) throws PdfRenderException{
PdfPTable table = new PdfPTable( widths.length );
try{
table.setTotalWidth( getTotalWidthsAsPs() );
table.setLockedWidth( true );
table.setSpacingAfter( 0f );
for( AbstractParagraph tableCell : cells ){
PdfPCell c = new PdfPCell();
float[] padding = new float[]{0f,0f,0f,0f};
if( tableCell instanceof TableCell ){
padding = ((TableCell) tableCell).getPadding();
}
c.setBorderWidth( 0f );
c.setLeft(0);
c.setTop(0);
c.setRight( 0 );
c.setBottom( 0 );
c.setUseAscender( true );
c.setIndent(0);
c.setHorizontalAlignment( Element.ALIGN_LEFT );
c.setVerticalAlignment( Element.ALIGN_TOP );
c.setPaddingLeft( SizeFactory.millimetersToPostscriptPoints(padding[0]));
c.setPaddingBottom( SizeFactory.millimetersToPostscriptPoints(padding[3]) );
c.setPaddingRight( SizeFactory.millimetersToPostscriptPoints(padding[2]) );
c.setPaddingTop(SizeFactory.millimetersToPostscriptPoints(padding[1]));
c.setBorder( 0 );
tableCell.onRender( c );
table.addCell( c );
}
cell.addElement( table );
}catch( Exception e ){
throw new PdfRenderException(e);
}
}
示例13: createTable
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
private PdfPTable createTable(PdfWriter writer, LabelFormat labelFormat, int firstRow, int lastRow) throws DocumentException {
if(firstRow >= lastRow) {
LOG.info("First row = " + firstRow + ", last row = " + lastRow + " so returning null");
return null;
}
if(lastRow - firstRow > labelFormat.getColumns() * labelFormat.getRows()) {
LOG.info("There were too many labels requested. "
+ "You wanted: " + (lastRow - firstRow) + " labels, "
+ "but this label format only allows: " + labelFormat.getColumns() * labelFormat.getRows());
return null;
}
final XSSFSheet sheet = xSSFWorkbook.getSheetAt(0);
if(lastRow > sheet.getLastRowNum()) {
LOG.info("last row was larger that the last row number of this sheet: " + sheet.getLastRowNum());
lastRow = sheet.getLastRowNum();
}
if(firstRow >= lastRow) {
LOG.info("after adjusting the last row, First row = " + firstRow + ", last row = " + lastRow + " so returning null");
return null;
}
final PdfPTable table = new PdfPTable(labelFormat.getColumns());
table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
table.setWidthPercentage(labelFormat.getWidthPercentage());
LOG.info("The width percentage i found is; " + labelFormat.getWidthPercentage());
for(int i = firstRow; i <= lastRow; i++) {
LOG.info("Showing row: " + i);
showOneLabel(sheet.getRow(i), table, writer, labelFormat);
}
if(lastRow == sheet.getLastRowNum()) {
// we are at the end
//check to make sure that the last row is filled in
if(lastRow % labelFormat.getColumns() != 0) {
for(int x = 0; x < lastRow % labelFormat.getColumns(); x++) {
final PdfPCell cell = new PdfPCell();
cell.setFixedHeight(labelFormat.getHeight() * 72);
cell.addElement(new Paragraph(" "));
table.addCell(cell);
}
}
}
return table;
}
示例14: testCreateLocalLinkInRotatedCell
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/34408764/create-local-link-in-rotated-pdfpcell-in-itextsharp">
* Create local link in rotated PdfPCell in iTextSharp
* </a>
* <p>
* This is the equivalent Java code for the C# code in the question. Indeed, this code
* also gives rise to the broken result. The cause is simple: Normally iText does not
* touch the current transformation matrix. So the chunk link creation code assumes the
* current user coordinate system to be the same as used for positioning annotations.
* But in case of rotated cells iText does change the transformation matrix and
* consequently the chunk link creation code positions the annotation at the wrong
* location.
* </p>
*/
@Test
public void testCreateLocalLinkInRotatedCell() throws IOException, DocumentException
{
Document doc = new Document();
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File(RESULT_FOLDER, "local-link.pdf")));
doc.open();
PdfPTable linkTable = new PdfPTable(2);
PdfPCell linkCell = new PdfPCell();
linkCell.setHorizontalAlignment(Element.ALIGN_CENTER);
linkCell.setRotation(90);
linkCell.setFixedHeight(70);
Anchor linkAnchor = new Anchor("Click here");
linkAnchor.setReference("#target");
Paragraph linkPara = new Paragraph();
linkPara.add(linkAnchor);
linkCell.addElement(linkPara);
linkTable.addCell(linkCell);
PdfPCell linkCell2 = new PdfPCell();
Anchor linkAnchor2 = new Anchor("Click here 2");
linkAnchor2.setReference("#target");
Paragraph linkPara2 = new Paragraph();
linkPara2.add(linkAnchor2);
linkCell2.addElement(linkPara2);
linkTable.addCell(linkCell2);
linkTable.addCell(new PdfPCell(new Phrase("cell 3")));
linkTable.addCell(new PdfPCell(new Phrase("cell 4")));
doc.add(linkTable);
doc.newPage();
Anchor destAnchor = new Anchor("top");
destAnchor.setName("target");
PdfPTable destTable = new PdfPTable(1);
PdfPCell destCell = new PdfPCell();
Paragraph destPara = new Paragraph();
destPara.add(destAnchor);
destCell.addElement(destPara);
destTable.addCell(destCell);
destTable.addCell(new PdfPCell(new Phrase("cell 2")));
destTable.addCell(new PdfPCell(new Phrase("cell 3")));
destTable.addCell(new PdfPCell(new Phrase("cell 4")));
doc.add(destTable);
doc.close();
}
示例15: writeChartToPDF
import com.itextpdf.text.pdf.PdfPCell; //导入方法依赖的package包/类
public static void writeChartToPDF(JFreeChart chart, int width, int height, String fileName)
{
PdfWriter writer = null;
Document document = new Document();
try
{
writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
document.open();
PdfContentByte pdfContentByte = writer.getDirectContent();
PdfTemplate pdfTemplateChartHolder = pdfContentByte.createTemplate(50, 50);
Graphics2D graphics2d = new PdfGraphics2D(pdfTemplateChartHolder, 50, 50);
Rectangle2D chartRegion = new Rectangle2D.Double(0, 0, 50, 50);
chart.draw(graphics2d, chartRegion);
graphics2d.dispose();
Image chartImage = Image.getInstance(pdfTemplateChartHolder);
document.add(chartImage);
PdfPTable table = new PdfPTable(5);
// the cell object
// we add a cell with colspan 3
PdfPCell cellX = new PdfPCell(new Phrase("A"));
cellX.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
cellX.setRowspan(6);
table.addCell(cellX);
PdfPCell cellA = new PdfPCell(new Phrase("A"));
cellA.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
cellA.setColspan(4);
table.addCell(cellA);
PdfPCell cellB = new PdfPCell(new Phrase("B"));
table.addCell(cellB);
PdfPCell cellC = new PdfPCell(new Phrase("C"));
table.addCell(cellC);
PdfPCell cellD = new PdfPCell(new Phrase("D"));
table.addCell(cellD);
PdfPCell cellE = new PdfPCell(new Phrase("E"));
table.addCell(cellE);
PdfPCell cellF = new PdfPCell(new Phrase("F"));
table.addCell(cellF);
PdfPCell cellG = new PdfPCell(new Phrase("G"));
table.addCell(cellG);
PdfPCell cellH = new PdfPCell(new Phrase("H"));
table.addCell(cellH);
PdfPCell cellI = new PdfPCell(new Phrase("I"));
table.addCell(cellI);
PdfPCell cellJ = new PdfPCell(new Phrase("J"));
cellJ.setColspan(2);
cellJ.setRowspan(3);
//instead of
// cellJ.setImage(chartImage);
//the OP now uses
Chunk chunk = new Chunk(chartImage, 20, -50);
cellJ.addElement(chunk);
//presumably with different contents of the other cells at hand
table.addCell(cellJ);
PdfPCell cellK = new PdfPCell(new Phrase("K"));
cellK.setColspan(2);
table.addCell(cellK);
PdfPCell cellL = new PdfPCell(new Phrase("L"));
cellL.setColspan(2);
table.addCell(cellL);
PdfPCell cellM = new PdfPCell(new Phrase("M"));
cellM.setColspan(2);
table.addCell(cellM);
document.add(table);
}
catch (Exception e)
{
e.printStackTrace();
}
document.close();
}