I am trying to insert html using DocumentBuilder.insetHtml function. The html (content and image )gets inserted well. However, it gets cropped from right side and when try to apply padding or width to Autofit (to Image) then its shows message that the property is Obselete and doesnt get applied while generating the Word document. It ask to use table for these properties but dont want to use table there.
To ensure a timely and accurate response, please attach the following resources here for testing:
- Your input Word and HTML documents.
- Please attach the output Word file that shows the undesired behavior.
- Please attach the expected output Word file that shows the desired behavior.
- Please create a simple application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.
As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.
PS: To attach these resources, please zip and upload them.
Pease read the following article and use Table.AutoFit method as shown below to get the desired output.
Specifying Table and Cell Widths
Document doc = new Document(MyDir + "Template.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(File.ReadAllText(MyDir+ "Input_Html.txt"));
doc.FirstSection.Body.Tables[0].AutoFit(AutoFitBehavior.AutoFitToWindow);
doc.Save(MyDir + "20.6.docx");
Thanks for the reply.
The provided code is working fine. However, I need to do the same for all the Bookmark sections in the document (around 20 different bookmarks) instead of FirstSection and LastSection.
Please do the needful.
Please share the detail as requested in my old post here for testing. We will investigate the issue and provide you more information on it. Thanks for your cooperation
Thanks for the reply.
Please attached files and do the needful.
Note: Input file is same for all bookmark section
The shared input document (Template.docx) has only one bookmark. We have not found any issue while using this document.
Unfortunately, we have not found input document for this case. Please ZIP and attach your input and expected output documents. We will investigate the issue and provide you more information on it.
To ensure a timely and accurate response please supply us requested resources, if you cannot supply us with this detail, we will not be able to investigate your issue and raise a ticket.
Please use the following code example to get the desired output. We have attached the output DOCX with this post for your kind reference. 20.6.zip (21.8 KB)
Document doc = new Document(MyDir + "Template.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (Bookmark bookmark in doc.Range.Bookmarks)
{
builder.MoveToBookmark(bookmark.Name);
builder.InsertHtml(File.ReadAllText(MyDir + "Input_Html.txt"));
}
foreach (Table table in doc.FirstSection.Body.Tables)
{
table.AutoFit(AutoFitBehavior.AutoFitToWindow);
}
doc.Save(MyDir + "20.6.docx");
Thanks for the reply. I have used the below code and working fine.
Code:
foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
table.AutoFit(AutoFitBehavior.AutoFitToWindow);
}
However, the Table also contains Image in cell and due to which the auto-fit goes for a toss.
Can you please put some light on it?
Please find the attached file for your reference.
Thanks,
Demo4.zip (86.2 KB)
We have not found the shared issue while using latest version of Aspose.Words for .NET 20.6. So, please use Aspose.Words for .NET 20.6. We have attached the output DOCX with this post for your kind reference. 20.6.zip (29.8 KB)