Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Count Word Pages

by packetstormer (Monk)
on Jun 10, 2013 at 13:56 UTC ( #1038073=perlquestion: print w/replies, xml ) Need Help??
packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I am searching for a way to count the number of pages in a MS Word document without using, or installing MS Word, on a machine. I have a process that strips emails of Word attachments but I need to count how many pages are within the document.

Could anyone point me in the right direction? I can't see any CPAN modules that might help, especially if running in a Linux console - don't think LibreOffce can do it either!

Replies are listed 'Best First'.
Re: Count Word Pages
by Corion (Pope) on Jun 10, 2013 at 14:00 UTC

    Use unoconv to convert the document to PDF and then count the pages in the PDF file.

    Alternatively, convert the document to a multipage TIFF file and count the pages in it.

      I did think of this but I am not certain (maybe you know?) if a Word file page count will ALWAYS equal the page count of the converted document. The process charges per Word pages so the count must be the same. I suppose I could try one or two and find out!!

        If that is the case, you are in trouble. The pagination only exists once the document is open in word depending (among other things) on the choice of paper in the printer driver. So if there is an absolute precision on page count required, you have to install Word. And even then your client might get different answers than yourself.


        The "Word file page count will" NOT "ALWAYS equal the page count of the Word document"!

        Pagination depends on font, size, output medium, margins, (and probably a few more not mentioned here).

        Could this be an XY problem? Why do you need something as ephemeral as a "page count?"

        If you didn't program your executable by toggling in binary, it wasn't really programming!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1038073]
Approved by sundialsvc4
[GotToBTru]: oh I know what it is .. but it is a number only slightly useful to me and of no possible use to our customer
[MidLifeXis]: Whew - you just saved the free world. <o)
[GotToBTru]: i guess it's a placeholder, the code will only fill it in if there is nothing else to use
[GotToBTru]: but then .. if you have nothing to say, why not say nothing?
[MidLifeXis]: I have a user who has a lot of say on how some of our processes work that abhors significant blanks. Perhaps that is a part of it. A not-so-obvious "this space intentionally left blank" indicator.
[MidLifeXis]: On the back end, however, that doesn't mean that i have to use that value to indicate "undefined", no matter how much he thinks I should.

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2017-01-20 19:16 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (176 votes). Check out past polls.