Add html source to PDF field with Java - java

I'm trying to create a PDF from a template in my backend and then serve it to the user when it needs to download it. The only problem that I have is that one of the fields in that template must have HTML source in it and must be rendered. Is there any way to add HTML source in that field and render it ? I am currently using PDFBox.

Related

How to create a PDF file from a JSP

I am developing a web application and when I want to add some functionality I find a problem:
-I offer to my clients the possibility of see a page called "Product details" with: the description of this product, product´s name, an image of the product... and I want to give them the chance of download a PDF file with (more or less) the same data.
The problem is that I am using Servlets and JSP so if I want to create a PDF from my HTML page I must take the "final" page.
So my question is:
-Is there a way to create a PDF automatically from a JSP in Java?

jsp page print or convert to PDF with all css applied

I want to convert a portion of my jsp page to pdf. Now I am considering iText for this. Now iText will convert html code to pdf which is fine. But how to fetch my html code with all the stylling applied?
I have my css classes in external css file. I am trying to fetch html code but not getting the css rules applied to elements.
Is there any alternative way?

iText - transform html to pdf and add and link to attachment

I have successfully parsed a XML file into a XHTML file, and then finally into a PDF using iText.
Now the next achievement would be to attach and link the Base64 embedded documents from the XML file into the PDF document. Attaching these files (so they appear in the "attachments pane" in the PDF viewer) is working.
Now my problem is that these attachments (.doc, .ppt, etc) should be opened by clicking on a text link or an image (icon). The images (and document names e.g. "test.doc") are already in the PDF, but how can I link the right file to the right image or text link? Could some of you give me a hint where to start?
What you could do is create a "mapping" of those files to the names, so they will have a unique identifier. After that you just create an endpoint that will return required file with required mime type (check out Octet stream as well). In the PDF you just add the hyperlinks that will go to your endpoint and fetch the required document by name.
EDIT: You could actually have more than one endpoint: you could need one for every mime type you use for more convenience.
In order to create a link inside PDF, use Anchor from iText lib.
In order to create an endpoint - it is really up to you. You can use any way to create a webapp that would return a file from web interactively.

Java agent to display dynamically generated graphic?

In Lotus Notes, I have a document that contains a PPT file attachment. Using Apache POI, I was planning to generate an image from a specific slide from that PPT and display it on the web browser by accessing the agent from the web probably with the use of Ajax. Is there a way to temporarily store the generated image and display it? If yes, how would you be able to do it?
You could achieve this even without saving the attachment by encoding it Base64 and embedding it in the source-code like this:
<img src="data:image/gif;base64,
R0lGODlhmwDFAPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0N
DQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8f
HyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDEx
MTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkND
.... Lot of ascii characters ....
gww18FBEikHcgNkMRW5lmkJI/teaa0wNiOhshFFuiRSVpL34nqQRphZmcV5miORZQwnRpndI
nUmiiTStuaKbLl4Z45wuuADDDDfsgNKeMmy160w1hdaVSZfupyiXSgLoWpOQFjgpWUsKCGem
CEXFlIRlBefllxqKKlyblb45olWqosgmi29iGiudM+6Knp5F6LhrDYYCccQRQuzQp1cBAQA7">
If you need to store it, you could store it to a temp- folder and then attach it to a document. Then you could easily show it using an img- tag with src- url http://server/db.nsf/_/documentuniqueidOfSavedDocument/$File/nameOfImage.jpg

Export to PDF Using Java or plain html

I am displaying few tables using HTML table tag and CSS . I am using Struts 2 and would like to include the "Export to PDF" functionality. Right now its just one page where i have to use this. Later one there will be one or two more page where i have to use this feature. I am Looking for some easy to implement available plugins or jar or anything that can be used to do that.
There is a Java API for generating PDF.
Here it is: http://itextpdf.com/download.php
Call it from you Servlet or Struts Action, and use HttpServletRersponse.getOutputStream to direct the PDF document back to the browser.

Categories

Resources