Apparently the module is not able to read pdf files generated by Microsoft Word (that's the only one I tested).
Here is the script:
#!/usr/bin/perl -w
use Tk;
use strict;
use CAM::PDF;
# Create necessary widgets
my $mw = new MainWindow ( -title => '',-width=> 200,-background=>'') ;
$mw->geometry("600x550");
$mw->resizable( 0, 0 ); #not resizable in either width or height
my $frame1 = $mw->Frame(-relief => 'flat', -bd => 2, -background=>'');
$frame1->pack(-side => 'top', -anchor => 'n', -expand => 1, -fill => 'x');
my $pdf_file;
$frame1-> Label(-text=>"")-> pack(-side => 'left',);
$frame1->Button(-text => 'Select a pdf file',
-borderwidth => 3,
-height => 1,
-width => 40,
-command => \&get_file )->pack(-side => 'left', -padx => 5 , -pady => 0);
my $file_entry = $frame1 -> Entry(-textvariable => "", -width=>30)-> pack(-side => 'left', -padx => 10 , -pady => 0);
my $frame2 = $mw->Frame(-relief => 'flat', -bd => 2, -background=>'');
$frame2->pack(-side => 'top', -anchor => 'n', -expand => 1, -fill => 'x');
button($frame2, "TEST IT", "TEST File",'top','cyan', \&read_file)->pack(-padx => 30 , -pady => 10, -side => 'bottom');
MainLoop;
sub button
{
my ($this, $text, $help, $position, $bgcolor, $command) = @_;
my $button = $this->Button(-text => $text, -command => $command, -font=>"default 14 bold", -background=> $bgcolor, -activeforeground => "red");
my $hotkey = "<Alt-" . lc(substr($text, 0, 1)) . ">";
$mw->bind($hotkey, $command );
$button->configure(-underline => '0'); # Alt-first char as hotkey
$button->pack(-side => $position,-padx => 0 , -pady => 10);
return $button;
}
sub read_file
{
if ($pdf_file)
{
my $pdf = CAM::PDF->new($pdf_file);
print $pdf->numPages();
}
}
sub get_file
{
my @types =
(["PDF files", [qw/.pdf/]],
["All files", '*'],
);
$pdf_file = $mw->getOpenFile(-filetypes => \@types) or return();
if( $pdf_file )
{
$file_entry->configure(-text => $pdf_file);
}
return($pdf_file);
}
Show quoted text-----Original Message-----
From: Father Chrysostomos via RT [mailto:bug-CAM-PDF@rt.cpan.org]
Sent: Wednesday, March 29, 2017 6:45 PM
To: Abdelbaki Brahmia <abrahmia@physics.rutgers.edu>
Subject: [rt.cpan.org #120793] rt.cpan.org #120773
<URL:
https://rt.cpan.org/Ticket/Display.html?id=120793 >
On Wed Mar 29 14:15:52 2017, abrahmia@physics.rutgers.edu wrote:
> It works fine if the pdf file is loaded internally like my $file =
> "C:/path/file.pf";
>
> But it fails when you load it using the Tk interface like:
> my $file= $mw->getOpenFile(-filetypes => \@whatever);
>
> This problem does not happen with PDF::API3 module.
It’s a little hard to go on that. Could you provide a complete script (but as small as possible) that demonstrates the problem?