in reply to PDF::API2 Questions

Or will it be best to create each and every document from scratch every time?

For one, it depends on the complexity of the document.  With simple/short documents it's probably "best" to create them from scratch every time — in case you want to operate at the PDF level yourself (like you would when using PDF::API2), and not use some higher level layout package like latex.

As for working with PDF templates, you should be aware that PDF is not a language for laying out documents, but rather a language for low-level description/rendering of drawing instructions, like "print those glyphs or lines at position x,y".  In other words, it doesn't do automatic paragraph layout, text block wrapping, page breaks, etc.

Also, the format doesn't lend itself particularly well to being templated directly, as it typically contains compressed content streams (which you could only modify in uncompressed form), and because the PDF file holds an index table specifying the byte offset of every "object" in the file (not the document index you see in a PDF viewer, but an internal one). When you modify one object in size, all offsets of the objects that follow in the document will have to be adjusted accordingly.

In case you really want to do templating directly at the PDF level, I'd suggest you use pdftk in combination with a template in uncompressed form.  In this case, you could essentially use any text templating module (though it would of course require a reasonable understanding of how PDF works), and pdftk would then handle compressing the document and recomputing the internal object offsets.  I wouldn't recommend this approach, however, unless you are (or want to become) familiar with the guts of PDF, and are making only minor changes, like filling in a few names or addresses, etc.

Replies are listed 'Best First'.
Re^2: PDF::API2 Questions
by akwe-xavante (Acolyte) on Mar 14, 2012 at 09:06 UTC

    Thank you for your reply

    Much of your words don't mean much at all at this point, but I’m sure they will at some point in the future.

    My knowledge of PDF::API2 at this moment is restricted to creating a one page PDF document with just one centralised line of text, that's the full extent of my knowledge right now

    My assumption is that my PDF document will be a simple one right now. Billing address aligned left, my details aligned right but opposite each other. An invoice number and date. Details about the service or repair carried out. A list of parts / materials used and costs involved. A total, a box where i can add cautionary notes, comments and observations the customer should be aware of etc, in other words a box where additional text can be added at the bottom. An image / logo perhaps, a clickable link to visit my website.

    I don't want make things unnecessarily complex at this early stage.

    I receive many an automatically created PDF receipt on a daily basis from my suppliers, i suppose i should analyse them to see what's achievable and work on that, perhaps use LibreOffice and M$ office to create something as a goal to aim for! Then for now explore PDF::API2 to see what i can achieve.

    Meanwhile if anybody else can offer a little advice that would be good too, I’m sure I’ll be back with Oooodles of questions and problems to resolve in the near future.