PHP code example of igeek / pdfservice

1. Go to this page and download the library: Download igeek/pdfservice 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/ */

    

igeek / pdfservice example snippets


return [
    'url' => env('PDFSERVICE_URL'),
    'key' => env('PDFSERVICE_API_KEY'),
];

use Igeek\PdfService\Facades\Pdf;

// Generate and save a PDF
Pdf::view('pdf.invoice', ['invoice' => $invoice])
    ->save('invoices/invoice-001.pdf');

// Generate and download
return Pdf::view('pdf.invoice', ['invoice' => $invoice])->download('invoice.pdf');

// Display inline in browser
return Pdf::view('pdf.invoice', ['invoice' => $invoice])->inline('invoice.pdf');

Pdf::html('<h1>Hello World</h1><p>This is a PDF.</p>')
    ->save('hello.pdf');

Pdf::view('pdf.content', $data)
    ->headerView('pdf.header', ['title' => 'My Report'])
    ->footerView('pdf.footer')
    ->save('report.pdf');

// Or with raw HTML
Pdf::view('pdf.content', $data)
    ->headerHtml('<div style="text-align: center;">Header</div>')
    ->footerHtml('<div style="text-align: center;">Page @pageNumber of @totalPages</div>')
    ->save('report.pdf');

use Igeek\PdfService\Enums\Format;

// Using enum
Pdf::view('pdf.content', $data)
    ->format(Format::Letter)
    ->save('letter.pdf');

// Using string
Pdf::view('pdf.content', $data)
    ->format('legal')
    ->save('legal.pdf');

Pdf::view('pdf.content', $data)
    ->size([8.5, 14])  // Custom size in inches
    ->save('custom.pdf');

Pdf::view('pdf.content', $data)
    ->landscape()
    ->save('landscape.pdf');

Pdf::view('pdf.content', $data)
    ->portrait()  // Default
    ->save('portrait.pdf');

Pdf::view('pdf.content', $data)
    ->margins(1, 0.5, 1, 0.5)
    ->save('with-margins.pdf');

Pdf::view('pdf.content', $data)
    ->waitDelay('1s')  // Default: 500ms
    ->save('delayed.pdf');

Pdf::view('pdf.content', $data)
    ->disk('s3')
    ->save('reports/monthly.pdf');

$success = Pdf::view('pdf.content', $data)->save('path/to/file.pdf');

return Pdf::view('pdf.content', $data)->download('filename.pdf');

return Pdf::view('pdf.content', $data)->inline('filename.pdf');

$pdfContent = Pdf::view('pdf.content', $data)->content();

use Igeek\PdfService\Facades\Pdf;

Pdf::using('https://other-gotenberg.example.com', 'other-api-key')
    ->view('pdf.content', $data)
    ->save('document.pdf');

Pdf::view('pdf.invoice', $data)
    ->headerView('pdf.header')
    ->footerView('pdf.footer')
    ->format(Format::A4)
    ->landscape()
    ->margins(1, 0.75, 1, 0.75)
    ->waitDelay('500ms')
    ->disk('local')
    ->name('invoice.pdf')
    ->save('invoices/2024/invoice-001.pdf');
bash
php artisan vendor:publish --tag="pdfservice-config"