Reading FOP Images from a Database

My application creates PDF files using images stored in the EAR. Images change approximately every month, and I would like to move them to the database in order to avoid deployment every time I change the image file.

Unfortunately, there is a problem:

<fo:block>
           <fo:external-graphic src="testImage.gif"/>
</fo:block>

FOP can simply accept a URL as a parameter. I could create a servlet that reads the database and can give an image, and then I could reference the servlet url from the FOP context, but I think this is not the best solution. Another solution would be to store the images in the file system and write the file names in the database, but I don't like any of these options. What do you think of these decisions? Is there a third? thanks Zoltan

+3
source share
2 answers

I think your servlet variant is probably the best.

Here is another option, not sure if it is good. Store the images in the database with the file name as the primary key. When starting the application, pull out all the images from the database and write them to the specified file names in the appropriate place so that the FOP logic can find them.

Either the application will need to be restarted when the image is changed in the database, or you will need to add a method to force updating image files on disk.

+2
source

Assuming you embed FOP in your application and do the conversion programmatically, you should be able to use a custom URI resolver to accomplish this.

- ( "db" ):

<fo:block>
           <fo:external-graphic src="db:testImage.gif"/>
</fo:block>

"db:" FOP User Agent ( FOP factory). . FOP ( "URIResolver" ).

, FOP ServletContextURIResolver, , . Apache FOP . p >

+2

Source: https://habr.com/ru/post/1767890/


All Articles