user142847
user142847

Reputation: 15

perl pdftk functionality not working , getting error

I was testing the functionality of PDF::Tk by installing in cpan module and installed the pdftk binary file and the path to variable and tried running source code.

source code:

use PDF::Tk;
my $doc = PDF::Tk->new( pdftk => '/apps/free/pdftk/' );
$doc->call_pdftk( 'input.pdf', 'outPDF.pdf', 'cat', '1-14' );

getting error as below:

pdftk input.pdf cat 1-14 releasenote.pdf failed: -1 at
/usr/lib/perl5/site_perl/5.10.0/PDF/Tk.pm line 73.

please guide me in resolving it.

Upvotes: 0

Views: 644

Answers (2)

user142847
user142847

Reputation: 15

for testing the encryption function (by default 128 bit encryption) , i created a pdf file 'apps.pdf' with password protected 'abcd' as password.

source code 1:

use PDF::Tk; 
my $doc=PDF::Tk->new(pdftk=>'/apps/free/pdftk/1.44/bin/pdftk');
$doc->call_pdftk('apps.pdf', '1.128.pdf', 'owner_pw', 'abcd');

getting error:

Error: Unexpected command-line data:
    owner_pw 
where we were expecting an input PDF filename, 
operation (e.g. "cat") or "input_pw". Exiting. 
Errors encountered. No output created. 
Done. Input errors, so no output created. 
pdftk apps.pdf owner_pw abcd 1.128.pdf failed: 256 at /usr/lib/perl5/site_perl/5.10.0/PDF/Tk.pm         line 73.

note: created a new pdf 'apps.pdf' with Document Open Password as 'abcd' and permission Password as 'abcd123'. Please let me know how to resolve it.

Upvotes: 0

cplc
cplc

Reputation: 33

Seems you are passing the wrong argument to the constructor of PDF::Tk. Have a look here.

You're supposed to pass a hash, with the key pdftk, and this should be the path of the executable, not a directory. As you can see here, this will be executed via system, so of course, executing a directory does not work.

To clarify, you should be using:

my $doc=PDF::Tk->new(pdftk => '/path/to/pdftk/executable');

If your pdftk executable is /usr/bin/pdftk, then you do not have to pass it at all as this is the default.

Upvotes: 1

Related Questions