I am using pdfbox to generate 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. Why it is not coming in front?
Asked
Active
Viewed 2,366 times
1
-
I am using pdfbox 2.0.2 and boxable 1.4 . I have referenced from here: http://stackoverflow.com/questions/8521290/cant-add-an-image-to-a-pdf-using-pdfbox. But the problem is that, the image comes at the end of the pdf, while I want to put it on beginning of the page. – Varshal Davda Jun 20 '16 at 04:25
-
1Boxable is on top of PDFBox... you should definitively add your code. The linked code is ok (y = 700), but I don't know how Boxable works. – Tilman Hausherr Jun 20 '16 at 07:01
-
1Your language is also ambigous... I suspect you meant "top" when you wrote "front", and "bottom" when you wrote "end", and "page" when you wrote "document". Please edit your question if I am right with my interpretation. This not to criticize you, it is so that people understand what you're asking and can help you. If you still don't get an answer, create an issue here: https://github.com/dhorions/boxable/issues . But be sure to try some of their examples first. – Tilman Hausherr Jun 20 '16 at 07:06
1 Answers
2
If you navigate to this URL you will see a section with header "Table".
If you check that section you will see how you can create a custom table inside 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). 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);

Bahadir Tasdemir
- 10,325
- 4
- 49
- 61