PHP code example of trianity / laravel-pdf-viewer

1. Go to this page and download the library: Download trianity/laravel-pdf-viewer 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/ */

    

trianity / laravel-pdf-viewer example snippets


return [
    'route_prefix' => 'pdf-viewer',

    'route_name' => 'pdf-viewer.',

    'middleware' => ['web', 'signed'],

    'signed_url_ttl' => 10,

    'gate' => null,

    'authorize' => null,
];

use Trianity\LaravelPdfViewer\Contracts\PdfDocumentResolver;
use Trianity\LaravelPdfViewer\Data\PdfDocument;

$this->app->bind(PdfDocumentResolver::class, function () {
    return new class implements PdfDocumentResolver {
        public function resolve(string $documentId): ?PdfDocument
        {
            // Look up the document in your own database.
            return new PdfDocument(
                disk: 'private',
                path: 'documents/example.pdf',
                filename: 'example.pdf',
                mime: 'application/pdf',
            );
        }
    };
});

'gate' => 'viewPdfDocument',

'authorize' => fn ($request, string $documentId, $document) => $request->user()?->can('viewPdfDocument', $document),
bash
php artisan vendor:publish --tag=pdf-viewer-config
bash
php artisan vendor:publish --tag=pdf-viewer-assets
txt
config/pdf-viewer.php
css
@source "../../vendor/trianity/laravel-pdf-viewer/resources/views/**/*.blade.php";
@source "../../vendor/trianity/laravel-pdf-viewer/src/**/*.php";