• Post Reply Bookmark Topic Watch Topic
  • New Topic

PDF StreamInfo is always empty  RSS feed

 
Jules Bach
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

I'm completely stuck on this, any advice would be appreciated.

I am using a struts Download action to handle downloading a PDF file to the client machine. The PDF file is generated on the fly.
I used a similar approach for handling CSV files, which worked fine.

I have imported the following packages:

import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfWriter;

The code compiles/runs..however, the PDF file is always empty. No content gets added.

Below is my code with simplified doc contents.



I have tried looking through other threads, google etc. but I can't find a working example of using a struts download action (like mine above) with PDF documents.
Have I missed something obvious why my downloaded PDF document is always empty?

Thanks,

Jules




 
Jules Bach
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worked it out in the end...it was the the toString() on the return stream.

this was the offending line:



fixed now with:



using my modified stream test method:



toString() worked fine with the CSV, silly mistake I guess in hindsight to assume it would be the same for PDF.

Jules
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, unlike CSV, PDF files are binary, not text, so "toString" can't be applied to them.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!