Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-20 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found