【发布时间】:2023-03-02 23:23:01
【问题描述】:
我正在使用 iText 2.1.7。在我正在生成的文档的最后一页上,我有一个签名段落,我总是希望在最后一页的底部呈现它。
我将所有文本捆绑到一个段落中,然后将它们全部放在一个单元格表中,并使用 PDFWriter 将其写入页面上的固定位置。段落中的文本显示正常,但未包含图像。
当我直接将段落本身添加到报告中时,图像呈现良好,但我没有我需要的定位控制。
这是代码的sn-p:
private void addSignatureAndContactInformationAndParagraphThree() throws DocumentException {
Font bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, PDFReportUtils.SIGNATURE_NAME_FONT_SIZE);
Font regular = FontFactory.getFont(FontFactory.HELVETICA, PDFReportUtils.BODY_FONT_SIZE);
Chunk kindRegards = new Chunk("Kind regards,\n", regular);
Chunk companyName = new Chunk(getReport().getCompanyName() + "\n", regular);
Chunk author = new Chunk(getReport().getReportAuthor() + "\n", bold);
Chunk email = new Chunk(getReport().getReportAuthorEmail() + "\n", regular);
Chunk phone = new Chunk(getReport().getReportAuthorPhone() + "\n\n", regular);
PdfPTable singleCellTable = new PdfPTable(1);
singleCellTable.setTotalWidth((getPdfDocument().right(getPdfDocument().rightMargin())
- getPdfDocument().left(getPdfDocument().leftMargin())) + 300f);
PdfPCell singleCell = new PdfPCell();
singleCell.setBorder(Rectangle.NO_BORDER);
Paragraph signatureImageBlock = new Paragraph();
signatureImageBlock.add(kindRegards);
if(getSignatureImage() != null)
{
signatureImageBlock.add(getSignatureImage());
}
signatureImageBlock.add(companyName);
signatureImageBlock.add(author);
signatureImageBlock.add(email);
signatureImageBlock.add(phone);
signatureImageBlock.add(getParagraphThree());
singleCell.addElement(signatureImageBlock);
singleCellTable.addCell(singleCell);
singleCellTable.writeSelectedRows(0, -1,
getPdfDocument().left(getPdfDocument().leftMargin()) - 45f,
singleCellTable.getTotalHeight() + getPdfDocument().bottom(getPdfDocument().bottomMargin()),
writer.getDirectContent());
}
getSignatureImage() 检查用户是否配置了签名图像,然后是来自硬盘的图像(这里是返回语句):
return Image.getInstance(signatureImagePath);
知道为什么它可以很好地呈现所有文本但根本不包含图像吗?我已经对此进行了调试以确保它从 getSignatureImage() 获取图像
【问题讨论】: