Wow. Two questions and two doozies. Dynamically determining column width from data is really really difficult, particularly for outputs which are paginated, dynamically formatted, and printed. It could've been fixed pretty easily, except for the fact that PDF::Template is a single-pass transformer. All the fixes require a two-pass engine and rewriting the engine just for this situation was deemed too much work for the effort.
The best solution I've found is to use percentages and keep tweaking. Alternately, you can actually have the widths be variable and calculate things in your code.
As for more permanent solutions, take a look at Excel::Template::Element::Cell::AutoSize. While it's for Excel::Template and not PDF::Template, they were written off the same engine (E::T is just a rewrite of P::T) and so the technique of adding your own elements dynamically works the same for both.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] |
You may need to drop into plain PDFLib to do this, IIRC the latest version supports a table-type layout, not sure how much automatic formatting it will do for you. You can always concat two (or more) PDFs using CAM::PDF if you find that you need to generate them seperately.
How can I translate this to textbox width?
PDFLib supplies a way to get the width of a given string using the currently selected font, I don't recall the function name right now, but it should be easy enough to find looking at the manual.
| [reply] |
Thanks for your replies. I am able to use the PDFLib method
$pdf->string_width(text => 'text')
On another note, does anyone know if I can set the pdf width? Thus far I see only page types (A3, A4, etc). Thanks again. | [reply] [d/l] |