silverstripe-module silverstripe-pdf
Provide PDF renders of your webpages or objects using SSViewer, Snappy and wkhtmltopdf
betterbrief/silverstripe-pdf
Provide PDF renders of your webpages or objects using SSViewer, Snappy and wkhtmltopdf
- Friday, February 9, 2018
- by willmorgan
- Repository
- 4 Watchers
- 12 Stars
- 3,599 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 2 Forks
- 1 Open issues
- 3 Versions
- 4 % Grown
SilverStripe PDF Extension
Have you ever wanted to deliver your SilverStripe website's content in a slow and bloated format? If you have, this module fulfils your needs!, (*1)
Install
- Use Composer:
composer require betterbrief/silverstripe-pdf
- Install the correct version of
wkhtmltopdf
...
- The version of the binary you use is dependent on your architecture. To find out the architecture your server is running, type
arch
in your terminal window. With the development environment, we use amd64.
Set up
- Once you have got the module from composer, you will need to get the wkhtmltopdf binary and then configure PDFExtension to point to it. The composer suggestions give you your options.
- Add
PDFExtension
to the objects you wish to render to PDF.
Config example
PDFExtension:
wkhtmltopdf_binary: '/vagrant/www/vendor/bin/wkhtmltopdf-amd64'
MyDataObject:
extensions:
- PDFExtension
Use it
- Author your template file called
MyDataObject_pdf.ss
in a suitable directory within your templates folder. Note that you can override this name if you wish to do so.
- If this is a standalone file, you will need to include the base tag so assets are rendered correctly. In your template:
<% base_tag %>
- Congratulations, you can now call
MyDataObject->generatePDF()
and get your PDF data.
- If you wish to send the output to the browser, you'll need to set your response body to
generatePDF()
's response, use SS_HTTPResponse->addHeader('Content-Type', 'application/pdf')
.
- To force a download,
SS_HTTPResponse->addHeader('Content-Disposition', 'attachment')
Configuration
You can configure generation on a call-by-call basis by modifying the PDFExtension->generatePDF()
parameters.
* Use the $userOptions
parameter to pass in Snappy / wkhtmltopdf options. Here's the full list.
* Use $variables
to pass in your standard SSViewer template variables. Note that by default enable-javascript
is turned off., (*2)
Config Option |
Default |
How to use |
wkhtmltopdf_binary |
null |
Set this to the absolute location of wkhtmltopdf, otherwise nothing will work. |
render_host |
http://localhost/ |
As the page is generated on the server, the public facing host will typically not be accessible, and instead be localhost. You may want to change this when deploying to distributed environments. |
Things to note
- Pages are generated in the context of the current session. So if the requesting user is a logged in administrator, the PDF will be generated with that member's state and permission level.
- It is advisable to get the following packages to avoid graphic / font issues with rendering: fontconfig, libXrender, libXext and urw-fonts. You can get these on CentOS with
yum install fontconfig libXrender libXext urw-fonts
Requirements
-
wkhtmltopdf will take the HTML you generate and create a PDF document out of it using Webkit as the rendering engine.
-
Knp's Snappy provides the bridge functionality between wkhtmltopdf and PHP
Licensing
- silverstripe-pdf's code is made available to you under the BSD license (see LICENSE)
- As of 2014-05-30, Knp Snappy is under the MIT license
- As of 2014-05-30, wkhtmltopdf is under the LGPL license.
dev-master
9999999-dev
Provide PDF renders of your webpages or objects using SSViewer, Snappy and wkhtmltopdf
Sources
Download
BSD
BSD-3-Clause
The Requires
silverstripe
pdf
1.0.0.x-dev
1.0.0.9999999-dev
Provide PDF renders of your webpages or objects using SSViewer, Snappy and wkhtmltopdf
Sources
Download
BSD-3-Clause
The Requires
silverstripe
pdf
v1.0.0
1.0.0.0
Provide PDF renders of your webpages or objects using SSViewer, Snappy and wkhtmltopdf
Sources
Download
BSD-3-Clause
The Requires
silverstripe
pdf