PDF printing to client's printer without opening them - java

I am working on a web application developed in Java with struts running on Tomcat. I have a requirement in the web application as follows:
One JSP page having a list of PDF files each associated with a checkbox. The JSP page has one Button. Once the user selects the PDF documents he wants to print by selecting the associated checkboxes, user clicks on the button.
Then all the selected PDF docs should be sent to a specific local Printer( i.e. printer connected to the client machine where from user is accessing the web application). The selected PDF files should not be opened either in acrobat reader or in browser. The PDF docs should not be visible to the user while being sent to printer.
Could anyone please help me in implementing this requirement?

It is possible with Internet Explorer and ActiveX. Search about "auto print" and "silent printing" with Google. You may have to lower security settings in Internet Explorer for that.
We're using it here for some Intranets from our Customers.
For Firefox you may be able to trigger the print dialog via javascript. (http://stackoverflow.com/questions/975652/silent-print-a-embedded-pdf)
If this is the case you can disable print dialog in FF with setting print.always_print_silent=true in about:config.
Never did it on my own, so I cannot say for sure if it works like the ActiveX thing does.
For Chrome there is an issue requesting same feature like FF has. See https://code.google.com/p/chromium/issues/detail?id=31395.

You will most likely have to use a Java Applet for this. The browser have no inherent capability to print a pdf document. You may be able to access the "standard" adobe plugin, but to my knowledge it is not exposed to the standard scripting environment.
You can look here: Can a Java Applet use the printer?
Note: it is recommended to have the applet signed to prevent security restrictions and/or annoying questions to the user to allow access to printer.
You'll also need some form of PDF renderer in your applet (to render to printer). Something like http://java.net/projects/pdf-renderer/, read more here: http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/

That is not possible with JavaScript. It is possible with either Flash or a Java applet. In either case, you will need to be able to use both the Printer drivers and a custom PDF reading toolkit. There are adequate plugins for both for PDF reading, and both come with a printing API.
If I may say so, this is a bad requirement -- it is not good to force a user to print a document without reading it -- and should be re-negotiated, especially since it is trivially simple to have those documents print to PDF anyway.

Related

How do can I share a PDF and interact with it remotely?

I want to make an functionality in which user can share the url of uploaded PDF. Now when the another user open the same pdf with given url, first person will scroll down and on another user can see the scrolled content directly or the pdf will be automatically scrolled.
Is it possible using Java, JavaScript or another technology?
Ex. Person 1 has shared exaple.pdf with person 2 by giving link of it.
Person 2 had clicked on link and the pdf is opened at his side.
Now person 1 is scrolling the pdf to page no. 3 and at the same time on the Person 2's screen the pdf will be auto scrolled to page no. 3.
Please let me know if my issue is still not clear.
If I were you I wouldn't definitely use PDF format because it's really hard to manipulate with. Instead of that, you could make your a document a HTML file and then listen to page events with JQuery (like scroll event). So far so good, this is the easy part.
Now you need to make clients communicate with each other so I think WebSocket is the best way for it. If you insist on Java, you can use brand new WebSocket API but it can be also implemented in pure JavaScript like Socket IO so you don't even have to use Java for it.
But if you have to work with PDFs, then good luck, it's going to be really tough task.
As Petr Mensik said it would be probably pretty hard to do it with PDF file with Java, JavaScript.
But if you really want I guess it would be appropriate to check some Adobe SDK. I'm not sure but maybe Adobe AIR or Flex or other Flash application.

Embedding Microsoft Word in a browser window (cross-browser)

Background
Our web application stores Microsoft Word documents which users want to edit (ideally with Word) in their browser of choice.
To access the web application (and the documents), users must login. As they are unwilling to login whenever they edit a document, document retrieval and storage must occur in their login session, which is easiest to accomplish if document download and upload is done by the browser.
Question
How can I embed Word into (or at least invoke it from) a browser window to edit a document the browser has retrieved from the server? It should work in both Internet Explorer and Firefox.
Own Research
ActiveX is not supported by Firefox.
There is not javascript api for invoking (let alone embed) native applications. Even if there were, I don't see how I could pass the document, and neither Internet Explorer 10 not Firefox 20 appears to offer an api to write a file to disk.
I could write a (signed) Java Applet to invoke Word, but ensuring that all changes are uploaded to the server appears difficult (what if the user closes the browser window before saving in Word?)
Eclipse has this nice feature of permitting in place editing word documents. This appears to be part of their SWT toolkit, but as that requires native code, I am not sure how to deploy it is an applet?
I don't know if they are embeddable for free, but you can take a look at Microsoft Office Webapps

Web application that deals with files -upload download

I have an existing swing desktop application that I wish to convert to a web application. The first thing that is stopping from doing so is that the desktop application deals with writing and reading from PDF files. Also the user fills up the PDF forms which needs to be read by the application.
Now a typical use case in the desktop application is like, the user logs in opens a PDF form and fills it up. The swing application manages where the file is stored so it goes to the file and reads the form, extracts the data and stores the data in the db. The user might not fill up the form all in one go. He might save it come back to it later and continue.
All of this needs to be done by the web app now. My problem is I don't want the user to download and upload the form multiple times to the server. That would eat the bandwidth and also asking the use to save the file locally and upload it back once he completes filling the form doesn't appeal to me since the desktop application nicely used to manage the location of these files as well.
Would I need to implement something like a dropbox kind of thing? A small deamon running continuously to check what file has been updated and upload it to the server? That would be difficult since at the server I wouldn't know if the file was latest or not. Is there anything like this that someone might have done before?
I have anther suggestion: why don't you show the user a form with the same fields and transfer them to the PDF after the user submits. This way the Pdf does not leave the server and you transmit just the minimal amount of data.
Switching to a web-version of the application may force you to re-think some of the way you are doing things. Certainly browsers are intentionally limited in their access to the local file system which introduces a major hurdle for your current mode of operation.
Even if you could display the PDF within a browser, detect the completion of edits and send this back to the server from within browser code (which is probably possible), you'll be subject to different browsers doing different (strange) things with whatever pdf plugin is installed.
As Vitaliy mentioned already, switching being able to populate a (web) form in the browser means that whole download upload problem goes away. But then you have to take what the user has done in a web page and pump that into a PDF somehow. If you don't HAVE to start with a PDF, but could collect the data and produce a PDF at the end then you might have more options. For example you could use iText to create a PDF directly if you don't have too many styles of document to work with. You could use something like Docmosis which you can give templates to and get it to populate and render PDFs later. With the Docmosis option you can also ask Docmosis for the list of fields in the template so could build a web form based on the selected template, let the user fill it in, then push that data to Docmosis to produce the file.
Hopefully there's some options there that are useful to you.
Adobe documents how to do this here. Never underestimate the power of design-by-google. I know this can be made to work because I've used PDF forms on line.
I worked on a similar issue a few years ago, although I wasn't dealing with signed forms. The signature definitely makes it a little more difficult. However, I was able to use iText to create a PDF form with fields, and only submit the field data back to the server. Offhand, I unfortunately do not remember exactly what/how we did it, but can confirm it is doable (with limitations/caveats). Ex: User had to have PDF reader plugin installed & User was forced to d/l the pdf every time.
Basically what I did was use iText to create an FDF from a PDF (with form existing form fields). The submit button in the FDF actually submits the form data to a URL of your choosing (not unlike an HTML form). Once you have that data, I believe I merged the form fields (from the FDF) with the PDF on the server side using iText.
Once you use the server to maintain all the form data, the synchronization/locking process you use to ensure that a single user is updating the latest and greatest form data is up to you.
Your comment under jowierun indicates that you want to deal with word/excel/etc docs as well, so I am not entirely sure I am understanding your needs. Your initial post discussed the needs to fill out PDF forms locally, but afterwards it sounds like you are looking for a file-sharing system instead.
Can you please clarify exactly what you are trying to accomplish?

Regarding Print options in web application

I want to give print options in our web application..We are using technologies like spring 3.0,hibernate3.0 and mysql database..What i want is single file ,multiple file print options..When i select check box perticular file after click print button it should go to the printer...Please give some example related to this print options using technologies like Spring,hibernate and mysql database..
Thanks in advance
There are many ways you can go with this, so I'll give you some options to consider:
If you don't care too much about the pixel-perfect formatting, the easiest way is to display a new html document with all the files combined and specify #media print in your CSS for that document. Launch the printer dialog for that document using window.print().
If formatting is very important you may consider rendering a PDF document. iText is a good choice since you're using a Java stack.
If you are in an enterprise environment and know which printers a user can access then you can send Postscript or PDF commands directly to the printer. This is probably the most work but also the most transparent to the user since it can be automated completely.

How to build a simple application which can capture user input and produce a printable output

We need to build the following application:-
User punches in couple of inputs into a form (e.g. customer name, insurance policy information, bank details and the insurance amount). The application is supposed to take a print copy with 3 perforations which contains the above information (one for the customer, insurance agent and the insurance firm)
The end users in this case (insurance agents) are not tech savvy and would like to have an application with the smallest footprint which can be launched from a CD. Also do note that they might not have an internet connection.
We are looking for ideas on frameworks we should use to build this application. Note: We are proficient in java only. Does this application need to be a web application or a simple html with some pdf generation capability. Looking for suggestions here?
If all you need is to enter the information and print the PDF, you can just create a PDF form with editable fields using OpenOffice, no need to code an application for that.
However if you need to save the data, you then can use PDFBox to parse the filled form and put its data into a database later.
Despite the 'web' part of Java Web Start, it might suffice to supply an applet (yes, I did mean applet not application) on the CD that is launched using JWS.
As of Java 1.6.0_10+, applets can be dragged from the web page (on the CD) where they reside. If a dragged applet is configured by JNLP (installed using JWS), it will then install itself into the user's system.
Further, JNLP offers a way for even sand-boxed apps. to use the printer. See my demo. of the JNLP PrintService for more details on that.

Categories

Resources