I generated a PDF report (using iText) that can be
retrieved via an url. Now I am trying to save the PDF
report as a hard copy in our system and email it to
client as an attachment. However, sometimes the hard
copy is blank while sometimes good. It has certain
pages long which appears the data is there, but the
pages are blank. I use the same flow for Excel report
and have no issues. Any suggestions?
Here is the code snippet
//generate the PDF report
Document document = new Document(PageSize.A4, 30, 30,
175, 50);
ByteArrayOutputStream buffer = new
ByteArrayOutputStream();
PdfWriter writer=PdfWriter.getInstance(document,
buffer );
writer.setPageEvent(myPageEvent);
document.open();
document.add(myTables)
document.close();
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] );
}
//retrieve the PDF report via url
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(url);
client.executeMethod(get);
String report = get.getResponseBodyAsString();
//create a file
File f = new File(directory, filename);
FileWriter fw = new FileWriter(f, false);
PrintWriter pw = new PrintWriter(fw);
//output the report to the file
pw.println(report);
pw.flush();
pw.close();
//sometimes the file is blank while sometimes good.
Thank you,
Li
____________________________________________________________________________________Looking
for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
http://farechase.yahoo.com/
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
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/