#!/usr/bin/perl
use strict;
use warnings;
use PDF::API2;
use PDF::Table;
use Data::Dump 'pp';
# Start PDF Process
my $pdf = PDF::API2->new(-file => "test.pdf");
#A4 Landscap
$pdf->mediabox('Letter');
my $page = $pdf->page;
# font settings
my $font_size = 12;
my $fnt = $pdf->corefont('Helvetica',-encode => 'latin1');
my $boldfont = $pdf->corefont('Helvetica-Bold',-encode => 'latin1');
my $fnt_t = $pdf->corefont('Times-Roman',-encode => 'latin1');
my $boldfont_t = $pdf->corefont('Times-Bold',-encode => 'latin1');
my $txt = $page->text();
#my $txt_under = $page->text(-underline => 'auto');
my $top = 700;
my $left_margin = 50;
my $left_margin_a = 100;
$txt->textstart;
my $new_lines = "Aliquam vitae ipsum id felis finibus congue. Ut molestie scelerisque purus,
sit amet rhoncus leo aliquet ac. In eu lobortis quam. Maecenas auctor semper enim,
ut convallis sapien dictum eu. Sed arcu ex, ornare et porttitor vitae, interdum a mi.
Mauris rutrum luctus rhoncus. Quisque velit quam, convallis vel est at, tincidunt accumsan velit.
Fusce ut metus ut which may either exceed \$1,000.00 or OK. G. LAT,
semper nunc, in dictum magna.
Aliquam ac vestibulum dolor. Praesent in magna nisi. Cras nec viverra ligula. Suspendisse
efficitur imperdiet eros, XXsed rhoncus sapien euismod cursus. Vestibulum a posuereYY elit,
eget tristique eros. Etiam et lectus venenatis, aliquet dui vitae, posuere lectus.";
;
my @lines = split/\n/, $new_lines;
print Dumper \@lines;
my $y = $top - 162;
# reading the text line by line, I am marking the text I need to be underlined with ...
for my $rows (@lines){
print "57 *$rows*\n";
$txt->font($fnt,11);
$txt->translate( $left_margin,$y);
if( $rows =~ /(.*?)<\/u>/xms ){
# here I can get each section of text between the
my ($one, $two) = ($rows =~ /(.*?)<\/u>/sg);
# now, underline each portion found
$txt->text("$one",-underline => 'auto');
$txt->text("$two",-underline => 'auto');
# and here is where I thought I could just put the newly underlined text
# back into the orinal text, by replacing it in the original,but instead
# it replaces all the rows with the underlined text, its almost there.
$rows =~ s/(.*?)<\/u>/$one/;
$rows =~ s/(.*?)<\/u>/$two/;
$txt->text("$rows");
}else{
$txt->text("$rows");
}
$y-=17;
}
$txt->textend;
$pdf->save;
$pdf->end( );