Perl Pdf Create

Active2 years, 5 months ago
  1. Perl Create Pdf From Html
  2. Learning Perl Pdf
  3. Adobe Pdf Creator Free Download

Dealing with files in Perl is very easy once you get used to the slightly odd syntax. Here are some examples to get you started. Open a File in Perl. To open a file in Perl, just the open subroutine. Here's an example of a program that opens a file, reads the file one line at a time and prints each line to the terminal. Perl 6 is a sister language, part of the Perl family, not intended as a replacement for Perl 5, but as its own thing - libraries exist to allow you to call Perl 5 code from Perl 6 programs and vice versa.

Perl Pdf Create

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.

Perl Create Pdf From Html

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

Marcus
MarcusMarcus
2,9607 gold badges30 silver badges56 bronze badges

6 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.

Chris DolanChris Dolan
7,4301 gold badge27 silver badges67 bronze badges

Three modules for creating PDF come to mind (in no particular order)....

PDF::Template gives you that template option you maybe hankering for? PDF::Create seems more straightforward (at least from the docs) and may meet your 'simple formatting' requirement more adequately.

However if you want to know what the 'community' thinks then only PDF::API2 gets a rating on CPAN Ratings coming in with 4 out of 5 stars overall score.

Hope that helps.

PS. Disclaimer: I've not used any of these modules. In past I've always gone for XML/XSLT/XSL-FO using Apache FOP with Perl being used to create the initial XML data. This can be an overkill for something small and not always ideal if you want to embed PDF generation into your Perl app.

PPS. So I'll also be looking at these CPAN PDF modules at some point in near future!

AndyG
29k7 gold badges75 silver badges114 bronze badges
draegtundraegtun
21.3k5 gold badges43 silver badges70 bronze badges

Does it have to be a Perl module? You could always use LaTeX and convert that to PDF. Not quite as straight-forward, but it is another option.

Glen SolsberryGlen Solsberry
7,11110 gold badges63 silver badges89 bronze badges

G'day Marcus,

Glad you found the tutorial. I do a lot of work in PDF::API2, so if there's anything I can help with, just let me know.

Naturally, I recommend PDF::API2!

There's a guy Jay Hannah, who's currently turning the text block into a module for CPAN that does exactly what you want: bold, italic, etc. If you check the mailing list, you'll see his posts at the top.

Cheers!

Rick Measham

RickMeashamPerl Pdf CreateRickMeasham
6931 gold badge7 silver badges22 bronze badges

Yeah, tough to answer without knowing exactly what your constraints are. If pure-Perl is not a necessity, I'd be inclined towards DocBook.

The initial markup you'll generate can be very simple XML; and the transformation requires just an XSL processor and shelling out to something like Apache's FOP.

Paul Roub

Learning Perl Pdf

Paul Roub
33.3k8 gold badges62 silver badges77 bronze badges

how to save a online pdf file using perl?http://www.nwcc.bc.ca/FNC/pdfs/Stepping%20Stones%20to%20improved%20Relationships%20-%20web.pdf

I am using file::download. but the problem is its not downloading url with url encoded strings.

sharma

sharma

Adobe Pdf Creator Free Download

Not the answer you're looking for? Browse other questions tagged perlpdfcpan or ask your own question.