NAME
Catalyst::View::Wkhtmltopdf - Catalyst view to convert HTML (or TT) content to PDF using wkhtmltopdf
VERSION
version v0.6.0
SYNOPSIS
# lib/MyApp/View/Wkhtmltopdf.pm
package MyApp::View::Wkhtmltopdf;
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',
# Guessed via File::Spec by default
tmpdir => '/usr/tmp',
# Name of the Template view, "TT" by default
tt_view => 'Template',
},
});
sub ciao : Local {
my($self, $c) = @_;
# Pass some HTML...
$c->stash->{wk} = {
html => $web_page,
};
# ..or a TT template
$c->stash->{wk} = {
template => 'hello.tt',
page_size => 'a5',
};
# More parameters...
$c->stash->{wk} = {
html => $web_page,
disposition => 'attachment',
filename => 'mydocument.pdf',
};
$c->forward('View::Wkhtmltopdf');
}
DESCRIPTION
Catalyst::View::Wkhtmltopdf is a Catalyst view handler that converts HTML data to PDF using wkhtmltopdf. It can also handle direct conversion of Template-Toolkit templates via Catalyst::View::TT.
METHODS
process
Generated the PDF as epr parameters in `$c->stash->{wkhtmltopdf}` or other configured stash key. Calls "render" to perform actual rendering. Output is stored in $c-response->body>.
It is possible to forward to the process method of the view from inside Catalyst:
$c->forward('View::Wkhtmltopdf');
However, this is usually done automatically by Catalyst::Action::RenderView.
render
Generates a PDF from the arguments in \%args and returns it. Arguments are the same one would place in the stash key for rendering + output via process(), but the following are (of course) ignored: disposition, filename (as they only apply when outputting the content to the client).
You can pass a template_args key inside the arguments hashref, which will be passed to Catalyst::View::TT's render method. If not supplied, undef will be passed, so the TT view method will behave as per its documentation.
STATUS
The wkhtmltopdf project is no longer being maintained, and this module will be deprecated in a later release.
See "SECURITY CONSIDERATIONS".
CONFIG VARIABLES
All configuration parameters are optional as they have a default.
- stash_key
-
The stash key which contains data and optional runtime configuration to pass to the view. Default is wk.
- tmpdir
-
Default: guessed via
File::Spec::tmpdir().Name of URI parameter to specify JSON callback function name. Defaults to
callback. Only effective whenallow_callbackis turned on. - command
-
Default:
/usr/bin/wkhtmltopdf.The full path and filename to the wkhtmltopdf command. Defaults to /usr/bin/wkhtmltopdf.
- allows
-
Default: the temporary directory.
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.
- disposition
-
Default:
inline.The content-disposition to set when sending the PDF file to the client. Can be either inline or (default) attachment.
- filename
-
Default: output.pdf.
The filename to send to the client.
- page_size
-
Default:
A4.Page size option. See wkhtmltopdf documentation for more information.
- orientation
-
Default:
portrait.Orientation option. See wkhtmltopdf documentation for more information.
PARAMETERS
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:
- page_width
- page_height
-
Width and height of the page, overrides page_size.
- margin_top
- margin_right
- margin_ bottom
- margin_left
-
Margins, specified as 3mm, 0.7in, ...
- dpi
- image_dpi
- image_quality
- title
- greyscale
- lowquality
- quiet
- no_background
- no_images
- disable_javascript
- print_media_type
Have a look at wkhtmltopdf documentation for more information regarding these options.
Other options can be added to the "command".
SECURITY CONSIDERATIONS
Do not use wkhtmltopdf with untrusted HTML.
The wkhtmltopdf project is no longer being maintained, and the underlying QtWebKit libraries that it uses have been unsupported since 2015.
The git repository was archived as read-only in 2023.
You should consider migrating to alternative solutions.
SEE ALSO
SOURCE
The development version is on github at https://github.com/robrwo/Catalyst-View-Wkhtmltopdf and may be cloned from https://github.com/robrwo/Catalyst-View-Wkhtmltopdf.git
Note that the git repository has changed since version v0.6.0.
SUPPORT
Only the latest version of this module will be supported.
Future releases may only support Perl versions released in the last ten (10) years.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-View-Wkhtmltopdf
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Reporting Security Vulnerabilities
If the bug you are reporting has security implications which make it inappropriate to send to a public issue tracker, then see SECURITY.md for instructions how to report security vulnerabilities.
AUTHOR
Michele Beltrame <mb@italpro.net>
This module is currently maintained by Robert Rothenberg <perl@rhizomnic.com>.
CONTRIBUTORS
Jens Gassmann <jens.gassmann@atomix.de>
Robert Rothenberg <perl@rhizomnic.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011-2018, 2026 by Michele Beltrame <mb@italpro.net>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.