Hi list,

I have a problem with font encoding that I was not able to find a solution in 
the list archive. This is MacOSX with Java SE6 and FOP 1.0. Please bear with me 
as I am new to XSLT and FOP.

The following character does not make it into to final PDF: → (Unicode #8594). 
The input XML is generated correct, showing the correct char when dumping to 
Eclipse console with System.out.println(myXML), encoding is UTF-8, the XSL is 
correctly set to UTF-8. However the resulting PDF shows a # instead of the 
desired character. Analysis of the PDF with Acrobat shows that the text is 
encoded ANSI with font Helvetica. How can I specify UTF-8? Helvetica does have 
the correct arrow char as pasting the XML file into BBEdit set to 
UTF-8/Helvetica also shows the correct character. Capturing the intermediate fo 
data and dumping it to Eclipse console also shows everything as it should be.

I use the following code to generate the resulting PDF byte[]. The code is 
right from the examples section on xmlgraphics.apache.org/fop/1.0/embedding. 
The data is then downloaded as PDF to the browser.

Thanks for any help
---markus---

   private byte[] xml2pdf(URL xslt, String xml ) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
                // Setup input and output files
                File xsltfile = new File(xslt.getPath());
                // configure fopFactory as desired
                FopFactory fopFactory = FopFactory.newInstance();
                FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
                // configure foUserAgent as desired
                try {
                        // Construct fop with desired output format
                        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, 
foUserAgent, out);
                        // Setup XSLT
                        TransformerFactory factory = 
TransformerFactory.newInstance();
                        Transformer transformer = factory.newTransformer(new 
StreamSource(xsltfile));
                        // Set the value of a <param> in the stylesheet
                        transformer.setParameter("versionParam", "2.0");
                        // Setup input for XSLT transformation
                        Source src = new StreamSource(new StringReader(xml));
                        // Resulting SAX events (the generated FO) must be 
piped through to FOP
                        Result res = new SAXResult(fop.getDefaultHandler());
                        // Start XSLT transformation and FOP processing
                        transformer.transform(src, res);
                } 
                finally {
                        out.close();
                }
        } 
        catch (Exception e) {
                e.printStackTrace(System.err);
        }
                return out.toByteArray();
    }
 

Reply via email to