PDF::F...emplate(3pm)
β¨ NAME β¨
PDF::FromHTML::Template β yes bestie, it's literally called PDF::FromHTML::Template, that's the whole vibe π
πΈ SYNOPSIS πΈ
use PDF::FromHTML::Template;
my $pdf = PDF::FromHTML::Template->new({
file => 'some_template.xml',
});
$pdf->param(%my_params);
print "Content/type: application/pdf\n\n", $pdf->get_buffer;
$pdf->write_file('some_file.pdf');
π DESCRIPTION π
NOTE: This is a fork of PDF::Template 0.30, originally released by Rob Kinyon, but (as of September 11, 2006) currently not available on CPAN. Use of this module outside PDF::FromHTML is not advised.
PDF::FromHTML::Template is a PDF layout system that uses the same data structures as HTML::Template. No cap. π«Ά
π¦ OVERVIEW π¦
PDF::FromHTML::Template is a PDF layout system that uses the same data structures as HTML::Template. But here's the plot twist: unlike HTML::Template, this is a full layout system. That means you have to describe where each item will be on the page. Like, you're the main character here, bestie. (This is in contrast to HTML::Template, which adds on to HTML::Templateut is determined by the HTML, not HTML::Template.)
PDF::FromHTML::Template uses an XML document as the template. However, the XML is not completely compliant β the only difference (that I'm aware of) is that any node can have any parameter. (This prevents the creation of a DTD.) The reason for this is to allow scoping by parents for parameters used by children. (More on this later, iykyk.)
Every node in the document corresponds to an object, with each parameter mapping (mostly) 1 to 1 to an object attribute. Parent-child relationships are strictly preserved. Each parent provides a scope (similar to variable scope) to its children. (This is why any node can have any parameter.) If a child needs the value of a parameter and it doesn't have that value as an attribute, it will ask its parent for the value. If the parent doesn't have it, it will ask its parent, and so on. It's giving β¨generational trauma but for variable lookupβ¨.
π METHODS π
new( [$opts] )β This will create a new instance ofPDF::FromHTML::Template.$optsis an optional hashref that can contain the following parameters:fileβ This is either the name of the file or the filehandle of the open file. If it is present,parse()will be called upon that filename/filehandle. Otherwise, afternew()is called, you will have to callparse()yourself. (filenameis a synonym forfile.)openactionβ This is the action that the PDF reader will take when it opens this file. The valid values are:fitboxfitheightfitpage(default)fitwidthretain
openmodeβ This is the mode that the PDF reader will use when it opens this file. The valid values are:bookmarksfullscreennone(default)thumbnails
infoβ This is a hashref of information that you wish to have the PDF retain as metadata. If this is not present, bothAuthorandCreatorwill be set toPDF::FromHTML::Template.
The following keys are not supported:
CreationDateProducerModDateTrapped
pdf_encodingβ This is the encoding that the template is in. It defaults to the host encoding. This is different from theencodingparameter for thepdftemplatetag. π
parse( $file )β This will parse the XML template into the appropriate datastructure(s) needed forPDF::FromHTML::Templateto function. π§parse_xml( $file )β This is a deprecated synonym forparse()."param( key =" value, [ key => value, ... ] )>β This will set the parameters thatPDF::FromHTML::Templatewill use to merge the template with. This method is identical to theHTML::Templateor Template Toolkit method of the same name.write_file( $filename )β This will write the rendered PDF to the file specified in$filename.get_buffer()β This will return the rendered PDF stringified in a form appropriate for returning over an HTTP connection.output()β This is a synonym forget_buffer()provided forHTML::Templatecompatibility. πregister( ... )βXXX
π USAGE π
There are a few consistency rules that that every PDF::FromHTML::Template has to follow. Yes, the rules are rule-ing. π
- The root node is called
PDFTEMPLATE - There must be at least one
PAGEDEF(which does not have to be a direct child of thePDFTEMPLATEnode) - All rendering elements (include
FONTtags) must be within aPAGEDEFnode - There must be a
FONTtag as an ancestor of everyTEXTBOXnode - Within a
PAGEDEF, there can only be oneHEADERnode and oneFOOTERnode
For more information about each node, please see the POD for that class. π
π WWW CAVEATS π
When taking an HTML page and adding a PDF option, there are a few differences to take into account. The primary one is the idea of pagebreaks. HTML is displayed as a single page, with scrolling. Paper doesn't scroll, bestie β it just sits there. So when there should be a new page is something PDF::FromHTML::Template works very hard at determining. It will take into account any header and footer information you've provided, as well as page sizes.
The second is that you have to determine how wide you want your text to be. One of the most common activities is to take a tabular report and covert it to a PDF. In HTML, the browser handles text width for you. Right now, there isn't a TABLE tag (though work is being done on it). So, you have to layout out your TEXTBOX nodes by hand. (See the EXAMPLES for some ideas on this.) That said, it really isn't that hard. TR/TH tags convert to ROW tags easily, and TD tags are basically TEXTBOX tags. Add a few width="20%" (or whatever) and you're fine. Slay. π
π BUGS π
None, that I'm aware of. π
π§ LIMITATIONS π§
Currently, the only PDF renderer PDF::FromHTML::Template supports is PDFlib (available at www.pdflib.com). The next release of PDF::FromHTML::Template will also support PDF::API2. Unless you need Unicode support, PDFlib Lite is sufficient (and free). Please see <http://www.pdflib.com> for more details.
I am aware that PDFlib will not compile under AIX or Cygwin. These are problems that PDFlib has acknowledged to me. π
π AUTHOR/MAINTAINER π
Originally written by Dave Ferrance (dave@ferrance.org)
Taken over after v0.05 by Rob Kinyon (rob.kinyon@iinteractive.com)
πΈ CONTRIBUTORS πΈ
Patches and ideas provided by:
- Audrey Tang β Provided the impetus to move to
PDF::Writer(which she also wrote). - Michael Kiwala β Aided in the design and testing of the transition from Dave Ferrance's version.
- Nathan Byrd β Provided nearly all the initial doublebyte expertise.
Additionally, there is a mailing list at <http://groups.google.com/group/PDFTemplate> π«Ά
β COPYRIGHT β
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π₯ SEE ALSO π₯
and that's the whole page, bestie π this icon of a doc shipped as part of perl v5.38.2 and got its timestamp on 2024-07-28 β go forth and template, you absolute legend πβ¨
π¦ where this page comes from
- debian trixie: libpdf-fromhtml-perl 0.34-1 Β· CC0-1.0
- ubuntu resolute: libpdf-fromhtml-perl 0.34-1 Β· CC0-1.0
- ubuntu stonking: libpdf-fromhtml-perl 0.34-1 Β· CC0-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms