Why is the number of pages in a Word document different in Perl and Word VBA?

I have a (set of) Word documents for which I am trying to get various properties (number of pages, author, etc.) using Win32 :: OLE in Perl:

print $MSWord->Documents->Open($name)-> BuiltInDocumentProperties->{"Number of pages"}->value . " \n"; 

This returns 4 pages. But the actual number of pages in the document is 9. The number of pages in the first section is 4. I want the total number of pages in the document.

If in Word VBA I do the following:

 MsgBox ActiveDocument.BuiltInDocumentProperties("Number of pages") 

Displaying 9. The number of pages displayed on the Properties / Statistics page is 9.

Do I need to recount? Is there a way to ask the OLE library to force recount, or do I need to process each section separately?

I am in XP, Word 2007, ActivePerl v5.10.0.

+2
source share
1 answer
 #!/usr/bin/perl use strict; use warnings; use File::Spec::Functions qw( catfile ); use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 3; my $word = get_word(); $word->{Visible} = 1; my $doc = $word->{Documents}->Open(catfile $ENV{TEMP}, 'test.doc'); $doc->Repaginate; my $props = $doc->BuiltInDocumentProperties; my $x = $props->Item(wdPropertyPages)->valof; print "$x\n"; $doc->Close(0); sub get_word { my $word; eval { $word = Win32::OLE->GetActiveObject('Word.Application'); }; die " $@ \n" if $@ ; unless(defined $word) { $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit }) or die "Oops, cannot start Word: ", Win32::OLE->LastError, "\n"; } return $word; } 
+4
source

Source: https://habr.com/ru/post/1286487/


All Articles