我正在使用 pdfbox 生成 pdf。 我想做一个信笺。我无法将 pdf 中的图像放在前面,而我将其放在文档的末尾。 为什么它没有排在前面?
最佳答案
如果您导航到此 URL您将看到标题为“Table”的部分。
如果您检查该部分,您将看到如何在 PDF 中创建自定义表格。通过创建自定义表格,您可以使用方法“Row.createImageCell()”为图像创建单元格,同时为自定义表格构建行和单元格(在那里,它只显示方法“createCell”,但它还具有方法“createImageCell”用于图像)。我希望这会有所帮助。
示例代码:
Image image = new Image(ImageIO.read(new File("/../logo.png")));
// imagine we have pretty big logo and we want scale that a little bit
float imageWidth = 75;
image = image.scaleByWidth(imageWidth);
Row<PDPage> row = table.createRow(12);
cell = row.createCell(30, "Data 1");
cell = row.createImageCell(imageWidth , image);
关于java - 使用 pdfbox 在特定单元格中添加 pdf 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37897543/