http://www.perlmonks.org?node_id=310268


in reply to Open a word(.doc) file and output the number of pages contained in it

If you're on Win and have Word installed you can use Win32::OLE as Corion indicated above.

Below is a working example

#!perl -w use strict; use Win32::OLE; use Win32::OLE::Const; use Win32::OLE::Variant; ## Start Word engine my $Word = Win32::OLE->new('Word.Application', 'Quit'); $Word->{'DisplayAlerts'} = 0; my $wdc = Win32::OLE::Const->Load("Microsoft Word"); my $tpl = "c:\\perltest\\pages.doc"; ## Subject to change ## Open template my $doc = $Word->Documents->Open($tpl, {ReadOnly => Variant(VT_BOOL, +1) } ) || die"add"; my $pages = $Word->ActiveDocument->BuiltInDocumentProperties( $wdc->{w +dPropertyPages} )->Value; $doc->Close( { SaveChanges => $wdc->{wdDoNotSaveChanges} } ); print " $tpl contains $pages pages\n";
HTH
  • Comment on Re: Open a word(.doc) file and output the number of pages contained in it
  • Download Code