I have a Spring Controller that converts PDFs into images (one for each page) and I need to display the images in a JSP.
Initially I thought of sending the images back as Base64 encoded strings, but I read a few posts advising against. So I tried to store the images as a temp file and send back to the JSP just the path to the files, but turns out it's not public.
As a temporary solution I am pointing the images' src to another REST method that retrieves the image and prints the content, however I would like to reduce the number of calls and have a single method that prints/returns all the images.
CodePudding user response:
Basically you are working with 2 files (PDF and image), you receive PDF from one location and convert into to image and display the image in the JSP, there is mechanism called CDN, now a days cloud providers offers free image hosting with limited features such as AWS, Azure, GCP. For instance, check the below from AWS, and you can refer the path in your JSP.
This could be public with control panel settings.
CodePudding user response:
The best way is to return a page part (in some form) having a links for every page image).
In your controller load the PDF and retrieve the number of pages
Return the HTML with links to every page, invoking a next service
When asked for a page, create the page image if not already created
Return the page image
The presentation of those links, could be with < 1 2 3 ... >
or whatever.
This probably requires some administration (PDF, images). It is likely there are some basic Spring examples.
You could optimize the process by job in the background / asynchrone preloading of the next page.