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?


In reply to How do I replace certain character if condition exists by peppiv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.