Hi Team,
I am using Aspose version: 17.4.0.0.
Please find attached document.
PAP_RS43733_GLB202302016_20230328145056.docx (104.8 KB)
Consider this is my Input document.
- How to delete empty page from the attached document. (page# 4, 53 etc.)
- How to delete empty pages are produced by a bunch of empty paragraphs.(page# 55 etc.)
@rs43733 to delete empty pages you can use the code example posted in our Knowledge Base.
Please notice that pages don’t exists in MS Word and Aspose.Words, he pages are generated by the render process of the document so in some cases after running the code to clear blank pages you need to check for empty paragraphs or para graphs that contain undesired page breaks. The following code clear all the empty paragraphs:
Document doc = new Document(@"C:\Temp\input.docx");
var paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach(Paragraph p in paragraphs)
{
var text = p.Range.Text.Trim();
if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(text))
{
p.Remove();
}
if (text == ControlChar.PageBreak)
{
var prev = p.PreviousSibling;
if (prev != null && prev.NodeType == NodeType.Paragraph)
{
((Paragraph)prev).Runs.Add(new Run(doc) { Text = text });
p.Remove();
}
else
{
p.ParagraphFormat.SpaceBeforeAuto = false;
p.ParagraphFormat.SpaceBefore = 0;
p.ParagraphFormat.PageBreakBefore = false;
}
}
}
doc.Save(@"C:\Temp\output.docx");