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!