http://qs1969.pair.com?node_id=251182

peppiv has asked for the wisdom of the Perl Monks concerning the following question:

Good day,

I've been using PDF::Create to make a PDF from info I pull from a DB. Works great (thanks tall_man). My only problem is that when info I pull that has a single parenthesis in the body, PDF::Create dumps out and cannot create the page. I'd like to replace the single parenthesis with a blank space (I've tried this and it works). I'd also like to leave the parenthesis if there's the opening and closing one (e.g. "Madrid (Spain)" is OK and works, "Madrid (Spain" is not and does not work).

Here's where I'm at:
#code is stripped to bare bones in effort to save time/space use strict; use DBI; use PDF::Create; my $id = param("id"); my $pdf = new PDF::Create ('filename' => '../html/logs/mypdf.pdf', 'PageMode' => 'UseNone', 'Title' => 'Anything', ); my $root = $pdf->new_page('MediaBox' => [ 0, 0, 612, 792 ]); # Add a page which inherits its attributes from $root my $page = $root->new_page; # Prepare 2 fonts my $f1 = $pdf->font('Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Helvetica'); my $dbh = DBI->connect('DBI:mysql:database=hr_db;host=69.169.169.9','u +srname','password'); my $sth = $dbh->prepare('SELECT * FROM applicant WHERE id = ?'); $sth->execute($id) or die $sth->errstr; while (my @results = $sth->fetchrow_array()) { $results[15] =~ tr/\(/ /g; $results[15] =~ tr/\)/ /g; $page->stringl($f1, 10, 28, 675, "Specific Position(s)"); $page->stringl($f1, 10, 28, 664, "Applied For:"); $page->stringl($f1, 10, 93, 664, "$results[15]"); $page->line(90, 662, 310, 662); $page->stringl($f1, 10, 320, 664, "Date Applied:"); $page->stringl($f1, 10, 393, 664, "$results[20]"); $page->line(390, 662, 587, 662); } $sth->finish(); $dbh->disconnect; # Add the missing PDF objects and a the footer then close the file $pdf->close;
This works in removing parenthesis from $results[15], but how can I catch them in the entire returned array? $results[1..80]? Also, how can I leave the parenthesis if they are placed correctly "(Spain)" not "(Spain"? This problem stems from the fact that some of this data came from user input and it wasn't controlled on the front end to filter them out.

This problem only appears to happen with parenthesis. It doesn't break with brackets or other characters. Since PDF::Create is no longer supported, I can't find a way to escape them in it's print to screen line ($page->stringl($f1, 9, 30, 352, "$results[1]");
It's not like I can use the qq or anything.

Any help would be greatly appreciated! TIA

peppiv

hey I love sports, but if it's such a macho thing, why do all these people punch, dunk and tackle for purses, belts and rings?