PHP code example of fyrts / chrome-devtools-pdf
1. Go to this page and download the library: Download fyrts/chrome-devtools-pdf 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/ */
fyrts / chrome-devtools-pdf example snippets
$instance = ChromeDevToolsPdf\Instance::connect(9222);
$instance = ChromeDevToolsPdf\Instance::launch('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome');
$instance = ChromeDevToolsPdf\Instance::launch();
$pdf = $instance->loadUrl('https://www.google.com');
$pdf->saveFile(__DIR__ . '/filename.pdf');
$instance->close();
$instance = ChromeDevToolsPdf\Instance::launch();
$pdf = $instance->loadHtml('<h1>Example</h1>');
$pdf->saveFile(__DIR__ . '/filename.pdf');
$instance->close();
$instance = ChromeDevToolsPdf\Instance::launch();
$pdf = $instance->loadUrl('https://www.google.com');
Storage::put($__DIR__ . '/filename.pdf', $pdf->generate());
$instance->close();
$instance = ChromeDevToolsPdf\Instance::launch();
$pdf = $instance->loadUrl('https://www.google.com');
$pdf->setLandscape(true)->setMarginLeft(3);
$pdf->setDisplayHeaderFooter(true)->setHeaderTemplate('Title: <span class="title"></span>');
$pdf->saveFile(__DIR__ . '/filename.pdf');
$instance->close();
$instance = ChromeDevToolsPdf\Instance::launch();
$pdf1 = $instance->loadUrl('https://www.google.com');
$pdf1->saveFileAsync(__DIR__ . '/filename-1.pdf');
$pdf2 = $instance->loadUrl('https://www.github.com');
$pdf2->saveFileAsync(__DIR__ . '/filename-2.pdf');
$pdf1->await();
$pdf2->await();
$instance->close();