Generate PDF using WeasyPrint
This plugin generates PDF using the third-party tool
WeasyPrint.
You will have to download this tool and install it on the Foswiki Server before being able to use it for Foswiki.
Usage
Get a PDF by adding
contenttype=application/pdf
to the view url like this:
%SCRIPTURL{"view"}/%WEB%/%TOPIC%?contenttype=application/pdf&cover=print
Optionally an url parameter
outfile
can be used to specifiy the target filename of the pdf being generated.
If not specified explicitly it defaults to
genpdf_%!TOPIC%.pdf
%SCRIPTURL{"view"}/%WEB%/%TOPIC%?contenttype=application/pdf&cover=print&outfile=myreport.pdf
Installation Instructions
Installation instructions for
weasyprint
can be found on
their site.
For a Debian/Ubuntu based installation use this:
apt-get install python-dev python-pip python-lxml \
libcairo2 libpango1.0-0 libgdk-pixbuf2.0-0 \
libffi-dev shared-mime-info
pip install WeasyPrint
Test with
weasyprint --help
Make sure that you record the full path to the binary and configure this plugin accordingly.
which weasyprint
Most probably, when installing
weasyprint
manually, this will be
/usr/local/bin/weasyprint
as is the default in this plugin's
configuration.
If you are using other plugins that implement a
completePageHandler
(see
InstalledPlugins) then you most
probably need to tune the
$Foswiki::cfg{PluginsOrder}
to list the
GenPDFWeasyPlugin behind those, for example like this:
$Foswiki::cfg{PluginsOrder} = 'SpreadSheetPlugin,PageOptimizerPlugin,NatSkinPlugin,GenPDFWeasyPlugin,SlideShowPlugin';
Fonts
Note that
weasyprint
does not (yet) understand
@font-face
. To make use of custom fonts you will need to install them on the server itself.
Recommended font packages on a debian/ubuntu system:
apt-get install fonts-font-awesome fonts-lato fonts-roboto ttf-mscorefonts-installer
You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.
Open configure, and open the "Extensions" section. "Extensions Operation and Maintenance" Tab -> "Install, Update or Remove extensions" Tab. Click the "Search for Extensions" button.
Enter part of the extension name or description and press search. Select the desired extension(s) and click install. If an extension is already installed, it will
not show up in the
search results.
You can also install from the shell by running the extension installer as the web server user: (Be sure to run as the webserver user, not as root!)
cd /path/to/foswiki
perl tools/extension_installer <NameOfExtension> install
If you have any problems, or if the extension isn't available in
configure
, then you can still install manually from the command-line. See
https://foswiki.org/Support/ManuallyInstallingExtensions for more help.
Dependencies
None
Change History
12 Nov 2019 |
don't append the html page to the end of the pdf output |
11 Jul 2016 |
added option pdfdisposition to inline or redirect content; remove leftovers from copy-pasting GenPDFPrincePlugin |
16 Sep 2015 |
initial release |