This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing word documents from Servlet

 
Abhijit Sontakey
Ranch Hand
Posts: 67
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhijit Sontakey
Ranch Hand
Posts: 67
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Other Open Source Projects, where I will give you a couple links I've run into.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic