Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
P is for Practical
 
PerlMonks  

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!

Comment on Count Word Pages
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.



        Beware.

        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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1038073]
Approved by sundialsvc4
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-04-20 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls