I want to generate PDFs from JSP view pages. Searching on web related topics
I got this mail ID from Manning Publishers site.
*
I have to use only tidy and iText only*
Please give me a help, it is very urgent.
I what I am doing is,
*
Step 1:*
I have no of jsps. I am putting pdf icon on each page and onclick I am
calling JavaScript and then Servlet class.
In the Servlet class I am able to get the JSP output(content) as HTML
content and making it as String.
String htmlFile = request.getParameter("html_input");//html_input will have
the content
*
Step 2:*
Creating ByteArray Streams and passing html string to input stream.
ByteArrayInputStream is = new ByteArrayInputStream(htmlFile.getBytes());
ByteArrayOutputStream os = new ByteArrayOutputStream();
*
Step 3*
Creating iText Document
Document document = new Document();
*
Step 4*
Using tidy, I am doing cleanning the html file
Tidy tidy = new Tidy();
tidy.setTidyMark(false);
tidy.setDocType("auto");
tidy.setWrapScriptlets(true);
tidy.setOnlyErrors(true);
tidy.setXHTML(true);
tidy.setEncloseText(true);
tidy.setXmlTags(true);
*
Step 5*
Parsing the file to DOM and creating new string on output steam
tidy.parseDOM(is, os); *// Here parsing is perfect, but I am not getting
"os" content. os is empty
*
String newString = os.toString(); *// Here since os is empty newString is
empty ie no string.
IS THERE ANY MECHINSM TO DO THIS. IN THE TIDY PARSE I AM GETTING
DOM-DOCUMENT THAT HAS TO BE CONVERT AS STRING
I TRIED TO USE SAX-PARSER ALSO BUT THAT GOING TO COMPLEX. I WANT TO PUT
SIMPLE TECHNIC
*
*
Step 6*
Creating itext Document instance
PdfWriter.getInstance(document, response.getOutputStream());
*
Step 7
*
I am opening the Document
document.open();
*
Step 8
*
Adding the string to Paragraph
document.add(new Paragraph (newString));*// Here I am able to see this
paragraph on PDF page
*
document.add(new Paragraph ("This is test page")); *// This is perfect
Step 9
*
Closing stmts
document.close();
os.close();
*
*
I think this info will help you to figure out my problem....if you any
doubts are suggetion please let me know.
TRY TO HELP ME ASAP.
THANKS IN ADV.
Jade
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/