Editing/Replacing Text in a PDF -- PDF::API2
am 20.12.2006 16:11:44 von Ben EagleThis is a multi-part message in MIME format.
style=3D'font-size:12.0pt'>ok I will
style=3D'font-size:10.0pt;
--===============0090985793==
Content-Class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C72449.296C6772"
This is a multi-part message in MIME format.
------_=_NextPart_001_01C72449.296C6772
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
ok I will try to be as detailed as possible, I have to create a PDF from
variables posted from Flash. getting the variables is easy, and putting
them in a PDF however was challenging when first started is now for the
most part under control. the tricky part it, the layout for the pdf is
designed using Adobe Indesign, I use perl to open the pdf and to place
variables in the template (PDF::API2), but the designer makes the text
in Indesign and wants me to replace his text holders with the variables
posted from flash. Right now I have been trying to just replace text,
and nothing works this is the code i have thus far.=20
#!/usr/bin/perl
=20
use PDF::API2;
use GD::Graph::bars;
use GD::Graph;
use GD;
use strict;
use constant mm =3D> 25.4/72;
use constant in =3D> 1/72;
use constant pt =3D> 1;
=20
$pdf =3D PDF::API2->open('InDesignTemp.pdf');
=20
my @data =3D (
["Jan-01","Feb-01","Mar-01"],
[21,25,33]
);
=20
my $graph =3D new GD::Graph::bars;
=20
$graph->set(
x_label =3D> 'Month',
y_label =3D> 'Revenue ($1,000s)',
title =3D> 'Monthly Online Sales for 2001',
bar_spacing =3D> 10
)
or warn $graph->error;
=20
$graph->plot(\@data) or die $graph->error;
=20
my %font =3D (
Helvetica =3D> {
Bold =3D> $pdf->corefont('Helvetica-Bold', -encoding =3D> =
'lat
+in1'),
Roman =3D> $pdf->corefont('Helvetica', -encoding =3D> =
'lati
+n1'),
Italic =3D> $pdf->corefont('Helvetica-Oblique', -encoding =3D> =
'lat
+in1'),
},
Times =3D> {
Bold =3D> $pdf->corefont('Times-Bold', -encoding =3D> =
'lati
+n1'),
Roman =3D> $pdf->corefont('Times', -encoding =3D> =
'la
+tin1'),
Italic =3D> $pdf->corefont('Times-Italic', -encoding =3D> =
'lat
+in1'),
},
);
=20
my $page =3D $pdf->openpage(1);
=20
s/Title/Ben is the Man/;
=20
my $headline_text =3D $page->text;
$headline_text->font( $font{'Helvetica'}{'Bold'}, 18/pt );
$headline_text->fillcolor( 'white' );
$headline_text->translate( 50/mm, 130/mm );
$headline_text->text_right( 'this is my new stuff' );
=20
my $photo =3D $page->gfx;
=20
open(GRAPH,">images/graph1.jpeg") || die "Cannot open graph1.jpg: $!\n
+";
binmode GRAPH;
print GRAPH $graph->gd->jpeg(100);
close GRAPH;
=20
$photo_file=3D$pdf->image_jpeg("images/graph1.jpeg");
$photo->image($photo_file, 60/mm, 70/mm, 85/mm, 75/mm);
=20
$pdf->saveas("Build3.pdf");
=20
############################################################ ##########
+###################
####this part I was using to to replace the text however it corrupts t
+he file after i do
############################################################ ##########
+####################
#open(PDF,"
#binmode PDF;
#undef $/;
#$_ =3D
#close(PDF);
=20
#s/Title/Ben is the Man/;
=20
=20
#open(OUT, '>out.pdf') || print header('text/html').'can\'t open out f
+ile';
#print OUT $_;
#close(OUT);
=20
=20
------_=_NextPart_001_01C72449.296C6772
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
charset=3Dus-ascii">
try to be as detailed as possible, I have to create a PDF from variables =
posted
from Flash. getting the variables is easy, and putting them in a PDF =
however
was challenging when first started is now for the most part under =
control. the
tricky part it, the layout for the pdf is designed using Adobe Indesign, =
I use perl
to open the pdf and to place variables in the template (PDF::API2), but =
the
designer makes the text in Indesign and wants me to replace his text =
holders
with the variables posted from flash. Right now I have been trying to =
just
replace text, and nothing works this is the code i have thus far. =
style=3D'font-size:10.0pt'>#!/usr/bin/perl
<=
tt>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">use =
PDF::API2;
size=3D2 face=3D"Courier New">use =
GD::Graph::bars;
size=3D2 face=3D"Courier New">use =
GD::Graph;
size=3D2 face=3D"Courier New">use =
GD;
size=3D2 face=3D"Courier New">use =
strict;
size=3D2 face=3D"Courier New">use =
constant mm =3D> 25.4/72;
size=3D2 face=3D"Courier New">use =
constant in =3D> =
1/72;
size=3D2 face=3D"Courier New">use =
constant pt =3D> =
1;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">$pdf =3D =
PDF::API2->open('InDesignTemp.pdf');=
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">my @data =
=3D (
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>["Jan-01","Feb-01","M=
ar-01"],
size=3D2 face=3D"Courier New"> =
[21,25,33]
size=3D2 face=3D"Courier New"> =
);
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New"> my =
$graph =3D new GD::Graph::bars;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New"> =
$graph->set(
size=3D2 face=3D"Courier New">x_label =
=3D> 'Month',
size=3D2 face=3D"Courier New"> y_label =
=3D> 'Revenue ($1,000s)',
size=3D2 face=3D"Courier New"> title =
=3D> 'Monthly Online Sales for =
2001',
size=3D2 face=3D"Courier New"> =
bar_spacing =3D> 10
size=3D2 face=3D"Courier New"> =
)
size=3D2 face=3D"Courier New"> or warn =
$graph->error;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New"> =
$graph->plot(\@data) or die =
$graph->error;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">my %font =
=3D (
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'> Helvetica =3D> =
{
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'> =
Bold =3D> =
$pdf->corefont('Helvetica-Bold', -encoding =3D> =
'lat
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+in1'),
>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'> Roman =
=3D> =
$pdf->corefont('Helvetica', &=
nbsp; -encoding =3D> 'lati
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+n1'),
=
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'> Italic =
=3D> $pdf->corefont('Helvetica-Oblique', -encoding =3D> =
'lat
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+in1'),
>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'> =
},
size=3D2 face=3D"Courier New"> =
Times =3D> {
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'> =
Bold =3D> =
$pdf->corefont('Times-Bold', =
-encoding =3D> 'lati
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+n1'),
=
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'> =
Roman =3D> =
$pdf->corefont('Times',  =
; -encoding =3D> =
'la
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+tin1'),
=3D> $pdf->corefont('Times-Italic', =
-encoding =3D> 'lat
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+in1'),
>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'> =
},
size=3D2 face=3D"Courier New"> =
);
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">my $page =
=3D $pdf->openpage(1);
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>s/Title/Ben is the =
Man/;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New"> my =
$headline_text =3D =
$page->text;
size=3D2 face=3D"Courier New"> =
$headline_text->font( $font{'Helvetica'}{'Bold'}, 18/pt =
);
size=3D2 face=3D"Courier New"> =
$headline_text->fillcolor( 'white' =
);
size=3D2 face=3D"Courier New"> =
$headline_text->translate( 50/mm, 130/mm =
);
size=3D2 face=3D"Courier New"> =
$headline_text->text_right( 'this is my new stuff' =
);
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">my $photo =
=3D $page->gfx;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>open(GRAPH,">images/graph1.jpeg")=
|| die "Cannot open graph1.jpg: =
$!\n
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+";
GRAPH;
size=3D2 face=3D"Courier New">print =
GRAPH =
$graph->gd->jpeg(100);
size=3D2 face=3D"Courier New">close =
GRAPH;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>$photo_file=3D$pdf->image_jpeg("images=
/graph1.jpeg");
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>$photo->image($photo_file, 60/mm, 70/mm, =
85/mm, 75/mm);
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>$pdf->saveas("Build3.pdf");
>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>##############################################=
########################
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+###################=
tt>
size=3D2 face=3D"Courier New">####this =
part I was using to to replace the text however it corrupts =
t
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+he file after i =
do
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>##############################################=
########################
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+####################<=
/tt>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>#open(PDF,"<Build3.pdf") || =
print header('text/html').'can\'t open =
PDF
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+ =
file';
size=3D2 face=3D"Courier New">#binmode =
PDF;
size=3D2 face=3D"Courier New">#undef =
$/;
size=3D2 face=3D"Courier New">#$_ =3D =
<PDF>;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>#close(PDF);
=
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>#s/Title/Ben is the =
Man/;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>#open(OUT, '>out.pdf') || print =
header('text/html').'can\'t open out =
f
size=3D2 color=3Dred face=3D"Courier New">
style=3D'font-size:10.0pt;color:red'>+ile';
=
size=3D2 face=3D"Courier New">#print =
OUT $_;
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>#close(OUT);
=
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt'>
font-family:Arial'>
------_=_NextPart_001_01C72449.296C6772--
--===============0090985793==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0090985793==--