PHP code example of squareetlabs / laravel-pdf-to-html
1. Go to this page and download the library: Download squareetlabs/laravel-pdf-to-html 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/ */
squareetlabs / laravel-pdf-to-html example snippets
use PdfToHtml;
try {
// Load a PDF file using the facade
$pdf = PdfToHtml::load('/path/to/document.pdf');
// Get HTML content
$html = $pdf->getHtml();
// Get all pages content as an array
$pages = $html->getAllPages();
// Get specific page
$page1 = $html->getPage(1);
echo $page1;
} catch (\Exception $e) {
echo "Error: " . $e->getMessage();
}
use Squareetlabs\LaravelPdfToHtml\Support\Pdf;
try {
// Create a new instance
$pdf = new Pdf('/path/to/document.pdf');
// Get HTML content
$html = $pdf->getHtml();
// Get all pages content as an array
$pages = $html->getAllPages();
// Get specific page
$page1 = $html->getPage(1);
echo $page1;
} catch (\Exception $e) {
echo "Error: " . $e->getMessage();
}
$options = [
'pdftohtml_path' => '/usr/custom/bin/pdftohtml', // Optional custom path
'pdfinfo_path' => '/usr/custom/bin/pdfinfo', // Optional custom path
'generate' => [
'singlePage' => false, // Split pages (default)
'imageJpeg' => true, // Convert images to JPEG
'ignoreImages' => false, // Keep images
'zoom' => 1.5, // Zoom factor
'noFrames' => true, // Output without frames
],
'html' => [
'inlineCss' => true, // Inline CSS into style attributes
'inlineImages' => true, // Convert images to Base64
'onlyContent' => true, // Return only body content
],
'clearAfter' => true, // Clear temp files after processing
];
// Using Facade
$pdf = PdfToHtml::load('/path/to/document.pdf', $options);
// Or using direct instantiation
$pdf = new Pdf('/path/to/document.pdf', $options);