Create a "print-only" PDF with itext - java

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

Related

Lazy Loading PDF

I would like to implement lazy loading PDFs. Going through the forums we need to make make the PDF documents as 'linearized' and It will load first few pages quickly because it store page references in the start of the file. Will this resolve below problem as well.
There is separate charge for data transfer in AWS. Users want to see only first pages, But our system has to download entire PDF document that may be huge file. So we have to pay more money. If linearized PDF solves how to implement in Java technoglogy while download
The way a linearized PDF is processed by a PDF reader is implementation dependent, but I dare to say that in all cases, it is very likely that the reader will just continue to download the rest of the file in the background after showing the first page. The goal of linearization is not to prevent the rest of the file from being downloaded.
An alternative could be for you to split the file in sections and provide bookmarks that point to external PDF documents that will allow navigating through all the sections.

Show PDF file inside web browser with iText

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?

View PDF files in IFrame with Named Destinations

We've got an application that displays PDF files in an IFrame at specific Named Destinations. This works well on Windows systems but not Mac. In Safari, with Acrobat, the Named Destination is ignored and the document is displayed at the start.
Does anyone have any suggestions on how we might accomplish the task of displaying this information? Our initial thoughts are to:
Convert the PDF to HTML on the fly and display the HTML version in the IFrame
Convert the PDF on the page referenced to another format such as PNG etc. and display that in the IFrame
Utilize some kind of Java app that allowed us to render the PDF while honouring the Named Destination (not sure if this exists)
Any other ideas on a potential method of better displaying PDF files at Named Destination points that is a little more cross platform?
EDIT: I guess another option is to store the data in XSL/XSLT type format and convert to HTML for veiwing or PDF for saving to the desktop.
Not much help, but I found that alternative ways to display PDF files (other than the Acrobat Reader client) are few and far between. As you say, the commonly accepted way to render PDF's in something that doesn't natively support it seems to be converting it "something else", which is supported (even Acrobat.com does it this way in their Flex client if I remember it correctly).
Even converting the PDF document to other formats may be disappointing - especially if you expect a certain level of quality. It may also introduce server-side performance issues.
I realise this doesn't help anyone much but I'm interested to see if any other suggestions come up. We've dealt with this problem before in the same way, using IFrame controls (but without named destinations) but I'm very much interested in other suggestions/ideas as well.

What is the best way of opening PDFs from a JSP?

I would like some guidance on the best way of launching PDFs from a browser.
I have a JSP that takes some parameters and based on this downloads a PDF from my Documentum server. The files are stored on my local file system. I then provide the user with a bunch of links to the PDFs so they can click on them to launch the PDF.
Is there a best practice method of doing this?
Thanks.
There is nothing special to do: a link is sufficient. But you can add target="_new" if you want the browser to open the pdf in a new window.
Just make sure that the content-type returned for the pdf is application/pdf.

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