How to find last paragraph of last page has section break

I am trying to merge two word documents, the first document last page, last paragraph has section break, because of that the second document does not start in new page.
I want to check in the code if the last paragraph has section break, if yes, then the second document should start in new page

@bala7

To check if the last paragraph of the last page in your Word document has a section break, you can use the Aspose.Words library. Here’s a step-by-step approach to achieve this:

  1. Load the First Document: Open the first document using the Document class.
  2. Access the Last Page: Navigate to the last page of the document.
  3. Get the Last Paragraph: Retrieve the last paragraph of the last page.
  4. Check for Section Break: Verify if this paragraph has a section break.
  5. Insert a Page Break: If it does, insert a page break before merging the second document.

Here’s a sample code snippet to illustrate this:

using Aspose.Words;

Document firstDoc = new Document("path/to/firstDocument.docx");
Document secondDoc = new Document("path/to/secondDocument.docx");

// Get the last paragraph of the first document
Paragraph lastParagraph = firstDoc.LastSection.Body.LastParagraph;

// Check if the last paragraph has a section break
if (lastParagraph != null && lastParagraph.ParentSection != null && 
    lastParagraph.ParentSection.Body.LastParagraph == lastParagraph)
{
    // Check if the last paragraph has a section break
    if (lastParagraph.ParagraphBreakType == ParagraphBreakType.SectionBreak)
    {
        // Insert a page break before merging the second document
        firstDoc.AppendDocument(secondDoc, ImportFormatMode.KeepSourceFormatting);
    }
}

// Save the merged document
firstDoc.Save("path/to/mergedDocument.docx");

This code checks if the last paragraph of the last section has a section break and ensures that the second document starts on a new page if necessary.

Next Steps: Implement this code in your project, ensuring you have the Aspose.Words library referenced. Test the functionality with your documents to confirm it works as expected.

If you have any further questions or need additional assistance, feel free to ask!

There is no ParagraphBreakType in lastparagraph

@bala7 Could you please attach your problematic input and expected output documents along with code that will allow us to reproduce the problem? We will check the issue and provide you more information.

Probably, in your case you can use Paragraph.IsEndOfSection property.