Trying to Embed PDF into my HTML Web Page for which I am calling an AJAX function.
The function retrieves the data from my backend of the PDF but instead of rendering that as PDF, my frame keep showing the data of that PDF as shown in screenshot.
Any suggestion on how to make my page render it into PDF, as webpages by default support showing PDFs.
My data from backend is in byte[]
format, further suggestion to improve
2
Answers
So I had asked this question. And, after some research, I found out that the approach was right, but I was omitting crucial headers which indicated that the data being sent from the backend is to be rendered as PDF or image.
So if any one working on spring boot and facing same problem can follow this:
Controller – endpoints mapping:
ScannerService Interface
ScannerService Implementation – this renders PDF as well convert image into PDF for viewing
My JavaScript call method to dynamically render different files and embed into frame
HTML embed tag to embed the rendered PDF into webpage:
Due to security reason, embedding is generally disabled for which we have to manually configure these setting into spring boot:
The above should be added to Security Filter Chain in security configuration.
<a href="file.pdf">PDF</a>
, simply set up an anchor tag like this, you can also add up a button in between or keep the plain text. Now, when your PDF text is clicked, your pdf document shall open in pdf formatmail me at [email protected] for further queries 🙂