1. Go to this page and download the library: Download drewlabs/php-dompdf 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/ */
drewlabs / php-dompdf example snippets
use function Drewlabs\Dompdf\Proxy\DomPdf;
const pdf = DomPdf([/* DOMPdf otpions */]);
use Drewlabs\Dompdf\Factory;
$factory = new Factory;
const pdf = $factory->create([/* DOMPdf otpions */]);
use function Drewlabs\Dompdf\Proxy\DomPdf;
use Nyholm\Psr7\Factory\Psr17Factory;
const pdf = DomPdf([/* DOMPdf otpions */]);
// Reading DOM string from \SplFileInfo
$document = new \SplFileInfo;
$pdf = $pdf->read($document);
// Reading from Psr7 compatible stream
$document = (new Psr17Factory)->createStreamFromFile($pathOrStream);
$pdf = $pdf->read($document);
// Reading from disk path
$pdf = $pdf->read('/home/users/dev/documents/document.pdf');
// Read from raw string
$pdf = $pdf->read("
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\" />
<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />
<title>Document</title>
</head>
<body></body>
</html>"
);
// Read from URI resource
$pdf = $pdf->read("https://www.google.com");
use function Drewlabs\Dompdf\Proxy\DomPdf;
$pdf = DomPdf([/* DOMPdf otpions */]);
$pdf->html(" ... html string");
// To load content from URI resource
$pdf = $pdf->resource('file:///home/users/dev/documents/document.pdf');
$pdf = DomPdf([/* DOMPdf otpions */]);
$pdf->print(); // Returns a raw string
$pdf = DomPdf([/* DOMPdf otpions */]);
// It's a late content read, meaning it does not send content to request client unless
// user code manually call send() on the response object
$response = $pdf->download(); // Symfony HTTP response
// To send the response to request client, developper must call $response->send() method
$response->prepare(new Request::createFromGlobals())->send();
$pdf = DomPdf([/* DOMPdf otpions */]);
$pdf->stream(); // Internally uses PHP echo method to write to the output buffer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.