I am using the code
if (ds.Tables[8].Rows.Count == 0)
{
doc.FirstSection.Body.Tables[3].Remove();
doc.FirstSection.Body.Tables[2].Remove();
doc.FirstSection.Body.Tables[1].Remove();
}
doc.MailMerge.CleanupOptions = Aspose.Words.MailMerging.MailMergeCleanupOptions.RemoveUnusedRegions;
doc.MailMerge.CleanupOptions = Aspose.Words.MailMerging.MailMergeCleanupOptions.RemoveEmptyParagraphs;
doc.Save(Path.Combine(SpecialFolderPath, fileName + ".doc"), SaveFormat.Doc);
The tables are getting removed but i am getting white (blank) area in the place of table so how to handle this? I am using aspose word for .NET
@SachinSingh Most likely the space you are talking about empty paragraph after the tables that were removed. Could you please attach your input, output and expected output documents here for our reference? We will check your documents and provide you more information.
sure,
Here is my original word documnet
InputDocument.docx (42.5 KB)
Here is the output
output.pdf (46.3 KB)
As you can see there is space (empty paragraph or blank area) between Position Description and Employment Details as i have programatically removed three tables in between.
This is how i am converting the word to pdf
Aspose.Words.Saving.SaveOptions saveOptions = Aspose.Words.Saving.SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Pdf);
saveOptions.PrettyFormat = true;
Doc.Save(FinalFilePath, saveOptions);
Aspose.Words.Saving.SaveOptions saveOptions = Aspose.Words.Saving.SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Pdf);
saveOptions.PrettyFormat = true;
Doc.Save(FinalFilePath, saveOptions);
@SachinSingh As I mentioned din the previous post the problem is caused by empty paragraphs after the tables. Please try using the following code to remove tables with empty paragraphs after them:
RemoveTable(doc.FirstSection.Body.Tables[3]);
RemoveTable(doc.FirstSection.Body.Tables[2]);
RemoveTable(doc.FirstSection.Body.Tables[1]);
private static void RemoveTable(Table table)
{
// Remove empty paragraphs after the table.
while (table.NextSibling.NodeType == NodeType.Paragraph && !((Paragraph)table.NextSibling).HasChildNodes)
table.NextSibling.Remove();
table.Remove();
}