This isn't exactly an iText-specific question, but so far nobody seems to know the answer.

I create PDFs using iText and save them to files, then I want to stream them to the browser and open using the Acrobat plugin. This works just fine in IE, but in Mozilla 1.5.2 and Firebird 0.6 the Acrobat splash screen appears, but no PDF ever loads. I can view source in Firebird and see that the PDF looks valid. If I open the file manually from the server, it works, so I know the PDF is good.

Has anyone sucessfully streamed PDFs to Mozilla or Firebird?

Here is how I'm currently streaming it:

/**
 * Wait action
 */

package ben.actions;

import org.enhydra.xml.io.DOMFormatter;
import ben.DocumentGenerator;
import ben.bom.Pak;
import ben.html.WaitHTML;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.RandomAccessFile;


public class WaitAction extends Action {


        public static String KEY = "Wait";
        private String clientDir;

public void execute(HttpServletRequest req, HttpServletResponse res) throws Exception {

WaitHTML html = new WaitHTML();

                Pak pak = (Pak)req.getSession().getAttribute("package");
                addHeaderFooter(html, pak, KEY);

DocumentGenerator dg = (DocumentGenerator)req.getSession().getAttribute("dg");

if (dg.notDone()) { // Rendering not complete... Wait some more
new DOMFormatter().write(html, res.getWriter());
return;
}


// Rendering complete, stream file to user

System.out.println("Streaming document: " + dg.getFilename());

res.setContentType("application/pdf");

RandomAccessFile in = new RandomAccessFile(dg.getFilename(), "r");
ByteArrayOutputStream ba = new ByteArrayOutputStream();


javax.servlet.ServletOutputStream out = res.getOutputStream();
res.setHeader("Content-disposition", "inline; filename=temp.pdf");
res.setContentLength((int)new File(dg.getFilename()).length());
byte[] buf = new byte[100];


                int i = in.read(buf);
                while (i != -1) {

                        ba.write(buf, 0, i);
                        i = in.read(buf);
                }

in.close();

                ba.writeTo(out);
                out.flush();

}

}




--
Ben Sinclair
[EMAIL PROTECTED]




-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to