We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Detecting "hard" page breaks

Using the java version of Aspose.Words…

I have a Word 2000 document that contains many pages, all created using the Insert… Page Break option in Word.

I assumed that the following code would be valid:

// get the first section (should be the whole document)
Section firstSection = srcDocument.getFirstSection();

// process each section; one page per work details
Section section = firstSection;
while ((section = (Section)section.getNextSibling()) != null)

However the entire document is being returned in the first section node and the processWorkPage within the loop is never visited.

Is there a way (without using the Visitor pattern) to access each page as a node in its own right, or is there a way to detect the page breaks when processing paragraphs within the body section?



Thanks for your request. Try to use the following code.

Document doc = new Document(@"243_97316_jsw2000\in.doc");
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph par in paragraphs)
    if (par.Range.Text.Contains("\f"))
        // this is next page.

I hope that it will help you.
Best regards.

Thanks for the tip. This should help us out.

Still it would be nice if you could access each page as a complete node.

Can you explain what the difference is between a section and one or more pages with page breaks?


You can find information about Sections here:
Also, note that SectionBreak specifies start of new section but PageBreak dos not.
Best regards.