Free Support Forum -

Get first page OR delete empty paragraphs in the first page

Hi aspose guys,

I need to delete empty paragraphs in the first page. But it seems that aspose word can not get the first page of document.

Is there any way to resolve my problem?

Thanks for any help

Hi Vuong,

Thanks for your inquiry. Please follow up the code snippet to remove empty paragraphs within first page.

doc = new Document(@“d:\test\inputtest.docx”);<o:p></o:p>

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph para in paragraphs)


// Check all runs in the paragraph for the first page breaks.

foreach (Run run in para.Runs)


if (run.Text.Contains(ControlChar.PageBreak))





// Check empty paragraph to remove

if (string.IsNullOrEmpty(para.ToTxt().Trim()) && para.ParentNode != null)




In case of any ambiguity, please let me know.

Hi imran.rafique,

Thanks for your help.
This code vill remove untill the first page break. But I only want to delete empty paragraphs in the first page of doc file. Because page break in my files maybe in the 3rd hoac later page.

Is there no way to specify the first page(not first page break) in aspose.word?

Hi Vuong,

Thanks for your request. Word document is flow document and does not contain any information about its layout into lines and pages. Therefore, technically there is no “Page” concept in Word document.

In Aspose.Words we are using our own Rendering Engine to layout document into pages. The Rendering Engine is using for converting to PDF. But, unfortunately, currently, there is no public API to determine where pages start/end.

Aspose.Words uses our own Rendering Engine to layout documents into pages. And we have plans to expose layout information. Your request has been linked to the appropriate issue. You will be notified as soon as this feature is supported.

Also, I think, as a workaround you can try using PageNumberFinder class suggested by Adam in this thread:

The issues you have found earlier (filed as WORDSNET-2978) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.