1. Go to this page and download the library: Download viavario/pdfgenerator 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/ */
viavario / pdfgenerator example snippets
viavario\pdfgenerator\PDFGenerator;
// This is invoke URL of the API Gateway or the endpoint returned by the
// serverless deploy command without `capture` at the end
$endpoint = 'https://##########.execute-api.eu-west-3.amazonaws.com/dev/';
$apiKey = '<your-api-key>'; // Your API Key configured in the API Gateway
$filename = 'screenshot.pdf'; // Change to screenshot.png to get a PNG image
$generator = new PDFGenerator($endpoint, $apiKey);
$generator->setURL('https://google.com')
->setFilename($filename)
->setMargins('1.5cm')
->setFormat('A4')
// The screenshot service automatically increases the height of the viewport
// to take a full page screenshot
->setViewportSize(1920, 1080)
->setOrientation(PDFGenerator::ORIENTATION_PORTRAIT);
try {
$tempfile = $generator->generate();
// Change the Content-Type to image/png if you changed the extension of the
// filename to .png
header('Content-Type: application/pdf');
echo $tempfile;
}
catch (\Exception $e) {
echo $e->getMessage();
}
public __construct (string $endpoint, string $apiKey)
public displayHeaderFooter (bool $displayHeaderFooter)
public generate (string $filename)
public omitBackground (bool $omitBackground)
public preferCSSPageSize (bool $preferCSSPageSize)
public printBackground (bool $printBackground)
public setContent (string $content)
public setFilename (string $filename)
public setFooterTemplate (string $html)
public setFormat (void)
public setHeaderTemplate (string $html)
public setHttpAuthentication (void)
public setMargins (string $margins, string $right, string $bottom, string $left)
public setOrientation (string $orientation)
public setURL (string $url)
public setViewportSize (void)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.