Page 1 of 1

Images get scaled up after converting html to docx

PostPosted: Thu Sep 13, 2018 2:23 am
by carlos
Hi everybody,
I'm facing the following issue, maybe someone can help me.
I'm converting html to docx. In the Html i have some images e.g <img src="image1.jpg" width="350" height="400" ..>
The conversion is successful in general but images get scaled up in the generated docx file.
I converted the width and height in pixels from the <img ... to cm, to compare them with the height and width in cm in the word file(The measures are bigger.). It seems docx4j is not converting properly. Or i need to add sth?


Im using :
wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(value, "file:/"+path.toString()+"/"+documentId));


Please, i would appreciate your help!
Thanks in advanced!

Re: Images get scaled up after converting html to docx

PostPosted: Thu Sep 13, 2018 8:48 am
by jason

Re: Images get scaled up after converting html to docx

PostPosted: Fri Sep 14, 2018 9:12 pm
by carlos
Hi Jason,
Thanks a lot for answering!
I solved my issue by deleting width and height from the tag <img> before generating my docx file.
Additionally i added this line Docx4jProperties.getProperties().setProperty("docx4j.DPI", "300"); and worked like a charm.
Nevertheless, with this workaround. I'm not able to resize my images in my editor (tinymce) since i will always upload the images in original size.
If you could please give me another clue, i would appreciate it a lot! :)
By the way, I'm facing another problem. When converting html to docx, some left margin is being added to the document. That means, for every time i saved my html in order to convert it to docx, a margin gets added.
Just to clarify: let' s suppose i have this paragraph:
1st time
(0 whitespace)Hello World

2nd time
(1 whitespace) Hello World

3rd time
(2 whitespaces) Hello World

and so on. I'd be really thankful if you could really help me.
Thanks in advance!
Carlos

Re: Images get scaled up after converting html to docx

PostPosted: Fri Sep 14, 2018 11:13 pm
by carlos
Hi Jason, every time i converted my html to docx indentation changes. :(

1st time
<w:p>
<w:pPr>
<w:spacing w:after="227" w:line="276"/>
<w:ind w:left="38"/>
<w:jc w:val="left"/>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial"/>
<w:b/>
<w:i w:val="false"/>
<w:color w:val="000000"/>
</w:rPr>
<w:t>AM-2018-18</w:t>
</w:r>
</w:p>

2nd time

<w:p>
<w:pPr>
<w:pStyle w:val="Normal"/>
<w:spacing w:after="230" w:line="276"/>
<w:ind w:left="95"/>
<w:jc w:val="left"/>
</w:pPr>
<w:r>
<w:rPr>
<w:rStyle w:val="DefaultParagraphFont"/>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial"/>
<w:b/>
<w:color w:val="000000"/>
<w:shd w:fill="33cccc"/>
</w:rPr>
<w:t>AM-2018-18</w:t>
</w:r>
</w:p>

3rd time
<w:p>
<w:pPr>
<w:pStyle w:val="Normal"/>
<w:spacing w:after="230" w:line="276"/>
<w:ind w:left="151"/>
<w:jc w:val="left"/>
</w:pPr>
<w:r>
<w:rPr>
<w:rStyle w:val="DefaultParagraphFont"/>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial"/>
<w:b/>
<w:color w:val="000000"/>
<w:shd w:fill="33cccc"/>
</w:rPr>
<w:t>AM-2018-18 </w:t>
</w:r>
</w:p>

Re: Images get scaled up after converting html to docx

PostPosted: Thu Sep 20, 2018 9:59 am
by jason
What is the input XHTML in each case?