1. Go to this page and download the library: Download restruct/wkhtmltopdf-static 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/ */
restruct / wkhtmltopdf-static example snippets
use Restruct\WkhtmltoPdf\WkhtmltoPdf;
// HTML string → PDF file
$result = WkhtmltoPdf::create()
->margins('0px', '0px', '0px', '0px')
->allowPath('/path/to/assets') // when HTML references local CSS/images, see "Security"
->disableSmartShrinking() // fixes 0.12.4→0.12.6 scaling differences
->generateFromHtml($html, '/path/to/output.pdf');
// HTML string → raw PDF bytes (throws RuntimeException on failure)
$pdfBytes = WkhtmltoPdf::create()->getOutputFromHtml($html);
// URL → PDF file
WkhtmltoPdf::create()->generateFromUrl('https://example.com/', '/path/to/output.pdf');
// Before (Snappy)
$snappy = new \Knp\Snappy\Pdf($binaryPath);
$snappy->generateFromHtml($html, $file, $options, true);
// After
WkhtmltoPdf::create()->setOptions($options)->generateFromHtml($html, $file);
use Restruct\WkhtmltoPdf\WkhtmltoPdfStatic;
WkhtmltoPdfStatic::isAvailable(); // true if either strategy works
WkhtmltoPdfStatic::getStrategy(); // 'binary' | 'docker' | ''
WkhtmltoPdfStatic::version(); // "wkhtmltopdf 0.12.6.1 (with patched qt)"
bootstrap.php constant resolution (WKHTMLTOPDF_PATH / _DOCKER_IMAGE / _DOCKER_NETWORK / _LOCAL_FILE_ACCESS)
src/
WkhtmltoPdf.php fluent HTML→PDF API (Snappy replacement)
WkhtmltoPdfStatic.php strategy resolution + process execution
WkhtmltoPdfResult.php output/errorOutput/exitCode value object
x64/mac/, x64/linux/ bundled 0.12.6.1 patched-Qt binaries
build/ Dockerfile + multi-arch build script
tests/ PHPUnit suite and the visual check (not in dist installs)