Home > Mobile >  Apache FOP: How to read image from the resources folder
Apache FOP: How to read image from the resources folder

Time:08-13

i have a maven spring boot project and i am using apache FOP to convert an XML to PDF with using XSL.

Everything works fine except that it fails to retrieve images from the resources folder.

I inserted the image into src/main/resources/static/test.jpg.

in fact, if I do localhost:8080/test.jpg, I can see the image.

if inside my XSL file I do this;

<fo:external-graphic src="url('http://localhost:8080/test.jpg')" content-height="24mm" content-width="190mm"/>

I can see the image inside my PDF file. The problem is that I don't want to set the host and port statically, but I want them to be recovered automatically. In previous versions of Apache FOP I saw that you could set the base URL, but now I don't know how, I'm using the latest version (2.7).

Or is there a different way than using the url? for example by using the path directly

Thank you

CodePudding user response:

I found this solution:

if for example in my resources folder I have this image:

src/main/resources/images_test/test.jpg

I can do:

<fo:external-graphic src="classpath:images_test/test.jpg" content-height="24mm" content-width="190mm"/>
  • Related