| Catalyst::View::Wkhtmltopdf - Catalyst view to convert HTML content to PDF using wkhtmltopdf |
Catalyst::View::Wkhtmltopdf - Catalyst view to convert HTML (or TT) content to PDF using wkhtmltopdf
# lib/MyApp/View/Wkhtmltopdf.pm
package MyApp::View::JSON;
use Moose;
extends qw/Catalyst::View::Wkhtmltopdf/;
__PACKAGE__->meta->make_immutable();
1;
# configure in lib/MyApp.pm
MyApp->config({
...
'View::Wkhtmltopdf' => {
command => '/usr/local/bin/wkhtmltopdf',
tmpdir => '/usr/tmp',
},
});
sub ciao : Local {
my($self, $c) = @_;
# Pass some HTML...
$c->stash->{wkhtmltopdf} = {
html => $web_page,
};
# ..or a TT template
$c->stash->{wkhtmltopdf} = {
template => 'hello.tt',
page_size => 'a5',
};
# More parameters...
$c->stash->{wkhtmltopdf} = {
html => $web_page,
disposition => 'attachment',
filename => 'mydocument.pdf',
};
$c->forward('View::Wkhtmltopdf');
}
Catalyst::View::Wkhtmltopdf is a Catalyst View handler that converts HTML data to PDF using wkhtmltopdf (which must be installed on your system). It can also handle direct conversion of TT templates (via the Catalyst::View::TT manpage).
The stash key which contains data and optional runtime configuration to pass to the view. Default is wkhtmltopdf.
Name of URI parameter to specify JSON callback function name. Defaults
to callback. Only effective when allow_callback is turned on.
The full path and filename to the wkhtmltopdf command. Defaults to /usr/bin/wkhtmltopdf.
An arrayref of allowed paths where wkhtmltopdf can find images and other linked content. The temporary directory is added by default. See wkhtmltopdf documentation for more information.
The content-disposition to set when sending the PDF file to the client. Can be either inline or (default) attachment.
The filename to send to the client. Default is output.pdf.
Page size option (default: a4). See wkhtmltopdf documentation for more information.
Parameters are passed fvia the stash:
$c->stash->{wkhtmltopdf} = {
html => $web_page,
};
You can pass the following configuration options here, which will override the global configuration: disposition, filename, page_size.
Other options currently supported are:
Width and height of the page, overrides page_size.
Margins, specified as 3mm, 0.7in, ...
Have a look at wkhtmltopdf documentation for more information regarding these options.
At present time this library just uses UTF-8, which means it should work in most circumstances. Patches are welcome for support of different character sets.
wkhtmltopdf command should be available on your system.
More configuration options (all the ones which wkhtmltopdf supports, likely) should be added. Also, we'll wanto to allow to override them all at runtime.
We might want to use pipes (the IPC::Open2 manpage) instead of relying on temp files.
And yes... we need to write tests!
Project in on GitHub:
https://github.com/lordarthas/Catalyst-View-Wkhtmltopdf
Michele Beltrame <mb@italpro.net>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Catalyst, the Catalyst::View::TT manpage
http://code.google.com/p/wkhtmltopdf/
| Catalyst::View::Wkhtmltopdf - Catalyst view to convert HTML content to PDF using wkhtmltopdf |