Announcement

Collapse
No announcement yet.

Problems with PDFBox in MirthConnect 3.2.1

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with PDFBox in MirthConnect 3.2.1

    Hi,

    I just made some tests with the current 3.2.1.7650 release.

    I have a channel that converts PDFs to DICOM Files.
    E.g. a secondary capture multiframe DICOM object, which works very very well. Well at least since 3.1.

    Since the update, I get an error when doing the following:

    Code:
    bais = new java.io.ByteArrayInputStream(FileUtil.decode($('FileContent'))) 
    pddoc = new org.apache.pdfbox.pdmodel.PDDocument.load(bais) // class from PDFBOX from pache
    pages = pddoc.getDocumentCatalog().getAllPages() 
    
    var InstanceNumber = 1 // number of the image for this series
    
    var singlePage = pages.get(0) //new org.apache.pdfbox.pdmodel.PDPage()
    buffImage = singlePage.convertToImage(1,200) // scna the PDF page to buffered image
    // get image meta data
    var imageColorComponents = buffImage.getColorModel().getNumColorComponents()
    var imageHeight = buffImage.getHeight()
    var imageWidth = buffImage.getWidth()
    var bitsPerPixel = buffImage.getColorModel().getPixelSize()
    var bitsAllocated = bitsPerPixel / imageColorComponents
    var samplesPerPixel = imageColorComponents
    The error looks like this:
    Code:
    Transformer error
    ERROR MESSAGE: Error evaluating transformer
    java.lang.NoClassDefFoundError: org/apache/fontbox/afm/AFMParser
    	at org.apache.pdfbox.pdmodel.font.PDFont.addAdobeFontMetric(PDFont.java:144)
    	at org.apache.pdfbox.pdmodel.font.PDFont.getAdobeFontMetrics(PDFont.java:113)
    	at org.apache.pdfbox.pdmodel.font.PDFont.<clinit>(PDFont.java:105)
    	at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:108)
    	at org.apache.pdfbox.pdmodel.PDResources.getFonts(PDResources.java:204)
    	at org.apache.pdfbox.util.PDFStreamEngine.getFonts(PDFStreamEngine.java:604)
    	at org.apache.pdfbox.util.operator.SetTextFont.process(SetTextFont.java:54)
    	at org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:554)
    	at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:268)
    	at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:235)
    	at org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:215)
    	at org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:127)
    	at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:801)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)
    	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:225)
    	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1473)
    	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:815)
    	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:109)
    	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
    	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
    	at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:120)
    	at com.mirth.connect.server.util.javascript.JavaScriptTask.executeScript(JavaScriptTask.java:68)
    	at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.call(JavaScriptFilterTransformer.java:142)
    	at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.call(JavaScriptFilterTransformer.java:118)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: org.apache.fontbox.afm.AFMParser
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	... 32 more
    so what happens:
    • $('FileContent') is the base64 encoded string of a PDF
    • that PDF is read into a byte array input stream
    • that stream is loaded by the PDDocument class from PDFBox
    • then a catalogue with all pages is created
    • then the properties of the first page are read out and stored


    I use pdfbox-app-1.8.5.jar in the custom-lib folder.
    However, I just found the 1.8.4 version of pdfbox in the extensions\doc\lib of mirthconnect.
    Do these two versions exclude each other?
    I just read the api documentation and my function should also work with 1.8.4.

    What could have caused that difference from going to version 3.2.1 of mirthconnect?

    When searching the error, many results are pointing out that the fontbox-1.8.X.jar might be missing. In my lib (pdfbox-app-1.8.5.jar), all dependencies are included already. If I now put the fontbox lib in my custom lib folder, it has no effect at all.

    I'm kind of lost right now and don't know how to fix this.

    thanks in advance!

  • #2
    In 3.2, libraries in custom-lib no longer get included with the overall server classpath. They are still available for use in JavaScript contexts and certain other places like Database/JMS/WS connectors though, via the new Resources settings tab.

    Because of that, you may be running into an issue where the overall server classloader has access to some 1.8.4 classes, but you're also including 1.8.5 in the JavaScript-specific classloader. So it looks like a conflict of some kind.

    PDFBox is a library used internally by Mirth Connect (via the Document Writer). If you like you can replace the JAR in extensions/doc/lib with your newer version (and the -app JAR so it has FontBox). Then restart the Mirth Connect server. That way there should no longer be any conflicts. Note that whenever you upgrade Mirth Connect you'll have to do the same process, because those internal library directories will be replaced.
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


    - How do I foo?
    - You just bar.

    Comment


    • #3
      EUREKA!

      it worked, thank you so much! I didn't knew the change in the custom-libs. Should read the new notifications and the changelog mor often

      thank you!

      Comment


      • #4
        Sorry to revoke this but somehow it ain't working no more.

        So what I basically did the last time was just using this code:
        Code:
        bais = new java.io.ByteArrayInputStream(FileUtil.decode($('FileContent'))) 
        pddoc = new Packages.org.apache.pdfbox.pdmodel.PDDocument.load(bais) // class from PDFBOX from pache
        pages = pddoc.getDocumentCatalog().getAllPages()
        If you compare it to my first post, only this "Packages." was missing to referr to the custom-lib.

        Anyway, it worked well on my test system. Then I copied everything to another PC, but same Channels etc. but it won't work.

        I now habe the pdfbox-app-1.8.10 included in custom-lib.
        When I check the resource-settings > [Default Resources] I can see pdfbox-app-1.8.10.jar is included.
        So I assume that I can use it like I used to do.
        Anyway, I get the same error again like in the first place.

        Is there a way I can use the command "import" or "package" in the editor to include libs?

        I have no clue how to solve this puzzle.
        By just replacing the pdfbox in "extensions\doc\lib" nothing happend. Even worse, I wasn't able to write documents anymore.

        Comment


        • #5
          Hi,

          I know it is a little bit old thread but it is referring to problems with PDFBox versions of jars.
          Earlier this month version 2 was released. There are a lot of differences between version 2 and 1.8.X.
          I would like to use version 2 with custom-lib but it is not working and there is no way to replace 1.8 with 2 in /doc/lib
          What do you suggest to do?

          BTW similar is with itext (there is version 5 available but I think there can be some problem with licensing)
          Last edited by reymed; 03-29-2016, 03:07 AM.

          Comment


          • #6
            Originally posted by reymed View Post
            Hi,

            I know it is a little bit old thread but it is referring to problems with PDFBox versions of jars.
            Earlier this month version 2 was released. There are a lot of differences between version 2 and 1.8.X.
            I would like to use version 2 with custom-lib but it is not working and there is no way to replace 1.8 with 2 in /doc/lib
            What do you suggest to do?

            BTW similar is with itext (there is version 5 available but I think there can be some problem with licensing)
            Hi,

            I solved my issue like described below. I think it should work out for you, too. But of course there might be problems due to new versions and changes of behaviours within the functions.

            1. Copy your new libs into ...\extensions\doc\lib
            2. open ...\extensions\doc\destionation.xml with Notepad or another Texteditor
            3. replace and/or add your libs in that file

            Comment

            Working...
            X