Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best Perl module to use for creating a .pdf from scratch?

Tags:

pdf

perl

cpan

There are quite a number of modules on CPAN relating to the creation and manipulation of .pdf files, and I'm hoping this community can save me some time going down blind alleys.

I am looking to create .pdf files from scratch, with only simple formatting such as bold/italic and left/right/center justify. Being able to use a template file would nice, from an MVC perspective, but if the best module doesn't support that, I'm ok. I want the best module for my narrow problem set.

Edit: let's add the constraint that it does have to be a Perl module, if not a pure-perl solution. Thanks for answers thus far!

Update: PDF creation is one difficult problem to decide how to approach. In addition to the good suggestions here, there seems to be about 1,000 different ways to solve this, and knowing which solution(s) to invest your time in is a real challenge. It is easy to acquire dependencies on outside executables in the process of building this solution, which is why I have been favoring doing everything in Perl if possible.

I went down the road of trying to use PDF::Create but found it too limiting. You have to give coordinates to place each string of text and there is no built-in concept of text wrapping... this is all work you have to do. Impossible amount of overhead for my task.

I am now using PDF::API2, which is much more powerful than PDF::Create, but still demands the PDF be assembled at a troublingly low level. Luckily, there is some help online. See Rick Measham's excellent PDF::API2 tutorial with accompanying text_block() subroutine, which thankfully does the heavy lifting on the text wrap problem.

Unless you see another update here, this is the solution that ended up working for me.

like image 408
Marcus Avatar asked Feb 17 '09 13:02

Marcus


People also ask

How do I create a PDF in Perl?

use PDF::API2; use GD::Barcode::Code39; $pdf = PDF::API2->new(); $page = $pdf ->page();

What is PDF module?

The PDF module allows you to render PDF document. It is rather simple to use as it only requires to import a static file.


1 Answers

I'm the author of the CPAN module CAM::PDF which is definitely not the best tool for this job -- it's designed for high-performance editing, not creating.

Among free PDF creation libraries, I like PDF::API2 the best. It has a very rich feature set and good encryption support (inspired by CAM::PDF I might add!) The author, Alfredo, manages a popular email list. People sometimes complain about documentation, but I've found it to be adequate.

Among commercial libraries, I've had good experiences with pdflib.

like image 84
Chris Dolan Avatar answered Oct 19 '22 03:10

Chris Dolan