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.

Sat May 10, 2025 10:34 am

hi thank you for dedicating time
im using python to develop my code
i want to add image with label and my description for it
i follow the link below Instructions
https://www.e-iceblue.com/Tutorials/Python/Spire.Doc-for-Python/Program-Guide/Others/Python-Add-or-Remove-Captions-in-Word-documents.html
but there is 3 problem
1- the caption format is different from word itself and text isnt under and middle of image like word caption itself
2- the label doesnt add to word document
3-because the label doesnt add to word document i cant insert Table of Figures

i appreciate, you help me to add picture with caption as same as word itself that i could create table of figures
regards

XxLonely
 
Posts: 21
Joined: Sat Mar 30, 2024 5:11 pm

Mon May 12, 2025 9:44 am

Hello,

Thanks for your inquiry.
In Microsoft Word, the caption can only be placed above or below the image, and cannot be centered. Can you do this in Microsoft? To help us investigate further, cloud you please tell us the steps?
To ensure that you can insert Table of Figures in Word, please use the following code to test and verify whether it meets your needs.
Code: Select all
from spire.doc import *
from spire.doc.common import *

# Create a Word document object
document = Document()
# Add a section
section = document.AddSection()
# Add a new paragraph and add an image to it
pictureParagraphCaption = section.AddParagraph()
pictureParagraphCaption.Format.AfterSpacing = 10
pic1 = pictureParagraphCaption.AppendPicture("AddImageCaption\\1.jpg")
pic1.Height = 100
pic1.Width = 100
# Add a caption to the image
format = CaptionNumberingFormat.Number
pic1.AddCaption("Figure", format, CaptionPosition.BelowItem)
# Add another new paragraph and add an image to it
pictureParagraphCaption = section.AddParagraph()
pic2 = pictureParagraphCaption.AppendPicture("AddImageCaption\\1.jpg")
pic2.Height = 100
pic2.Width = 100
# Add a caption to the image
pic2.AddCaption("Figure", format, CaptionPosition.BelowItem)
# Update all fields in the document
document.IsUpdateFields = True
# Save the document as a docx file
result = "output.docx"
document.SaveToFile(result, FileFormat.Docx2016)
# Close the document object and release resources
document.Close()
document.Dispose()

Sincerely,
Tommy
E-iceblue support team
User avatar

Tommy.Tang
 
Posts: 85
Joined: Mon Apr 21, 2025 7:05 am

Return to Spire.Doc

cron