The pdfgeneration module uses css2xslfo to generate PDFs from SilverStripe templates.
Sam Minnée (sam at silverstripe dot com)
To generate a PDF, you will first need to make an HTML/CSS template that will provide the content of the PDF.
In both of these examples, $objToBeRendered
is going to be rendered with MyTemplateName.ss
.
Use this syntax to send a PDF file to the user. You could define this as a method on a controller, for example:
function downloadpdf() {
$objToBeRendered = $this;
$pdf = new PDFGenerator($objToBeRendered, 'MyTemplateName', 'my-pdf-filename.pdf');
return $pdf->sendToBrowser();
}
Alternatively, use this syntax to save a PDF file to a location on the server:
$pdf = new PDFGenerator($objToBeRendered, 'MyTemplateName', "my-pdf-filename.pdf");
$pdf->generate("../assets/my-pdf-filename.pdf");
For more information on how to design your HTML/CSS, see the css2xslfo manual.
By default, pdfgeneration/fonts
is used as the font directory. It contains a single font,
DejaVuSans, including it's bold, italic, and bold italic forms.
If you wish to specify your own fonts, you should create a directory containing the necessary TTF files. To specify normal, bold, italic, and bold-italic variations of a single font, you should name the files using the following pattern.
MyFont.ttf
MyFont Bold.ttf
MyFont Italic.ttf
MyFont Bold Italic.ttf
You can then load the new font directory into your PDFGenerator
object like so:
$pdf->setFontDir('mysite/fonts');