Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Jan 08, 2025 7:01 am

I have an HTML Editor (TipTap) that I pass to my document export service (document_export.py). I've been able to generate a docx with all the formatting and styles without any issue. The only issue I do have is positioning the image. This first image shows what the TipTap editor presents:
TipTapEditorHTML.png


The second image is the exported DOCX:
ExportedDOCX.png


I'm unsure as to why this is happening. I've tried several ways to handle the image, including this method:

Code: Select all
def _insert_image_to_paragraph(self, paragraph: object, image_path: str, width: int = None, height: int = None, alignment: str = None):
        """Insert an image into a paragraph with specified properties"""
        picture = paragraph.AppendPicture(image_path)
        # Set size if specified
        if width:
            picture.Width = width
        if height:
            picture.Height = height

        # Set alignment and wrapping
        if alignment == 'left':
            picture.TextWrappingStyle = TextWrappingStyle.Square
            picture.DistanceFromText.Left = 0
            picture.DistanceFromText.Right = 20
        elif alignment == 'right':
            picture.TextWrappingStyle = TextWrappingStyle.Square
            picture.DistanceFromText.Left = 20
            picture.DistanceFromText.Right = 0
        elif alignment == 'center':
            picture.TextWrappingStyle = TextWrappingStyle.InLineWithText
            picture.DistanceFromText.Left = 10
            picture.DistanceFromText.Right = 10
       
        return picture


Essentially I'm getting the html class attributes and along with those trying to append the image to the start of the paragraph and set it's wrapping style. But it's not working.

Any suggestions?

I'm obviously using Spire.DOCX or Python and running this on a Ubuntu server.

Thanks in advance.

edfenech
 
Posts: 1
Joined: Wed Jan 08, 2025 6:33 am

Wed Jan 08, 2025 9:32 am

Hello,

Thank you for your letter.
In our latest version (Spire.Doc for Python Version: 12.12.0), the "TextWrappingStyle.InLineWithText" needs to be changed to "TextWrappingStyle.Inline". My initial test settings are all effective. If you are using an old version, you can first verify it with the latest version. If your problem still exists, please provide your test input document, complete test code, and your current results, and then I will further investigate.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1510
Joined: Wed Apr 25, 2018 3:20 am

Fri Jan 24, 2025 9:41 am

Hello,

Greetings from E-iceblue. Could you please let us know how is the issue going? I would appreciate that if you could give us some feedback.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1510
Joined: Wed Apr 25, 2018 3:20 am

Sat Jan 25, 2025 5:00 pm

Personally it helped me, I won't speak for the author of the thread, but the method works

thiefcrazy98
 
Posts: 4
Joined: Sat Jan 25, 2025 4:52 pm

Return to Spire.Doc