G'day BernieC,

Here's a quick comparison of PDF-related modules.

PDF
As ++marto states, 23 years old and Active bugs. Probably abandonware; I'd suggest avoiding this one.
CAM::PDF
Suggested by AM. This is 10 years old; has a lot of bugs; and probably abandonware. See "CAM::PDF Error: Expected identifier label" for example problem and discussion.
PDF::API2
I'm most familiar with this one. It was last updated just 6 months ago. I did a quick test for the page count you were trying (code mostly just copied from the SYNOPSIS). I'm not sure what else you might want; perhaps "METADATA METHODS" is of interest.
$ perl -E ' use strict; use warnings; use PDF::API2; my $pdf = PDF::API2->new(); my $font = $pdf->font("Helvetica-Bold"); for my $p (1 .. 10) { my $page = $pdf->page(); my $text = $page->text(); $text->font($font, 20); $text->position(200, 700); $text->text("Page: $p"); } $pdf->save("test.pdf"); ' $ file test.pdf test.pdf: PDF document, version 1.4, 10 pages $ perl -E ' use strict; use warnings; use PDF::API2; my $pdf = PDF::API2->open("test.pdf"); say "Page count: ", $pdf->page_count(); ' Page count: 10
PDF::Builder
Suggested by marto. It was last updated just 4 months ago. I hadn't encountered this one previously. It's SYNOPSIS is almost identical to PDF::API2's. It may be a branch of PDF::API2 that's intended to provide improvements or enhancements; it mentions PDF::API2 a few times by way of comparison; I didn't see anything regarding a branch but I also didn't study the docs in detail. It has "METADATA METHODS" too.

See its README.md for possible hurdles to using this, such as requiring Perl v5.24; having said that, it installed first time for me using the cpan utility (I have Perl v5.36.0).

Given the similarities, I just repeated the test I did previously, replacing API2 with Builder and test.pdf with test2.pdf. At least in this respect, PDF::API2 and PDF::Builder function identically. If anyone has other information re PDF::API2 vs. PDF::Builder, please add comments.

$ perl -E ' use strict; use warnings; use PDF::Builder; my $pdf = PDF::Builder->new(); my $font = $pdf->font("Helvetica-Bold"); for my $p (1 .. 10) { my $page = $pdf->page(); my $text = $page->text(); $text->font($font, 20); $text->position(200, 700); $text->text("Page: $p"); } $pdf->save("test2.pdf"); ' $ file test2.pdf test2.pdf: PDF document, version 1.4, 10 pages perl -E ' use strict; use warnings; use PDF::Builder; my $pdf = PDF::Builder->open("test2.pdf"); say "Page count: ", $pdf->page_count(); ' Page count: 10

Update (additional information): I just noticed that the PDF produced by PDF::Builder is substantially bigger than that produced by PDF::API2. I would have expected them to be almost the same size.

ken@titan ~/tmp/pm_11152014_pdf $ ls -l total 16 -rw-r--r-- 1 ken None 4272 May 7 00:50 test.pdf -rw-r--r-- 1 ken None 7024 May 7 01:05 test2.pdf

— Ken


In reply to Re: Help with PDF module [comparison] by kcott
in thread Help with PDF module by BernieC

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.