Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

[SOLVED] PDF::API2 and the Elusive Courier Font

by rsmeineke (Initiate)
on Nov 07, 2013 at 13:11 UTC ( [id://1061558]=perlquestion: print w/replies, xml ) Need Help??

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

Found it ....

in the PDF/API2/Resource/Font/CoreFont/courier.pm file I changed

'fontname' => 'Courier',

to

'fontname' => 'Courier-New',

and I added -New, in the other three courier-related files

'fontname' => 'Courier-New,Oblique',
'fontname' => 'Courier-New,Bold',
'fontname' => 'Courier-New,BoldOblique',

and now all is right with the world!

======================%< snip >%================================

I'm wondering if it is just me ...

I recently had need for the Courier font in some PDF output. I have been trying to use the corefonts in PDF::API2 but can't seem to get anything other than Courier-Oblique for output. The other corefonts seem to render fine. Here is a mini test program:

#!/usr/bin/perl use strict; use warnings; use PDF::API2; my @fonts = qw( Courier Courier-Bold Courier-BoldOblique Courier-Oblique Verdana Times Times-BoldItalic Georgia Georgia-Bold ); my $pdf = PDF::API2->new; my $page = $pdf->page; my $text = $page->text; my $y = 700; $text->translate( 100, $y ); foreach my $f (@fonts) { my $cft = $pdf->corefont($f); $text->font( $cft, 12 ); $text->text($f); $y -= 15; $text->translate( 100, $y ); } $pdf->saveas('pdftest.pdf'); $pdf->end();

I have tested this on a couple of my Linux boxes and always get the same result -- four lines of Courier-Oblique on the top. Any ideas where I might be going wrong?

Thanks, Robert M.

Replies are listed 'Best First'.
Re: PDF::API2 and the Elusive Courier Font
by hippo (Bishop) on Nov 07, 2013 at 14:02 UTC

    Your code as posted works fine for me (Fedora 64 Bit). Are you sure you have all the necessary fonts installed?

      +1
      It appears that you do not have courier font. Maybe courier-regular?
      You'll need to check your font dir. On *BSD, it's in any of the directories located in
      /usr/local/lib/X11/fonts
      HTH

      --Chris

      #!/usr/bin/perl -Tw
      use perl::always;
      my $perl_version = (5.12.5);
      print $perl_version;
Re: PDF::API2 and the Elusive Courier Font
by rnewsham (Curate) on Nov 07, 2013 at 14:16 UTC

    I have tested your code on one of my servers running CentOS 6.4 and it works for me.

Re: PDF::API2 and the Elusive Courier Font
by kschwab (Vicar) on Nov 08, 2013 at 05:07 UTC

    The "convert" utility that comes with Imagemagick is handy for finding which fonts are installed, and what their names are.

    $ convert -list font| grep -i courier Font: Courier family: Courier Font: Courier-Bold family: Courier Font: Courier-BoldOblique family: Courier Font: Courier-Oblique family: Courier Font: Courier-10-Pitch-Bold family: Courier 10 Pitch Font: Courier-10-Pitch-Bold-Italic family: Courier 10 Pitch Font: Courier-10-Pitch-Italic family: Courier 10 Pitch Font: Courier-10-Pitch-Regular family: Courier 10 Pitch

    If you're on a debian-derived linux: apt-get install imagemagick

      Thanks to all who responded to my initial inquiry. A quick note of follow-up.

      "convert" seems to think Courier is installed:

      robertm@sys76:~$ convert -list font |grep -i courier Font: Courier family: Courier Font: Courier-Bold family: Courier Font: Courier-BoldOblique family: Courier Font: Courier-Oblique family: Courier Font: Courier-10-Pitch-Bold family: Courier 10 Pitch Font: Courier-10-Pitch-Bold-Italic family: Courier 10 Pitch Font: Courier-10-Pitch-Italic family: Courier 10 Pitch Font: Courier-10-Pitch-Regular family: Courier 10 Pitch robertm@sys76:~$

      And here is the weird thing. When I used PDF::Create in a similar script all four versions of Courier are rendered perfectly. So PDF::Create is the obvious solution to this particular issue. I just wish I could figure out my problem with PDF::API2. It's starting to feel like a pernicious permissions problem, or similar. Puzzling.

      Thanks again, Robert M.

        I checked the source, and the $pdf->corefont() method pulls from 14 built-in fonts in the module itself...where their data is encoded in .pm files, here:

        /the_module_install_dir/lib/PDF/API2/Resource/Font/

        So, it's not looking at system installed fonts at all.Your issue is within the module itself.

        Since your code is working for others, I would guess you've got a borked installation of the module. You could find try the ttffont() or psfont() method instead, assuming you have ttf or pfm files for the desired fonts around. The convert utility shows the location of these. Or perhaps try reinstalling the module?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-16 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found