
How to take screenshots and generate PDFs in PHP (without wkhtmltopdf)
How to Take Screenshots and Generate PDFs in PHP (Without wkhtmltopdf) PHP PDF generation has always been painful. wkhtmltopdf requires a binary installation and struggles with modern CSS and JavaScript. Dompdf is pure PHP but can't render JavaScript-heavy pages. mPDF is similar. Browsershot (Spatie) wraps Puppeteer, which means Node.js on your server. Here's the clean path: one HTTP request, binary response, no system dependencies. Screenshot from a URL <?php function screenshot ( string $url ): string { $ch = curl_init ( 'https://pagebolt.dev/api/v1/screenshot' ); curl_setopt_array ( $ch , [ CURLOPT_POST => true , CURLOPT_RETURNTRANSFER => true , CURLOPT_HTTPHEADER => [ 'x-api-key: ' . $_ENV [ 'PAGEBOLT_API_KEY' ], 'Content-Type: application/json' , ], CURLOPT_POSTFIELDS => json_encode ([ 'url' => $url , 'fullPage' => true , 'blockBanners' => true , ]), ]); $result = curl_exec ( $ch ); curl_close ( $ch ); return $result ; } // Save to disk file_put_contents ( 'screenshot.png' , scree
Continue reading on Dev.to Webdev
Opens in a new tab



