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.
Related
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.
In my application i have a webpage created for the user, which display the content from the mysql workbench in the tabular format. this application is created using spring mvc(eclipse ide). in this page i have created a export button, on click of this button the contents present the table will be exported to pdf or excel format and the generated file should be downloaded to the download folder.
Can anyone help with:
extract these table content
export the content to pdf/excel(xls)
download of the file on click of the button.
I am totally confused how do i start with it. any reference for how to read the webpage content and proceed with this will be helpful.
Not exactly sure of what you want to do, but to extract a website content is easy with Jsoup, it is a great html parsing library and can be downloaded here. To produce excel file you could use a library developed by Apache - Apache POI. A tutorial on how to do this can be found here.
Here is what I think you can do-
Since you are displaying the contents in a webpage, you already have an API that fetches the data from the data source. You can utilize the same API for getting the data. You would then need to turn that data into a CSV format. On top of this you can have a little REST service that serves contents of type text/csv. Your download button in the UI can invoke this REST to get the CSV file downloaded. Hope this helps.
I am new to wicket and need to load a PDF, using Java and Wicket, when a user enters a URL. For example, typing in the URL:
www.domain.com/pdf/myDocument
will force the document www.domain.com/pdf/myDocument.pdf to be loaded
The reason for doing this is that I have a bunch of PDF documents in the webapp folder of my Java project. A printed letter that is being mailed to customers has a link to one of these documents but is missing the PDF file extension. I therefore need to put something in place that intercepts this URL and load the appropriate PDF resource.
Many thanks for any help.
Check http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/. You can load with webApplication.getServletContext().getResource(parameters.get(0).toString() + ".pdf")
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
I developed a report (without and independent of any db datasource) only with iText. I know that with JasperReports this is easy. But in my case I just storage the report in pdf file or I used acrobat for java beans to show the report to user. Now I need to change my implementation code to show this report in web browser instead to save in the file.
How I can do this?
You need 2 thinks, first the browser plugin installed on the browser and second to set the content disposition header as inline in the respose, otherwise the browser will try to download it.
response.setHeader("Content-Disposition","inline; filename=\"file.pdf\"");
I assume that you've already set the Content Type to application/pdf and know how to convert an iText document to a bytearray and transmit it to the user.
A word of caution: if people outside your organization will use this app, the might not have the pdf plugin installed, in which case, the browse will download the pdf instead of displaying the pdf.
if the browser has the appropriate add-on installed, you can just drag and drop a pdf-file into the browser and it will show it.
Or if you have a site on which you want to present the pdf, you just put a link to it:
link to your pdf
Or did you mean you want to generate html-output for your report instead of pdf?