PHP code example of grasenhiller / silverstripe-wkhtmltox

1. Go to this page and download the library: Download grasenhiller/silverstripe-wkhtmltox 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/ */

    

grasenhiller / silverstripe-wkhtmltox example snippets


$pdf = new WkPdf();
$pdf->setFolder('folder/beneath/assets/to/save');

$pdf = new WkPdf();
$html = $pdf::get_html($obj, $variables = [], $template = '');

$pdf = new WkPdf();
$html = $pdf::get_html($obj);
$html = $pdf::replace_img_paths($html);

$pdf = new WkPdf();
echo '<pre>';
print_r($pdf->getOptions());
echo '</pre>;
die();

$pdf = new WkPdf();
echo $pdf->getOption('name_of_option');
die();

	private static $allowed_actions = [
		'pdfExport',
	];

	public function pdfExport() {
		$stylesheet = 'resources/vendor/grasenhiller/silverstripe-intranet-wiki/client/css/pdf.css';

		$filter = URLSegmentFilter::create();
		$filename = $filter->filter($this->MenuTitle);
		$filename .= '__' . date('Y-m-d') . '.pdf';

		$baseUrl = Director::absoluteBaseURL();

		$pdf = new WkPdf();
		$pdf->setOption('margin-top', 20);
		$pdf->setOption('margin-bottom', 20);
		$pdf->setOption('margin-left', 15);
		$pdf->setOption('margin-right', 15);
		$pdf->setOption('user-style-sheet', $stylesheet);
		$pdf->setOption('header-html', $baseUrl . 'gh-wkhtmltox/header?template=Grasenhiller\Intranet\Wiki\Pages\Pdf\Header');
		$pdf->setOption('footer-html', $baseUrl . 'gh-wkhtmltox/footer?template=Grasenhiller\Intranet\Wiki\Pages\Pdf\Footer');
		$pdf->setOption('header-spacing', 5);
		$pdf->setOption('footer-spacing', 5);

		$html = $pdf::get_html($this);

		$pdf->add($html);
		$pdf->download($filename);
	}
text
SS_WKHTMLTOX_USERNAME
SS_WKHTMLTOX_PASSWORD