PDF is to be regarded as a binary file type. Therefore, if you convert the byte array to a String and work on it using Readers and Writers you kill the file integrity. Instead of a ByteArrayOutputStream, simply use a FileOutputStream to write directly to the file and it'll work.
http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleXML2PDF.java?rev=1.10 On 12.10.2004 12:27:27 Eldho George wrote: > > Hai all > > The following is my code snippet. I want to create a pdf file using fop > output. > But it is not working .i am trying to open that pdf with adobe acrobat 6.0. > It showing some message like this is not a supported file type or the file > has been corrupted. > Please tell me where i made mistake.How can i use the content of byte array > to > make pdf file > > driver.setLogger(logger); > driver.setRenderer(Driver.RENDER_PDF); > > //make xml and xsl stream > Source xmlSrc = new StreamSource(new StringReader(xml)); > > Source xslSrc = new StreamSource(new StringReader(xsl)); > > ByteArrayOutputStream outStream = new ByteArrayOutputStream(); > //Setting driver ouput stream > driver.setOutputStream(outStream); > > //parsing the xml stream using sax parser > TransformerFactory tf = TransformerFactory.newInstance(); > Transformer transformer = tf.newTransformer(xslSrc); > Result result = new SAXResult(driver.getContentHandler()); > transformer.transform(xmlSrc, result); > > byte[] content = outStream.toByteArray(); > > String pdfFileContent=content.toString(); > File file=new File("c:/Samp.pdf"); > FileWriter writer=new FileWriter(file); > > BufferedReader br=new BufferedReader(new StringReader(pdfFileContent)); > String str=""; > while((str=br.readLine())!=null) > { > writer.write(str); > } > writer.close(); Jeremias Maerki --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]