简体   繁体   English

使用pdfbox在特定单元格中以pdf格式添加图像

[英]Add image in pdf using pdfbox at a particular cell

I am using pdfbox to generate pdf. 我正在使用pdfbox生成pdf。 I want to make a letterhead. 我想做一个抬头纸。 I am not able to place the image in pdf at front, while I am getting it at the end of the document. 我无法在文档末尾获得pdf格式的图像。 Why it is not coming in front? 为什么它不在前面?

If you navigate to this URL you will see a section with header "Table". 如果导航到该URL,您将看到标题为“表格”的部分。

If you check that section you will see how you can create a custom table inside PDF. 如果选中该部分,将看到如何在PDF中创建自定义表格。 By creating your custom table, you can create cells for images with the method "Row.createImageCell()" while building the rows and cells for your custom table (there, it just shows the method "createCell" but it also has the method "createImageCell" for images). 通过创建您的自定义表,您可以使用方法“ Row.createImageCell()”为图像创建单元格,同时为您的自定义表构建行和单元格(那里只显示了“ createCell”方法,但也有方法“图片的createImageCell”)。 I hope this helps. 我希望这有帮助。

Sample code: 样例代码:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM