Page 1 of 1

DOCX to FO with Images

PostPosted: Fri Mar 02, 2012 2:01 am
by jcizzle
Hi,

I've been converting DOCX files to XML-FO using the available code, however none of the images in the original document get converted. There appears to be code to support images, and I've tried with GIF, JPG and PNG.

During conversion I see the following exceptions in the log:
Code: Select all
java.lang.NoSuchMethodException: For extension function, could not find method static org.docx4j.model.images.WordXmlPictureE10.createXslFoImgE10([ExpressionContext,] #UNKNOWN (org.docx4j.openpackaging.packages.WordprocessingMLPackage), #STRING, #NODESET, #UNKNOWN (java.util.HashMap)).
   at org.apache.xalan.extensions.MethodResolver.getMethod(MethodResolver.java:276)


From what I can gather the second input is for the image handler which is of type ConversionImageHandler, but the type it's using is String. From the docx2fo.xslt it wasn't clear where the $imageHandler is being created. Could this be an issue with my classpath, any help on this would be appreciated. If this might be a bug, I'd be happy to look into trying to come up with a fix but would need a push in the right direction where to start looking at why the imageHandler is different to the expected type.

Re: DOCX to FO with Images

PostPosted: Fri Mar 02, 2012 8:35 pm
by jason
Images (both E10 - which are Word 2003 images, and E20) work for me. So:

- Which version of docx4j are you using? (try the most recent nightly at http://www.docx4java.org/docx4j/ )

- Can you post a short sample docx which exhibits the problem?

Re: DOCX to FO with Images

PostPosted: Sat Mar 03, 2012 1:08 am
by jcizzle
I was using docx4j 2.7.1 with the exact same JAR's from http://www.docx4java.org/docx4j/docx4j-2.7.1/ (Including all the other dependency jars), I've been running it in Eclipse. I've just tried with docx4j-nightly-20120212.jar and I still get this. I've created a new test case with a single image in it.

This is the exception that I'm getting with this file:
Code: Select all
Caused by: java.lang.NoSuchMethodException: For extension function, could not find method static org.docx4j.model.images.WordXmlPictureE20.createXslFoImgE20([ExpressionContext,] #UNKNOWN (org.docx4j.openpackaging.packages.WordprocessingMLPackage), #STRING, #NODESET, #UNKNOWN (java.util.HashMap)).
   at org.apache.xalan.extensions.MethodResolver.getMethod(MethodResolver.java:276)
   at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:321)

Re: DOCX to FO with Images

PostPosted: Sat Mar 03, 2012 7:47 am
by jason
Hi, your docx contains:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
        <w:drawing>
          <wp:inline distT="0" distB="0" distL="0" distR="0">
            <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
              <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


which is handled by docx2fo.xslt's E20 code:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
                <xsl:when test="./a:graphic/a:graphicData/pic:pic">
               
                        <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPictureE20.createXslFoImgE20(
                                        $wmlPackage, $imageHandler,
                                        $wpinline, $modelStates)" />
          
                </xsl:when>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


In contrast, the XSLT E10 code is only entered when:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
                <xsl:when test="./v:shape/v:imagedata">

                <xsl:variable name="wpict" select="."/>
                       
                        <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPictureE10.createXslFoImgE10(
                        $wmlPackage, $imageHandler,
                        $wpict, $modelStates)" />

                </xsl:when>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


I expect this test docx will actually work for you (as it does for me). Could you try producing another? If you can only do it with sensitive content, you can email me off list if you like.

Re: DOCX to FO with Images

PostPosted: Sat Mar 03, 2012 10:31 am
by jcizzle
Hi Jason, thanks for the response, as it's working for you, but not me I decided to take my test out of Eclipse and run the command manually. Doing this worked, so there must be something wrong with my Eclipse project, I'll investigate!

James