Ok, I understand the requirement... Seems like a lot of trouble to go through to solve it, but I understand, if that's what the client says to do, you do it.

However, I don't see any good way to do it... Hmm... if I remember correctly, filters fire AFTER a JSP is interpreted, if you set it up as a post-processing filter... in that case, you may be able to take the response stream and find some library that can take it and make a PDF out of it... I think someone else referenced an article detailing using FOP for HTML to PDF... as long as you ensure that the output of your JSP is XHTML, you can skip that step in that tutorial, and go right to PDF generation. Do all this from a filter and I *think* you can do what you need to... I think what you'll have is you do whatever you do now, where the user sees the page to be printed... then, add some Javascript that fires onLoad that opens a new window and sets is href to the mapping that generates that HTML again, but this time with the filter mapped to it. Then do the PDF work in the filter.

The result should be that when the user navigates to that page, they will see the page in the main browser window, and will also get a popup window that, after a second or three, displays the same page in PDF format.

Does that all make sense? It's a fair bit of work, but I'm not sure there's too many alternatives if your client really needs this feature.

Frank

Anjishnu Bandyopadhyay wrote:
Hi Frank,

Thanks for your suggestion.

My actual requirement is to display the print preview of the contents of
the original page in the dynamically generated popup html page. For
this, I am reading the contents of the parent page through "innerHTML"
and outputting the contents in the popup (through document.write).

Now, in IE, by default, the background color is not printed unless you
explicitly set the same in the settings. But our client does not want
each and every user to change the setting manually.

So, they have suggested this approach of sending the data to PDF,
instead of HTML.
With best regards,

Anjishnu.

-----Original Message-----
From: Frank W. Zammetti [mailto:[EMAIL PROTECTED] Sent: Thursday, September 07, 2006 11:34 AM
To: Struts Users Mailing List
Subject: Re: Converting HTML content to PDF

Ah, your doing something even less typical :)

There really is no easy way to do this... once your on the client, about


the only way to generate a PDF would be if the user had Acrobat, or a suitable substitute available, one that exposes a print driver (i.e.,
Print to PDF functionality).

Two options I can think of... first, is there any reason you have to
generate the document on the client?  If not, I would suggest looking at


any of the PDF generation packages out there, iText being the one I've personally used, and do it on the server. You say "open this dynamically generated window". which I take to mean that you pop a new window and write to it. If that's correct, how you would do it instead is open the window, and set its source to an Action, which does the PDF generation. You then write it to the response stream and it will show
up in the window, assuming the user has a suitable plugin installed.

Alternatively, you could generate it on the client, but then send the
result to the server to generate and send back.  This is really a pretty


bad idea IMO, so I'd be going with option A for sure. But again, maybe you have some good reason for doing it on the client, in which case I doubt you'll find many options... *maybe* an applet that could grab the written contents of the document body and generate a PDF, but even that
would be way more work than it needs to be.

Generate on the server, that's the simplest and best answer :)

Frank

Anjishnu Bandyopadhyay wrote:

Hi Frank,




I am generating the HTML page from my JavaScript file through

"document.writeln()";


I want to open this dynamically generated window in a PDF document.




With best regards,


Anjishnu.






-----Original Message-----

From: Frank W. Zammetti [mailto:[EMAIL PROTECTED]

Sent: Thursday, September 07, 2006 11:22 AM

To: Struts Users Mailing List

Subject: Re: Converting HTML content to PDF




Hi,




Setting the content type is not sufficient to generate a PDF... are
you

trying to output a PDF from an existing HTML file, or are you


dynamically generating the HTML?  You say you aren't using JSP, so I'm



thinking your either forwarding to an HTML page, or generating it in


your Action.  While there are HTML to PDF converters, I'm not sure
which



if any could be called from a webapp, and even so, typically
dynamically



generated PDF doesn't make a stop as HTML first, so it might help to


understand a little better what your trying to do to offer some


suggestions.  But, it is definitely more than just the content type.




Frank




Anjishnu Bandyopadhyay wrote:


Hi all,






I am trying to programmatically convert an HTML file to pdf

dynamically;


by setting the content type. But, I am not being able to succeed.



Any pointers regarding the same will be of much use.






Please note that, I am not using a JSP here. (So that, I could be
able


to set the "content" of the "response").






With best regards,



Anjishnu.








**************** CAUTION - Disclaimer *****************


This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended

solely for the use of the addressee(s). If you are not the intended

recipient, please notify the sender by e-mail and delete the original

message. Further, you are not to copy, disclose, or distribute this

e-mail or its contents to any other person and any such actions are

unlawful. This e-mail may contain viruses. Infosys has taken every

reasonable precaution to minimize this risk, but is not liable for any

damage you may sustain as a result of any virus in this e-mail. You

should carry out your own virus checks before opening the e-mail or

attachment. Infosys reserves the right to monitor and review the
content

of all messages sent to or from this e-mail address. Messages sent to
or

from this e-mail address may be stored on the Infosys e-mail system.


***INFOSYS******** End of Disclaimer ********INFOSYS***





--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: [EMAIL PROTECTED]
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to