I'm using fop in a servlet to render pdf from a jdom document and an xsl
stylesheet.
It works fine if I write the pdf to a file, but if I write it back to the
HttpResponse object I get a mime type of "application/octet-stream" even
though I'm setting it to "application/pdf"
code snippets follow:
from servlet.doGet method
-----------------------------------------------------------
jdom.Document dataxml = XmlTools.getDocument(xml);
PdfRenderer Pdf = new PdfRenderer(xsl);
response.setContentType("application/pdf");
OutputStream os = response.getOutputStream();
Pdf.writePdf(dataxml, os);
from PdfRenderer.java
---------------------------------------------------------------
public class PdfRenderer {
private File XsltFile;
private Driver driver;
private Transformer transformer;
public PdfRenderer(URL xsltUrl)throws Exception {
InputStream is = xsltUrl.openStream();
Source xsltSrc = new StreamSource(is);
setup(xsltSrc);
}
private void setup(Source xsltSrc)throws TransformerConfigurationException
{
driver = new Driver();
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
driver.setLogger(logger);
driver.setRenderer(Driver.RENDER_PDF);
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer(xsltSrc);
}
public void writePdf(Document doc, OutputStream os) throws Exception {
writePdf(new JDOMSource(doc), os);
}
private void writePdf(Source data, OutputStream pdfos)throws
TransformerException {
driver.setOutputStream(pdfos);
Result res = new SAXResult(driver.getContentHandler());
transformer.transform(data, res);
}
---------------------------------------------------------------------------
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
---------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]