It works well.
It can also be modified to get the file downloaded from a dialog box instead of viewing in the browser
//
// Template JSP file for iText
// by Tal Liron
//
response.setContentType( "application/pdf" );
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a temporary buffer
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
PdfWriter.getInstance( document, buffer );
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
document.add(new Paragraph("My text"));
// step 5: we close the document
document.close();
// step 6: we output the writer as bytes to the response output
DataOutput output = new DataOutputStream( response.getOutputStream() );
byte[] bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
for( int i = 0; i < bytes.length; i++ ) { output.writeByte( bytes[i] ); }
%>USB ITEXT wrote:
Hi,
I am having problems with displaying the dynamically generated PDF using iText on the browser. I have set the response content length as mentioned in the FAQ section, but the PDF is not getting displayed yet. Could anyone help.
My code is as follows:
PdfReader reader = new PdfReader(new URL(urlString.toString()));
PdfStamper stamp = new PdfStamper(reader, ba);
AcroFields afields = stamp.getAcroFields(); HashMap fieldsHM = afields.getFields();
if ((String) session.getAttribute("txtFirstName") != null) { if ((String) session.getAttribute("txtFirstName") != null) afields.setField( "txtFirstName", (String) session.getAttribute("txtFirstName")); } else { if ((String) req.getParameter("txtFirstName") != null) afields.setField( "txtFirstName", (String) req.getParameter("txtFirstName")); }
stamp.close();
resp.setContentLength(ba.size());
ServletOutputStream out = resp.getOutputStream();
ba.writeTo(out);
out.flush();
I had tried generating the PdfStamper output to "response.getOutputStream()" also, and the same problem.
Thanks in advance.
------------------------------------------------------------------------
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online <http://us.rd.yahoo.com/evt=22055/*http://taxes.yahoo.com/filing.html>
-- Dott. Giuliano Intrito Universita' degli Studi di Napoli "Parthenope" Via Amm. F. Acton, 38 - 80133 Napoli Tel: 0814977112 E-mail: [EMAIL PROTECTED]
------------------------------------------------------- SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now! http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions
