Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How do I replace certain character if condition exists

by bart (Canon)
on Apr 17, 2003 at 13:25 UTC ( [id://251189]=note: print w/replies, xml ) Need Help??


in reply to How do I replace certain character if condition exists

PDF::Create is no longer supported? That's too bad, I recently used it for a project and it worked well. I even added some commands myself, to support color.

Anyway: PDF is based on Postscript. In PostScript, the string delimiters are parens. That's the cause of the problems, and why it doesn't break with brackets and braces. The way around it, is to escape the parens, any parens, if PDF supports it, with a backslash. The backslash itself must be special, too.

Let me pull in the PDF docs, from PDFReference.pdf:

3.2.3 String objects — literal strings
Any characters may appear in a string except unbalanced parentheses and the backslash,which must be treated specially. Balanced pairs of parentheses within a string require no special treatment.
The "special treatment" is pretty much as in Perl: preceding each special non-word character with a backslash; newline can be represented by "\n" and a tab with "\t". No surprise there. And finally, you can use octal representation with 3 digits, again, just like in Perl: "\ddd".

That should be enough to get you on your way, I suppose. You can check the table at page 30 from the above PDF file (warning: huge file: 9MB), that is the 50th page in the document.

p.s. It seems that quite a few people are rather fond of this module, including myself. If the original author is no longer interested in supporting it, perhaps somebody else should pick it up. How does one go about, in order to do that? (BTW the best place to escape the backslashes and the parens, would be in the module.)

  • Comment on Re: How do I replace certain character if condition exists

Replies are listed 'Best First'.
Re: Re: How do I replace certain character if condition exists
by JamesNC (Chaplain) on Apr 17, 2003 at 16:38 UTC
    Great Job Bart.. could you post your additions to add color? Sounds great :)
      could you post your additions to add color? Sounds great :)
      Sure. Eventually, I'd like to get it on CPAN, but I'm not sure how long it can still take, so in the meantime, here's my add-on module for PDF::Create, which I gave the name PDF::Create::Extensions. All you need is this extra file, which adds a few methods to PDF::Create::Page, and they're available as soon as you do
      use PDF::Create; use PDF::Create::Extensions;
      You can create two kinds of colour, "linecolor" (for lines) and "fillcolor" (for area fills). For each, you can set the color in the same way, in RGB ("RGB" or "RG": red, green, blue, each value ranging from 0 to 1, less is darker), grayscale ("GRAY", "GREY" or "G", 1 value from 0 (white) to 1 (black); and CMYK ("CMYK" or "K", 4 values from 0 to 1, more is darker), like this:
      $page->linecolor(RGB => 0.6, 0.2, 0.2);
      The color type is case insensitive.

      The second thing you can set, is line width, line connection style ("join": styles "miter", "round", "bevel"), and line end style ("cap": styles "butt", "round", "square" (="projecting square")), like this:

      $page->linewidth(0.8, 'join' => 'miter');
      See the PDF documentation on what the possibilities represent, or just experiment with these options. Again, the names are case insensitive.

      Save the next code as PDF/Create/Extensions.pm somewhere in your @INC

        Wow bart! Very cool. Very easy to use. Thanks a million.

        peppiv

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://251189]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found