1

Is there a way to set a background picture in a PDF generated by PDFBox ? I also want to set pictures and text on top of it...

I tried with an image which takes the size of the document. When I set the picture after the text, the text I want over the picture is invisible but can be selected (is it under picture ?) . When I set it before the text the background image disappears altogether and everything looks as if I had never set it.

Any ideas ?

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
  • 1
    Please inspect (or supply for inspection) your PDF file. There are quite a number of PDF files out there which first fill a white rectangle the size of the page and then add content on it. Thus, if you add the image before all that, the white rectangle will cover your background image in spe. In that case you might want to add a transparent foreground image; unless you want to write code to first analyze the page content in your PDF and remove the white rectangle, that is... – mkl Feb 11 '13 at 16:21
  • Thanks a lot that will help, can you recommend any free inspection tools ? – Christophe Roussy Feb 11 '13 at 16:24
  • 1
    You might want to look at [RUPS](http://sourceforge.net/projects/itextrups/) (Reading and Updating PDF Syntax; AGPL). You must be ready to read PDF content stream operators, though. I'm not aware of a free inspection tool showing the page content elements graphically. – mkl Feb 11 '13 at 16:28
  • Viewed 1000 times but still no answer :) Here is a similar question: https://stackoverflow.com/questions/33406920/how-to-add-background-image-to-pdf-using-pdfbox – Christophe Roussy May 22 '18 at 12:34
  • *"Viewed 1000 times but still no answer"* - The reason is simple: Your question is about a specific problem (*"When I set it before the text the background image disappears altogether..."*), one which quite likely is due to some special property of your PDF, see my first comment, or due to some glitch in the code. For a serious answer, therefore, you need to supply the PDF and your pivotal code. You did neither. In contrast the similar question you linked is not about such a specific problem but about a generic example for the task. – mkl May 22 '18 at 13:05
  • Yes but sadly this is so old I do not have the PDF anymore. Those keywords seem to match google searches or whatever. So at least I posted the link to possibly linked answer ... – Christophe Roussy May 22 '18 at 14:16
  • If that's ok with you, we can close your question as duplicate of the question you referenced. – mkl May 22 '18 at 15:02
  • Yes we can, I had to upvote the answer of the other question to do this. – Christophe Roussy May 22 '18 at 15:33
  • *"I had to upvote the answer of the other question to do this."* - yes, you can only close as duplicate of questions with an accepted or upvoted answer. – mkl May 22 '18 at 19:25

0 Answers0