Page 1 of 1

docx4j-ImportXHTML (flying saucer fork) image size problem

PostPosted: Thu Mar 24, 2016 3:10 am
by solid
I am having a problem with image size in docx4j-ImportXHTML (the flying saucer fork). It seems to not handle image size from style the same. I chose docx4j because the library has a PDF conterpart (flying saucer) that can use the same html template to render either. For the most part, it does work but for images it seems to ignore the styles for size causing the images to not scale and be pushed past the edge of the document. The flying saucer (PDF) version doesnt do this just docx4j-ImportXHTML.

I have attached a project that has a simple html file (<20 lines) and a unit test that renders that file as both pdf and docx, using flying saucer and docx4j-ImportXHTML respectively. You can review the output documents in the target directory for comparison. The PDF appears right while the docx file appears to ignore my image sizes. BTW I am using inches and cm as the image size units but it does not seem to matter if I convert them to pixels either unless I assume a ridiculous DPI (like 600!) which breaks the PDF rendering.

-Matt
related: docx-java-f6/image-size-differs-when-pdf-and-docx-are-generated-t2367.html

Re: docx4j-ImportXHTML (flying saucer fork) image size probl

PostPosted: Sun Mar 27, 2016 12:56 pm
by jason
Hi Matt

I haven't looked into this in any detail.

The text below is something I wrote to someone else a month or so ago. Perhaps you could review that, then post again as necessary?

cheers .. Jason

https://github.com/plutext/docx4j-Impor ... java#L1504 is the start of image handling

You can see that the code there determines a size for the image based on the size of the box (think xhtml div) containing it.

If those values are null, the image is inspected to determine/use its intrinsic size:

https://github.com/plutext/docx4j-Impor ... .java#L103

Note that the code in the first reference above was introduced by https://github.com/plutext/docx4j-Impor ... dad0e489c8

That commit included https://github.com/plutext/docx4j-Impor ... dTest.java

Note the ways of specifying image height/width.

Note this code isn't in docx4j-ImportXHTML-3.2.2, you'll need to build it from source.

Finally, xhtml-import-f28/library-question-t2249.html may also be of interest

Re: docx4j-ImportXHTML (flying saucer fork) image size probl

PostPosted: Sat Apr 02, 2016 1:33 am
by solid
Any Idea when the next version will be released (made available in maven central specifically). We may be able to wait and our organization has a problem with running thirdparty libs compiled internally.