1

I was using the package for a while now and it was working fine. After the update to the latest Package the code broke.

After initializing the factory with some default constructor I get an error:

'org.apache.fop.render.ImageHandlerRegistry' threw an exception.

Anyone got an idea how the configuratin should look like so it will work again?

    public string GeneratePdf(string foFile, string pdfFile)
    {
        OutputStream os = new BufferedOutputStream(new FileOutputStream(new java.io.File(pdfFile)));
        string ret = "";
        try
        {
            // Factory before update
            FopFactory fopFactory = FopFactory.newInstance();
            // After the update the Factory needs some sort of configuration
            // I tryed with all the constructors but can't get the sample to work.
            FopFactory fopFactory = FopFactory.newInstance(null);
            Fop fop = fopFactory.newFop("application/pdf", os);
            FOUserAgent foUserAgent = fop.getUserAgent();
            javax.xml.transform.TransformerFactory factory = javax.xml.transform.TransformerFactory.newInstance();
            javax.xml.transform.Transformer transformer = factory.newTransformer();
            javax.xml.transform.Source src = new javax.xml.transform.stream.StreamSource(new java.io.File(foFile));
            javax.xml.transform.Result res = new javax.xml.transform.sax.SAXResult(fop.getDefaultHandler());
            transformer.transform(src, res);

            ret = pdfFile;
        }
        catch (Exception ex)
        {
            throw ex;
        }

        finally
        {
            os.close();
        }
        return ret;
    }
Jester
  • 3,069
  • 5
  • 30
  • 44

2 Answers2

0

The actual source of the problem was probably not the upgrade of the crispin, but of the IKVM 8 dependency package, https://stackoverflow.com/a/30887042/993388 seems to describe a similar problem.

After I have downgraded IKVM back from 8.x to 7.x, the problem was gone. Also make sure to remove or adjust any binding redirects to IKVM 8.x from App.Config, otherwise the runtime could still try to grab the newer assemblies.

This is only a workaround, but it is the best I could find at the moment.

Community
  • 1
  • 1
swalex
  • 3,885
  • 3
  • 28
  • 33
0

Old question but, this works for me:

var jFopFactory = org.apache.fop.apps.FopFactory.newInstance(new java.net.URI("."));

I have not tried with any images or other resources though.

mevtagezer
  • 77
  • 7