PDF::FromHTML(3pm)
PDF::FromHTML πβ¨
okay bestie, so this is a User Contributed Perl Documentation page for PDF::FromHTML (that's the 3pm one, iykyk) and it's literally about turning your HTML into PDF. no cap. let's get into it π«Ά
πΈ NAME πΈ
PDF::FromHTML β Convert HTML documents to PDF. that's it. that's the whole vibe. HTML in, PDF out, iconic behaviour π
β¨ SYNOPSIS β¨
okay so here's how you actually use it, copy-paste girlies rise:
my $pdf = PDF::FromHTML->new( encoding => 'utf-8' );
# Loading from a file:
$pdf->load_file('source.html');
# Or from a scalar reference:
# $pdf->load_file(\$input);
# Perform the actual conversion:
$pdf->convert(
# With PDF::API2, font names such as 'traditional' also works
Font => 'font.ttf',
LineHeight => 10,
Landscape => 1,
);
# Write to a file:
$pdf->write_file('target.pdf');
# Or to a scalar reference:
# $pdf->write_file(\$output);
see how it's got file mode and scalar reference mode? versatile queen π
π¦ DESCRIPTION π¦
This module transforms HTML into PDF, using an assortment of XML transformations implemented in PDF::FromHTML::Twig. so it's not doing some cursed regex magic, it's doing proper XML transformations. we love a structured approach fr fr β¨
There is also a command-line utility, html2pdf.pl, that comes with this distribution. so if you're not about that Perl life, you still got options π
π PUBLIC METHODS π
convert(%params)
Convert the loaded file to PDF. π Valid parameters are:
PageWidth 640
PageResolution 540
FontBold 'HelveticaBold'
FontOblique 'HelveticaOblique'
FontBoldOblique 'HelveticaBoldOblique'
LineHeight 12
FontUnicode 'Helvetica'
Font (same as FontUnicode)
PageSize 'A4'
Landscape 0
so those are your knobs and dials, bestie β PageWidth defaults to 640, PageResolution to 540, the bold/oblique font trio is all Helvetica-flavoured, LineHeight sits at 12, FontUnicode is 'Helvetica' and Font is literally just the same thing as FontUnicode, PageSize is 'A4' by default, and Landscape defaults to 0. set them to whatever your little heart desires π
π HINTS & TIPS π
<img> tags
Add the height and width attributes if you are creating the source HTML, it keeps PDF::FromHTML from having to open and read the source image file to get the real size. Less file I/O means faster processing. πβοΈπ¨
fr fr, this is the free performance glow-up. just tell it the size up front and it won't go digging through your image files like a nosy bestie. slay.
π CAVEATS π
okay this is the part where we have to be real with each other. π
Although PDF::FromHTML will work with both HTML and XHTML formats, it is not designed to utilise CSS.
This means any HTML using external or inline CSS for design and layout, including but not limited to: images, backgrounds, colours, fonts etc... will not be converted into the PDF. π«
To get an idea of the likely resulting PDF, you may wish to use an non-CSS capable browser for testing first.
There is currently no plan to adapt this module to utilise CSS. (Patches welcome, though!) π
no CSS bestie. none. zero. your beautiful gradient backgrounds and your cute little fonts? gone. not invited to the PDF party. test with a non-CSS capable browser first so you don't get jumpscared by the output π
π SEE ALSO π
html2pdf.plis a simple command-line interface to this module.PDF::FromHTML::Twig,PDF::Template,XML::Twig.
go read those too, the lore runs deep πβ¨
π«Ά CONTRIBUTORS π«Ά
Charleston Software Associates <info@charletonsw.com>
π AUTHORS π
Audrey Tang <cpan@audreyt.org>
β CC0 1.0 Universal β
To the extent possible under law, ει³³ has waived all copyright and related or neighboring rights to PDF-FromHTML.
This work is published from Taiwan.
<http://creativecommons.org/publicdomain/zero/1.0>
and that's the whole page, bestie!! π this doc came from perl v5.38.2 and it's dated 2024-07-28, so give it a lil kiss goodnight πβ¨ go forth and convert, you absolute icon ππ
π¦ 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