aspose file tools*
The moose likes Other Java Products and Servers and the fly likes Printing word documents from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Printing word documents from Servlet" Watch "Printing word documents from Servlet" New topic
Author

Printing word documents from Servlet

Abhijit Sontakey
Ranch Hand

Joined: Sep 26, 2005
Posts: 67
Hi,
I have a requirement to print word documents from a servlet. The documents are to be printed at the client printer. User selects a printer to print the document. I am struggling to find a way to connct to the word document from servlet. I also have to add watermarks to the word document before printing. Can anybody help me in this regard. Any code examples will be of great help.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There is nothing in the servlet spec for working with PDF.
Creating and/or altering them from Java apps is done with 3rd party libraries such as Apache FOP or iText.
Inquire in our "Other Open Source Projects" for more information on these libraries.

Printing is something that is handled on the client.
The client will need to open the file in a PDF viewer (such as Adobe Acrobat) and print it from there.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Abhijit Sontakey
Ranch Hand

Joined: Sep 26, 2005
Posts: 67
Hi,
Thanks for the reply. However i have to manipulate word documents and print word documents at the printer selected by the user. itext and FoP are only for PDFs not for Word.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Moving to Other Open Source Projects, where I will give you a couple links I've run into.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This tutorial page from the iText documentation site:
http://itextdocs.lowagie.com/tutorial/general/webapp/
has example code for a servlet that 'silently' prints a PDF:
http://itextdocs.lowagie.com/examples/com/lowagie/examples/general/webapp/SilentPrintServlet.java

I haven't tried it but it might be just what you're looking for.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
LIke Ben says, you won't be able to print to the users printer "from the servlet". Can't you just provide a link to the file, which allows the user to access the document directly, thus allowing him to print it whereever he desires?

As to watermarking a Word document, have a look at the AccessingFileFormats page. The POI, WordApi and (particularly) OpenOffice packages may help with this.
[ September 21, 2006: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing word documents from Servlet