Render PDF in webapp?

Help
Anonymous
2012-08-11
2013-07-24

  • Anonymous
    2012-08-11

    Hello,

    Has anyone ever had any success using JPod Renderer in a web application?

    I am able to render pdfs through a local applet, but I am only able to render a single logo on a PDF in a webapp within a Tomcat7 container. Which leads me to believe there are invalid classpath references, Tomcat security constraints are preventing native code execution, or the FreeType libraries need re-compiled.

    I've tried:
    1. Installing FreeType and manually loading the FreeType library through NativeLibrary.addSearchPath("freetype", path));
    2. Making sure that grant permission java.security.AllPermission in the catalina.policy.
    3. Trying different versions of the JPod libraries as well thrid-party dependencies.

    Code:

    CSPlatformRenderer renderer = new CSPlatformRenderer(null, graphics);
    renderer.process(content, page.getResources());
    

    Latest Stack Trace for calling:
    2012-08-10 23:10:05,055  ERROR StackTrace  - Full Stack Trace:
    java.lang.ExceptionInInitializerError
    at de.intarsys.nativec.type.NativeReference.<clinit>(Unknown Source)
    at de.intarsys.cwt.freetype.Freetype.initFreeType(Unknown Source)
    at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeFontFactory.getLibrary(Unknown Source)
    at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeFontFactory.createPlatformFont(Unknown Source)
    at de.intarsys.pdf.platform.cwt.rendering.CSPlatformDevice.textSetFont(Unknown Source)
    at de.intarsys.pdf.content.CSDeviceBasedInterpreter.render_Tf(Unknown Source)
    at de.intarsys.pdf.content.CSInterpreter.process(Unknown Source)
    at de.intarsys.pdf.content.CSInterpreter.process(Unknown Source)
    at de.intarsys.pdf.content.CSDeviceBasedInterpreter.process(Unknown Source)
    at de.intarsys.pdf.content.ICSInterpreter$process.call(Unknown Source)
            … 177 more
    2012-08-10 23:10:05,059  ERROR StackTrace  - Full Stack Trace:
    java.lang.NullPointerException
    at de.intarsys.nativec.type.NativeSimple.<init>(Unknown Source)
    at de.intarsys.nativec.type.NativeVoid.<init>(Unknown Source)
    at de.intarsys.nativec.type.NativeVoidType.createNative(Unknown Source)
    at de.intarsys.nativec.type.NativeVoid.<clinit>(Unknown Source)
    at de.intarsys.nativec.type.NativeReference.<clinit>(Unknown Source)
    at de.intarsys.cwt.freetype.Freetype.initFreeType(Unknown Source)
    at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeFontFactory.getLibrary(Unknown Source)
    at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeFontFactory.createPlatformFont(Unknown Source)
    at de.intarsys.pdf.platform.cwt.rendering.CSPlatformDevice.textSetFont(Unknown Source)
    at de.intarsys.pdf.content.CSDeviceBasedInterpreter.render_Tf(Unknown Source)
    at de.intarsys.pdf.content.CSInterpreter.process(Unknown Source)
    at de.intarsys.pdf.content.CSInterpreter.process(Unknown Source)
    at de.intarsys.pdf.content.CSDeviceBasedInterpreter.process(Unknown Source)
    at de.intarsys.pdf.content.ICSInterpreter$process.call(Unknown Source)
    2012-08-10 23:10:05,238  ERROR StackTrace  - Full Stack Trace:
    java.lang.NoClassDefFoundError: Could not initialize class de.intarsys.nativec.type.NativeReference
    at de.intarsys.cwt.freetype.Freetype.initFreeType(Unknown Source)
    at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeFontFactory.getLibrary(Unknown Source)
    at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeFontFactory.createPlatformFont(Unknown Source)
    at de.intarsys.pdf.platform.cwt.rendering.CSPlatformDevice.textSetFont(Unknown Source)
    at de.intarsys.pdf.content.CSDeviceBasedInterpreter.render_Tf(Unknown Source)
    at de.intarsys.pdf.content.CSInterpreter.process(Unknown Source)
    at de.intarsys.pdf.content.CSInterpreter.process(Unknown Source)
    at de.intarsys.pdf.content.CSDeviceBasedInterpreter.process(Unknown Source)
    at de.intarsys.pdf.content.ICSInterpreter$process.call(Unknown Source)

    Yes, I know that is just about useless but I'm about to whits end..

    If' you've gotten the JPod Renderer library working in a webapp, could please explain?

     

  • Anonymous
    2012-08-11

    Well, I am able to successfully render the PDFs with an external jar call and pipe the result back into webapp service.. I'm still curious if anyone has had any luck with Jpod Renderer within a webapp and what configuration needs to be performed.

     
  • Elfi Heck
    Elfi Heck
    2012-08-15

    Do the tomcat logs say anything? If tomcat refuses to load something it should say so in the logs (you might have to increase the logging detail for this).
    I will check if what you're trying to do works for us.

     
  • Elfi Heck
    Elfi Heck
    2012-08-15

    OK, here's what I did:
    - download Tomcat 7 from Apache
    - create a webapp with one simple test servlet
    - put the jars from the sourceforge download in the webapp's lib dir
    - put the code from one of the rendering examples in the test servlet class
    Works like a charm. Can you try just these steps?

     
  • (not OP here) I think this happens when there is a different version of jna.jar in use somewhere. I think i have a similar problem with my webapp (based on Grails and Tomcat). I've setup a standalone Java Application, which works fine as long as I use the shipped jna.jar. When i replace this jna.jar with the one from my project (version 3.2.2 i think), i get similar Errors in the standalone app as well. Is there a way to obtain the isnativec code to adapt it to a newer version of jna.jar?

     
  • Update: JPod uses a newer version (3.2.7 versus 3.2.3 in Grails)
    Update2: Replacing the jar in Grails with the one from JPodRenderer made it work. I hope it doesnt break anything in Grails ;)

     
    Last edit: Alexander Stecker 2013-07-17
  • Elfi Heck
    Elfi Heck
    2013-07-24

    Glad you found a solution. FYI, the isnativec should work with any newer version of the 3.n line of jna. Not sure about 4.0 though. We'll check that sometime.