web stats
Problems with PDFBox in MirthConnect 3.2.1 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 04-15-2015, 07:20 AM
gkittlaus gkittlaus is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Posts: 104
gkittlaus is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 04-15-2015, 08:32 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

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.
Reply With Quote
  #3  
Old 04-15-2015, 02:05 PM
gkittlaus gkittlaus is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Posts: 104
gkittlaus is on a distinguished road
Default

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!
Reply With Quote
  #4  
Old 08-13-2015, 06:26 AM
gkittlaus gkittlaus is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Posts: 104
gkittlaus is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 03-29-2016, 04:05 AM
reymed reymed is offline
Mirth Newb
 
Join Date: Nov 2015
Posts: 6
reymed is on a distinguished road
Default

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 at 04:07 AM.
Reply With Quote
  #6  
Old 04-27-2016, 07:53 AM
gkittlaus gkittlaus is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Posts: 104
gkittlaus is on a distinguished road
Default

Quote:
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
Reply With Quote
Reply

Tags
convert, dicom, image, pdf, pdfbox

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 09:51 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation