Articles in this section
Category / Section

Why it is not possible to access the Word document contents page by page?

3 mins read

The Word document is a flow document in which contents (paragraphs, tables, etc.) will not be preserved page by page; instead, the contents will be preserved sequentially, section by section. Each section may extend to various pages based on its contents, such as tables, text, images, etc.

Word viewers/editors render the contents of the Word document page by page dynamically when opened for viewing or editing. This page-wise rendered information will not be preserved at the file level. Whereas Syncfusion® .NET Word library is a non-UI component that provides a full-fledged document object model to manipulate the Word document contents.

Hence, it is not directly possible to access the Word document contents page by page using DocIO. As a workaround, you can split the contents of each page as a separate section in the Word document and access the contents by sections instead of pages.

Alternate approaches:

Below are some alternate suggestions to access the Word document contents page by page using DocIO.

  1. Split Word documents according to pages:
    • To achieve this, you need to maintain each page as a separate section, thereby allowing you to split the Word document by sections. To know more about splitting Word documents based on sections, refer here.
    • Alternatively, you can convert the Word document to PDF, then convert the PDF to a Word document again by converting each page as an image and adding each image to a separate Word document. Note: This created Word document will not be editable, as the contents are preserved as images.
  2. Insert text in a particular page:
    • You can insert a placeholder in the input Word document, thereby enabling you to find the placeholder in the Word document and replace it with the necessary content using the Find functionality. To know more about find and replace, you can refer here.
    • Alternatively, you can insert a bookmark in the input document, thereby allowing you to navigate to the bookmark and replace the bookmark content programmatically. To know more about bookmarks in a Word document, refer here.
  3. To extract text based on each page, you can maintain each page as a separate section, thereby allowing you to split the Word documents according to sections. Then, using the GetText() API, you can retrieve all the text from the split Word documents.
  4. To add line numbers restarting for each page, you can maintain each page as a separate section, then add line numbers for each section starting from the beginning value. To know more about adding line numbers, refer here.
  5. To remove empty pages from a Word document, where the empty pages are due to continuous section breaks or page breaks, you can refer to the GitHub sample.
  6. To fetch page numbers from a Word document, you can maintain each page as a separate section and add a Page field in each section. To know more about fetching page numbers from a Word document, refer here.
  7. To set landscape and portrait orientation for each page, you can maintain each page as a separate section, then set different orientations for different sections. Refer here.

Take a moment to peruse the documentation where you can find basic Word document processing options along with features like mail merge, merge, split, and compare Word documents, find and replace text in the Word document, protect Word documents, and most importantly, the PDF and Image conversions with code examples.

Conclusion
I hope you enjoyed learning about why it is not possible to access the Word document contents page by page using the .NET Core Word Library.

You can refer to our ASP.NET Core DocIO feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our ASP.NET Core DocIO example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied