Calculate pages

Hi guys,

I have MS Word document, that contains multiple sections. Each section can contain multiple pages. Could you tell me how to calculate total number of  pages in the document?

Thanks,
Alex

8 Replies

RH Ramanan  Hariharasubramanian Syncfusion Team December 6, 2017 12:46 PM UTC

Hi Alex,

Thank you for contacting Syncfusion support.

Please refer the below KB article which explains why we cannot access the Word document as page by page:
http://www.syncfusion.com/kb/3989/why-it-is-not-possible-to-access-the-word-document-contents-page-by-page

Note: This is a limitation of Word document file format, and not specific to DocIO or any other Word document processing tools.


As a workaround, you can design the Word document of each page as separate section (by inserting NextPage as section break at end of each page) in Microsoft Word or any other Word viewer/editor application. There is also a chance for page wise display difference between various Word document viewers.

We have prepared the sample for counting the pages using section breaks. Please find the sample from below link and let us know if it helps.
Sample link:
http://www.syncfusion.com/downloads/support/forum/134894/ze/GetPageCount_by_Section299848712

Please let us know if you have any concerns.

Regards,
Ramanan H



AK Alexander Kurnevich December 6, 2017 03:15 PM UTC

Hi guys,

I couldn't run your example. Could you provide console application or include all Mvc dependencies to nuget package.

I just would like to clarify, that I am using mail merge and import data from table, so I don't know when insert section break.

May be there is an option to convert the docx to pdf and get pages count from pdf or you have another ideas.

Please advice.

Thanks,
Alex


RH Ramanan  Hariharasubramanian Syncfusion Team December 7, 2017 09:58 AM UTC

Hi Alex,

Sorry for the inconvenience.

We have modified the sample by removing unused assembly references in it and the sample can be downloaded from the following location.
Sample link:
http://www.syncfusion.com/downloads/support/forum/134894/ze/Sample-792623562

Regarding “May be there is an option to convert the docx to pdf and get pages count from pdf
”:
Yes, it is possible to get pages count after converting Word document as a PDF using Essential DocIO. You can use the Count property in Page class to get the page counts. We have prepared a sample which can be downloaded from the following location.
Sample link:
http://www.syncfusion.com/downloads/support/forum/134894/ze/Sample1406435939

Microsoft Word and Syncfusion generated PDF may differ in some cases. It may differ due to unsupported element present document or GDI calculation difference compared to Microsoft Word. Due to this we can’t able to provide exact as Microsoft Word application displayed page count.

You can also convert the Word document to Image collection to get the pages count.We have attached code snippet for your reference.
 
WordDocument document = new WordDocument(document);
Image[] page = document.RenderAsImages(ImageType. Metafile);
int pageCount =page.Length; 

Please let me know if you have any other questions.

Regards,
Ramanan H



AK Alexander Kurnevich December 8, 2017 02:02 PM UTC

Hi guys,

Thanks a lot for your help, I appreciate it.
I used this approach: 

WordDocument document = new WordDocument(document);
Image[] page = document.RenderAsImages(ImageType. Metafile);
int pageCount =page.Length; 

So far it works.

Thanks again,
Alex



MJ Mohanaselvam Jothi Syncfusion Team December 11, 2017 05:33 AM UTC

Hi Alex,

Thank you for your update.

We are glad to know that our solution has resolved your issue.

Please let us know if you need any further assistance. We are happy to assist you as always.

Regards,
Mohanaselvam J
 



AK Alexander Kurnevich February 16, 2018 03:53 PM UTC

Hi guys,

The following solution pretty much works for all files except one.

WordDocument document = new WordDocument(document);
Image[] page = document.RenderAsImages(ImageType. Metafile);
int pageCount =page.Length; 

The actual document contains 8 pages, but program returns 9.
I attached the sample.

Could you please advice how to calculate pages right?

Thanks,
Alex



Attachment: CountOfPages_7e55df25.zip


MJ Mohanaselvam Jothi Syncfusion Team February 19, 2018 07:38 AM UTC

Hi Alex,

Thank you for your update.

On further analyzing with the given input Word document, we have found some paragraphs contain Word 2013 justification alignment. Microsoft Word maintains two different line engines for layout and render the justified paragraphs by adjusting its lines inter word spacing. One engine is used in Word 2010 and below versions, another one is used in Word 2013 and higher version.

Both engines using separate algorithm for calculating inter word spacing to align the justified text. Currently DocIO provide full-fledged support for Word 2010 and below versions justification alignment (100% equivalent to Microsoft Word) but our Word 2013 justification algorithm is not 100% equal to Microsoft Word. That means our word splitting algorithm slightly mismatched with Microsoft Word 2013, word splitting algorithm. So, the last word of some lines may move to the next line which results in pagination.

This is the reason for generating 9 images (instead of 8) while rendering the given input Word document as images using DocIO. We have already logged Word 2013 justification algorithm enhancement as a feature request in our database. We will implement this feature in any of our upcoming releases. At present, we cannot provide any concrete timeline for this feature implementation. We will let you know once this feature is implemented.

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



MR Manikandan Ravichandran Syncfusion Team October 6, 2020 09:49 AM UTC

Hi Alexander,

Reg - Word 2013 Justification alignment
We have improved Word 2013 Justification algorithm in Word to PDF/Image conversion and this enhancement was included in our 2020 Volume 3 release v18.3.0.35.

We are glad to announce that our Essential Studio 2020 Volume 3 release v18.3.0.35  is rolled out and is available for download under the following link.
https://www.syncfusion.com/forums/158306/essential-studio-2020-volume-3-release-v18-3-0-35-is-available-for-download

We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.

Regards,
Manikandan Ravichandran 


Loader.
Up arrow icon