Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

print Unicode characters

by kalyanrajsista (Scribe)
on Jun 14, 2010 at 07:22 UTC ( #844533=perlquestion: print w/replies, xml ) Need Help??
kalyanrajsista has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I'm trying to print a string in my PDF along with a Unicode character like below

use strict; # sample string to be printed in PDF my $string = 'Number' . ' N with degree above';

How can I achieve this task.

Many Thanks

Replies are listed 'Best First'.
Re: print Unicode characters
by moritz (Cardinal) on Jun 14, 2010 at 07:49 UTC
    How do you generate the PDF?

    Most PDF writing modules in Perl don't support arbitrary Unicode characters, so it's often not as easy as just putting a Unicode character into a string (which you'd do with charnames).

    Perl 6 - links to (nearly) everything that is Perl 6.

      I'm generating PDF using PDF::Template module. Any suggestions please if it doesn't support Unicode characters.

        As I understand it, PDF's "built-in" fonts don't support Unicode characters. So for anything outside the Latin-1 range you need to embed a font.

        The PDF::Reuse module now supports embedding TrueType fonts and outputting non ASCII characters using Perl's internal character string format.

Re: print Unicode characters
by Khen1950fx (Canon) on Jun 14, 2010 at 08:33 UTC
    Following moritz's advice, I used charnames like this. I hope it gets you going.
    #!/usr/bin/perl use strict; use charnames ':full'; print "\N{LATIN CAPITAL LETTER A}\n", "\N{LATIN SMALL LETTER A}\n";

      Thanks for the inputs and suggest me if I'm going in right way...

      #!/usr/bin/perl use strict; use charnames ':full'; print "\N{LATIN CAPITAL LETTER N}", "\N{DEGREE SIGN}\n";
        I'm not quite sure what you mean by "degree sign". I kept getting a "wide character in print" warning. However, I think that this is what you're after:
        #!/usr/bin/perl use strict; use encoding 'utf8'; use charnames ':full'; print "\N{LATIN CAPITAL LETTER N WITH DOT ABOVE}\n";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://844533]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2017-07-27 00:41 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (402 votes). Check out past polls.