Creating PDF from JSP - java

I want to create a PDF file from an existing JSP on my server, as a downloadable report of an order on an electrical appliances web aplication, when you click on "create PDF" button. I've spent many hours investigating about this, but i have only found examples where you have to "model" your own PDF file using the iText Api, by adding Paragraphs, fonts, etc... Is there any way i can "capture" the common JSP output, like the one that dispatches a Servlet, and convert that into PDF?
Edit: I have investigated about using iText5/iText7, with no clear results.

Related

Programmatically combine PDF bookmarks in the final PDF with pdfbox

An other title could have been :
Combine several PDFs at runtime, create for each of them a bookmark in the final PDF but also keep bookmarks present in one or more of the unit PDFs if any
Hello,
I have following problem :
our webapplication "concatenates" PDFs from our content management system corresponding to a user request and send it back to the user.
We are using org.apache.pdfbox.pdmodel.PDDocument.addPage and also org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem in our code)
It works well, but we recently noticed a problem :
"when one of the PDF already contained bookmarks they are not considered in the final PDF bookmark tree"
It's normal, we haven't developped this functionnality! :-(
My question : can somebody give me some hints I can follow to merge also the bookmarks (I mean at runtime, not using the command line PdfMerger tool)
Many thanks in advance
Benoît

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?

Generate PDF or Similar to it

I'm creating a JAVA application
and I want to create and display and print a PDF file.
Like this example:
http://img11.hostingpics.net/pics/331702Sanstitre.jpg
So can you give the right way to do it ?
I mean is this a pdf file displayed into a JPanel or something else ?
and thnx alot.
For working with PDF files I would recommend using a library such as Apache PDFBox which has the ability to write, read, and print PDF files using org.apache.pdfbox.PrintPDF
The API can be found Here
As for displaying it in the JFrame, you can simply read the text and print it out in a Swing Text Area
For generation of pdf files you can use Jasper Reports library. It is popular API for creation pdf files from template in which specific data is inserted. Template files have ".jrxml" extension and can be created and edited by Jaspersoft Studio. These files look like forms with variable fields, this is very useful for generating different kinds of reports.
The API for Jasper Reports Library can be found here.

Create a "print-only" PDF with itext

This question is related to another one I've posted recently: Check printing with Java/JSP
We're looking for alternatives to how we currently print checks in a Java web application via an applet. It seems the consensus is to use PDF for printing and that itext offers the ability to do so with Java.
However, it's important in our particular case that the checks are "print-only" - the user should not have any ability in the application to save the check (I know a savvy user could do a PrintScreen but we want to cover our rears and make no native functionality in the app to save checks).
I haven't been successful in browsing the web to find out if it's possible to create a PDF with itext in this manner. I have seen posts on restricting permissions in a PDF but what I'm really looking for is a way to disable the ability to save a PDF locally using itext.
Does this functionality exist? If so, could you point me to documentation/code samples on it?
I'm presuming that you're serving this PDF and wishing to print it from within a web application / web site where no out of the ordinary client side plug-ins are installed.
If printing the PDF using conventional means (e.g. Adobe Reader), the PDF MUST be downloaded to the browser's cache to be opened and printed. There is no way around that.
Now you can probably prevent the average Joe from saving the PDF locally via the following technique, but any savvy user will be able to inspect your HTML's source and download the PDF directly.
Output your PDF in iText such that when the PDF is opened, a print action automatically occurs
Put an invisible IFRAME on your HTML page which loads this PDF, but is not visible in the browser to your user
When the user loads your HTML page, the PDF will be loaded in the IFRAME and sent to the users printer (presuming that Adobe Reader is installed in the browser). Yes, the PDF will end up in the browser cache, but the user would have to be savvy enough to both recognize this and then hunt it down in their browser's cache.
If this is not acceptable, you're going to have to look at converting the PDF to another file type (e.g. pages are rendered to images displayed in the browser or perhaps a Flash / Java object that sends each page in the document to the printer directly)
The printWriter class gives some static variables for certain options: PrintWriter
And here is another SO post that might help: iText disable printing/Copying/Saving

Generating and Displaying PDF file in Flex/Java

We have Flex on the front end and Java on the back end. When a user will request for a PDF file, request will go to the Java backend, where a PDF file will be generated using Jasper Reports. What we dont know is how to display this PDF file in browser; since we dont want to use JSP/Servlets etc - It has to be flex only. Any suggestions?
Flash Player cannot natively render PDF files. This is possible using Adobe AIR but not in a Flex application. Your best bet is to call navigateToURL() and open a Servlet in a new browser tab/window. The Servlet can simply write contents of the PDF file to the OutputStream and set the appropriate HTTP headers.
i think this question is old, but it may help others, there's a new library developed by Jasper Forge them selves, which deals with JasperReports directly, i mean it's not a PDF viewer, but a JasperReport exporting tool, you can download it from here
i tried it through using JasperServer, when viewing reports you can choose from different options to export it, one of them is flash, and it's working nice
Well for starters, PDFs don't always display in the browser. It depends on the user's settings. You essentially header them the pdf file and either they download it or a program like Acrobat Reader opens in the browser to display it.
Not sure how this is done in flex, I would imagine if you're using Java one simple servlet could do it.

Categories

Resources