PHP code example of blutrixx / nativephp-pdf-renderer

1. Go to this page and download the library: Download blutrixx/nativephp-pdf-renderer 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/ */

    

blutrixx / nativephp-pdf-renderer example snippets


use Blutrixx\PdfRenderer\Facades\PdfRenderer;

$pageCount = PdfRenderer::getPageCount($path);

use Blutrixx\PdfRenderer\Facades\PdfRenderer;

$count = PdfRenderer::getPageCount('/storage/documents/invoice.pdf');

$dims = PdfRenderer::getPageDimensions('/storage/documents/invoice.pdf', page: 0);

$page = PdfRenderer::renderPage(
    path: '/storage/documents/invoice.pdf',
    page: 0,
    width: 1000,
);
// $page['path'] (or your own $outputPath) now points at a rendered PNG/JPEG on-device

PdfRenderer::renderThumbnail(
    path: '/storage/documents/invoice.pdf',
    outputPath: '/storage/thumbnails/invoice.png',
    width: 320,
);

// routes/api.php
Route::get('/documents/{document}/pages/{page}', function (Document $document, int $page) {
    return \Blutrixx\PdfRenderer\Facades\PdfRenderer::renderPage($document->local_path, $page, width: 1200);
});

Route::get('/documents/{document}/page-count', function (Document $document) {
    return ['pageCount' => \Blutrixx\PdfRenderer\Facades\PdfRenderer::getPageCount($document->local_path)];
});