0

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?

Community
  • 1
  • 1
Zack Macomber
  • 6,682
  • 14
  • 57
  • 104

2 Answers2

2

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.

  1. Output your PDF in iText such that when the PDF is opened, a print action automatically occurs
  2. 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)

userx
  • 3,769
  • 1
  • 23
  • 33
  • Hi - thanks for this answer - one problem I'm having is that the PDF print dialog is coming up REALLY slow, even when I have a simple "Hello, World" PDF. Any thoughts on how to speed it up? – Zack Macomber Mar 12 '12 at 19:23
1

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

Community
  • 1
  • 1
tom
  • 2,735
  • 21
  • 35
  • 2
    You should be careful though, as of iText 5 it is no longer free to use for commercial support but I guess you are aware of that. – tom Mar 09 '12 at 18:27
  • Thanks tom - I looked at that post earlier and it seems that when implementing that method, it will just force the user to supply a password to do those functions, right? I guess I could try it out and see myself... – Zack Macomber Mar 09 '12 at 18:32
  • Also, in regards to your comment on commercial support - this application is inside an intranet and will not be generating revenue - it is just used by users in the company for doing administrative tasks - does that sound like it qualifies as being "non-commercial"? To me, "commercial" implicates money will be made with the application but that will not occur in this app. – Zack Macomber Mar 09 '12 at 18:34
  • I am not a layer at all so I cannot advise you on that. When in doubt use iText 2 (this is still free) and that is what we do. – tom Mar 09 '12 at 18:38
  • admin tasks in a commercial enterprise are support activities for the revenue-generating tasks. They are all commercial activities, IMHO (and I'm no lawyer either). – Kevin Welker Mar 09 '12 at 18:40
  • About the password. I believe that everything you allow does not need the password but I might be wrong. – tom Mar 09 '12 at 18:40