PHP code example of creativesynergy / silverstripe-wkhtmltopdf
1. Go to this page and download the library: Download creativesynergy/silverstripe-wkhtmltopdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
creativesynergy / silverstripe-wkhtmltopdf example snippets
php
$trainer = Trainer::get()->first();
$pdf = new SS_PDF();
$html = $pdf::getHtml($trainer);
$pdf->add($html);
$pdf->save('trainer.pdf');
php
$pdf->add('<html>...</html>'); // Html code
$pdf->add('.../path/to/page.html'); // Html file
$pdf->add('https://www.google.com'); // Website
$pdf->add($pdf::getHtml($dataObject)); // DataObject
php
$options = array(
'image-quality' => 100,
'margin-bottom' => 0,
'margin-left' => 0,
'margin-right' => 0,
'margin-top' => 0,
'header-html' => null,
'footer-html' => null
);
$pdf->add('.../path/to/cover.html', 'Cover', $options);
php
$variables = array(
'Title' => 'My New Title',
'MyFreakyWhatever' => DataObject::get()->byID(123)->WhatEver()
);
$html = $pdf::getHtml($trainer, $variables);
$pdf->add($html);
php
$html = $pdf::getHtml($trainer, $variables, 'NewPDFTemplate');
$pdf->add($html);
php
$pdf->preview();
php
$pdf->save('trainer.pdf'); // This will also return an file instance to work with
php
$pdf->setFolderName('trainers/pdfs');
php
$pdf->download('trainer.pdf');
php
$css = BASE_PATH . '/themes/' . SSViewer::current_theme() . '/css/pdf.css';
$header = BASE_PATH . '/mysite/templates/Pdfs/header.html';
$footer = BASE_PATH . '/mysite/templates/Pdfs/footer.html';
$options = array(
'enable-javascript',
'dpi' => 150,
'image-dpi' => 150,
'image-quality' => 100,
'user-style-sheet' => $css,
'header-html' => $header,
'footer-html' => $footer,
...
...
);
$pdf->setGlobalOptions($options);
php
$pdf->setOption('enable-javascript');
$pdf->setOption('dpi', '300');
$pdf->setOption('run-script', array(
'../path/to/local/script1.js'
));
$pdf->setOption('replace', array(
'{whatever}' => 'something new'
));
php
$pdf->removeOption('replace');
php
$pdf->setOption('header-html', '/path/to/header.html');
$pdf->removeOption('footer-html');
php
$pdf->setOption('user-style-sheet', '/path/to/pdf.css');