I'm trying to work out a method to edit a PDF file. I found somecode that is 'supposed' to do this. I've edited the code a bit, so it works correctly (had a few syntax errors, such as not defining an object for CGI).
The code is as follows;
use PDF;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$IN = new CGI;
if ($IN->param('action') eq 'make_pdf') {
open(PDF, "test.pdf") || print $IN->header('text/html')."can't open PDF file. Reason: $!";
undef $/;
$_ = <PDF>;
close(PDF);
$_ =~ s/Title/test/sig;
#s/##first_name##/$IN->param('first_name')}/;
#s/##last_name##/$IN->param('last_name')}/;
open(OUT, '>out.pdf') || print $IN->header('text/html').'can\'t open out file';
print OUT $_;
close(OUT);
print $IN->header('text/html');
print 'Your PDF has been created. It is available <a href="out.pdf">here</A>';
} else {
print $IN->header().'
<FORM ACTION="'.$ENV{SCRIPT_NAME}.'" METHOD="post">
Enter your info to make your own summersault business card in PDF format:<P>
First Name: <INPUT TYPE="text" NAME="first_name" SIZE="32" MAXLENGTH="32"><BR>
Last Name: <INPUT TYPE="text" NAME="last_name" SIZE="32" MAXLENGTH="32"><BR>
Email Address: <INPUT TYPE="text" NAME="email" SIZE="32" MAXLENGTH="32"><BR>
<INPUT TYPE="hidden" NAME="action" VALUE="make_pdf">
<INPUT TYPE="submit">
</FORM>
';
}
I don't get any errors, and the PDF seems to open find in Adobe Acrobat, but the text 'Title' is not replaced with the new string.
Does anyone have a better method to do this, or should this work?
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
The code is as follows;
Code:
#!/usr/bin/perl use PDF;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$IN = new CGI;
if ($IN->param('action') eq 'make_pdf') {
open(PDF, "test.pdf") || print $IN->header('text/html')."can't open PDF file. Reason: $!";
undef $/;
$_ = <PDF>;
close(PDF);
$_ =~ s/Title/test/sig;
#s/##first_name##/$IN->param('first_name')}/;
#s/##last_name##/$IN->param('last_name')}/;
open(OUT, '>out.pdf') || print $IN->header('text/html').'can\'t open out file';
print OUT $_;
close(OUT);
print $IN->header('text/html');
print 'Your PDF has been created. It is available <a href="out.pdf">here</A>';
} else {
print $IN->header().'
<FORM ACTION="'.$ENV{SCRIPT_NAME}.'" METHOD="post">
Enter your info to make your own summersault business card in PDF format:<P>
First Name: <INPUT TYPE="text" NAME="first_name" SIZE="32" MAXLENGTH="32"><BR>
Last Name: <INPUT TYPE="text" NAME="last_name" SIZE="32" MAXLENGTH="32"><BR>
Email Address: <INPUT TYPE="text" NAME="email" SIZE="32" MAXLENGTH="32"><BR>
<INPUT TYPE="hidden" NAME="action" VALUE="make_pdf">
<INPUT TYPE="submit">
</FORM>
';
}
I don't get any errors, and the PDF seems to open find in Adobe Acrobat, but the text 'Title' is not replaced with the new string.
Does anyone have a better method to do this, or should this work?

Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!