Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I'm looking for a solution of counting number of pages in a word document while the server not having Office installed and therfore I cannot use an word application object.

In my website the user load any DOc,DOcx file to the server and I want to kno how many pages the file contain.

I know there are meny reward solution but searching for free ones.

Tx,

dav
Posted
Comments
Sergey Alexandrovich Kryukov 6-Nov-11 13:12pm    
Why do you think there are solutions? A reference, please. If there is a solution, it's a false one. I explain why in my solution.
--SA
Member 4529316 10-Nov-11 15:48pm    
I thought on a solution to convert the word documet to PDF and then calculate the pages using regular expression code. but, "itextsharp-all-5.1.2" cannot create pdf file with doc as an input.
If you're familiar with other converter tool, you're more than welcome to share.

This is not correctly posed problem. You can count number of words or something, but not number of pages.

The thing is: a number of pages is not an attribute of a document. The document will be formatted to different number of pages depending on the width of the window where you view the document or its print preview (results can be different in number of pages!), or printing parameters and perhaps other factors, such as software used for viewing or printing. In this way, the structure and integrity of document is preserved, but not number of pages.

In this way, the problem is not defined and you should not try to solve it as it makes no sense. Just use some other measure of the size of the document. I would simply suggest a byte size of it.

—SA
 
Share this answer
 
You may have to work with third party libraries like Aspose.Words[^]. Here is how you can count number of page over the web. http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-print-multiple-pages-on-one-sheet.html[^]
 
Share this answer
 
Comments
Member 4529316 10-Nov-11 15:43pm    
Good suggestion but he prefer a free solution and that one is expensive.
The free trial is also limitted to 30 days.
I thought on a work around but need your assitance.

I have a code that using regular expressions to count the number of pages in a PDF file.

If I will be able to convert (again with free tool) on the server the file to PDF then I will be able to run the code on that PDf file.

I search the new and found some solution:
1. send the file to website and get the file back by mail - long time that I cannot wait for reciving mail.
2. create PDF using "itextsharp-all-5.1.2" - not supporting converting Doc to PDF.
3. Use drivers - very expensive for my needs.

I will be glad to get any suggestion for a cheap way to do that. I don't care if the convert to PDf file will add commercials to the doc, because I don't need that PDF I just want to produce it so I will be able count the pages.
 
Share this answer
 
No Mr. SAKryukov.

Word document keeps information about number of pages.

Dav i can give you a approach for find out number of pages in document.

I tried with word 2007 document.

Create a temp copy of word document.
Add a .zip extension to the end of the file name.
Extract the parts to a folder.
Open that folder and find docProps folder.you will find app.xml file in it.

Read <pages> tag there. This is the information about your number of page in word document.

This is my way of read data from Word Document Packages.

I have done automation of this process too using code. may be this is long process but in your case i think it will help you.
 
Share this answer
 
v2
Comments
Richard MacCutchan 6-Nov-11 16:33pm    
You cannot rely on this information. As Mr Kryukov said, this is a feature of the page size that the document is to be printed on, so you need that information also.
Sergey Alexandrovich Kryukov 8-Nov-11 21:01pm    
Correct.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900