Page 1 of 1

Images not aligning correctly in generated Word documents

PostPosted: Thu Jul 07, 2022 1:20 am
by kb221
For block images which exist in the following html, images are not being aligned to the right in the generated Word document. please notice that if text-align added to parent P element it’ll be aligned so the parser is not able to deal with block images with text align and margin attributes to align the images.

<html xmlns=“http://www.w3.org/1999/xhtml”>
<head></head>
<body>
<p fr-original-style=“” style=“margin: 0px 0px 5px; font-family: Telex, Arial, sans-serif; font-size: 13px; line-height: 18px; height: auto; white-space: normal;“><img src=“http://localhost:8085/rest/get/project/1035/SchoolLogo.png-1655596580588” style=“width: 300px; display: block; vertical-align: top; margin: 5px 0px 5px auto; text-align: right; max-width: 100%; border: 0px; position: relative; cursor: pointer; padding: 0px 1px; user-select: none;” fr-original-style=“width: 300px; display: block; vertical-align: top; margin: 5px 0px 5px auto; text-align: right;” fr-original-class=“fr-draggable” /></p>
<p fr-original-style=“” style=“margin: 0px 0px 5px; font-family: Telex, Arial, sans-serif; font-size: 13px; line-height: 18px; height: auto; white-space: normal;“><br fr-original-style=“” style=“margin: 0px;” /></p>
</body>
</html>

Any help with this issue would be much appreciated...

Re: Images not aligning correctly in generated Word document

PostPosted: Mon Jul 11, 2022 10:01 am
by jason
If I open your html in Chrome, it aligns the image to the left...

Re: Images not aligning correctly in generated Word document

PostPosted: Tue Jul 12, 2022 5:07 am
by kb221
That's very odd. It's aligning the image to the right for me. I'm using Chrome too.

Re: Images not aligning correctly in generated Word document

PostPosted: Tue Oct 04, 2022 12:31 am
by kb221
The image in the html below displays to the right in chrome. I tried to update the html and add text-align to the right to parent <P> element. It’s displayed right in chrome and in generated Word and PDFs but if margins are used in the <img> itself to control alignment it only works in chrome, not the generated documents. I think margin values are correct because I can control the right value by setting it to 0 pixels and setting the left value to auto.

Why does the margin setting not work correctly in the generated Word and PDF documents?

<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<p fr-original-style="" style="margin: 0px 0px 5px; font-family: Telex, Arial, sans-serif; font-size: 13px; line-height: 18px; height: auto; white-space: normal;"><img src="IMG_0587.jpg" style="width: 300px; display: block; vertical-align: top; margin: 5px 0px 5px auto; text-align: right; max-width: 100%; border: 0px; position: relative; cursor: pointer; padding: 0px 1px; user-select: none;" fr-original-style="width: 300px; display: block; vertical-align: top; margin: 5px 0px 5px auto; text-align: right;" fr-original-class="fr-draggable" /></p>
<p fr-original-style="" style="margin: 0px 0px 5px; font-family: Telex, Arial, sans-serif; font-size: 13px; line-height: 18px; height: auto; white-space: normal;"><br fr-original-style="" style="margin: 0px;" /></p>
</body>
</html>

Re: Images not aligning correctly in generated Word document

PostPosted: Thu Oct 20, 2022 10:51 am
by jason
There are 2 types of images in Word, 1 inline and 2 anchored.

An anchored image is similar to HTML float.

ImportXHTML's XHTMLImageHandlerDefault creates inline images.

Things work as expected when you add text-align right to the parent <P> element, because when you set this on a paragraph in Word, any inline image in that paragraph inherits the value.

Setting it on the image itself does not translate across that neatly, because in Word, the alignment is a paragraph level property.

What exactly are you trying to achieve? Do your image paragraphs sometimes also contain text?

It helps to know what the corresponding image would be in Word. I'm not sure that you can put a margin around an inline image? To achieve a margin-like effect around an image it may need to be anchored. Word does seem to swap to making the image anchored.

Once you know the mapping between your XHTML and an appropriate structure in Word, then to implement that, XHTMLImageHandlerDefault can be extended or replaced.