Sending directly PDF content to the browser

Is it possible to send a PDF stream to the browser without saving it into an attachment?I am using iText to convert XML to PDF.

I want to display the PDF directly in the browser without saving it as an attachment.

This is the code I am using with no success:

ByteArrayOutputStream outputstream = new ByteArrayOutputStream();

PdfWriter writer = PdfWriter.getInstance(document, outputstream);

PrintWriter pw = getAgentOutput();

String outputFile = “pfdfilename.pdf”;

pw.println(“Content-Type:application/pdf; name="”+outputFile+“"”);

pw.print(outputstream);

where outputstream contains the PDF content.

I get a “File download” alert, the file name is the name of the Agent that I was running, and the File type is Adobe Acrobat Control for ActiveX.

When I click on Open, “Window cannot open this file”…

If I remove the

pw.println(“Content-Type:application/pdf; name="”+outputFile+“"”);

instruction, then I get a part of the PDF content in the web browser, as it was plain text.

Anyone can help?

Thanks in advance!

Subject: Sending directly PDF content to the browser

Pass the output stream to PdfWriter, like this:

PdfWriter.getInstance( document, response.getOutputStream() );

Subject: Sending directly PDF content to the browser

I have so far been unable to send a generated PDF to the browser without saving it as an attachement. I remember reading somewhere that the classes available to Java agents weren’t sufficient to send binary content like that directly to the browser so you’d have to attach the file to a document and redirect the browser there. I don’t, however, remember just where I read that, so I’m not sure what the details might be or even if I’m entirely correct on that point.