I'm trying to develop a PDF using Apache FOP and Java. I'm utilizing a valid xsl-fo file that we can produce a pdf with while using command line FOP.

My problem happens after i attempt to run FOP while using Apache FOP Libraries. Running across a java/php bridge. The bride to be is correctly set up and java / php communicate. Around the java side I've got a function that can take inside a string that contains xsl-fo and returns a String which consists of a pdf. After I execute this function and redirect the output to stdout then to file for, or over the java / php bridge, the pdf seems blank and it is dimensions are roughly double those of the right pdf which i retrieve via command line. I suppose I'm getting some type of encoding problem.

Has anybody seen this problem before?

Here's my java code

public String ConvertFoToPdf(String fo) {

// Will contain the results after the transformation. ByteArrayOutputStream out = new ByteArrayOutputStream(); // Input string StringReader sr = new StringReader(fo); // Should be UTF-8; String strEncoding = Charset.defaultCharset().name(); // Resulting string. String pdfResult = ""; try { // Get an instance of the fop factory FopFactory fopFactory = FopFactory.newInstance(); FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); // Construct fop with desired output format Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); // Setup JAXP using identity transformer TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); // Setup input stream Source src = new StreamSource(sr); // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); // Set the encoding on the transformer. transformer.setOutputProperty(OutputKeys.ENCODING, strEncoding); // Start XSLT transformation and FOP processing transformer.transform(src, res); // Put the byte array stream into a string pdfResult = out.toString(strEncoding); } // Catch all exceptions for simplicities sake. catch (Exception e){ // Log } return pdfResult; }</pre></code>