PHP code example of oasys / chrome-pdf

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

    

oasys / chrome-pdf example snippets


 declare(strict_types=1);

use Oasys\Pdf\ChromePdf;

$pdf = new ChromePdf();

$pdf->save(
    html: '<h1>Hello world</h1>',
    output: __DIR__ . '/document.pdf'
);

$pdf = new ChromePdf();

$pdf = new ChromePdf(
    binary: 'chromium'
);

$pdf = new ChromePdf(
    binary: 'C:\Program Files\Google\Chrome\Application\chrome.exe'
);

$pdf = new ChromePdf(
    flags: [
        'disable-gpu'   => true,
        'user-data-dir' => '/tmp/chrome'
    ]
);

[
    'no-sandbox' => true
]

[
    'no-sandbox',
    'disable-gpu'
]

[
    'user-data-dir' => '/tmp/chrome'
]

[
    'window-size' => [1280, 720]
]

[
    'no-sandbox'  => false,
    'disable-gpu' => null
]

$pdf->save(
    '<h1>Invoice</h1>',
    __DIR__ . '/invoice.pdf'
);

$base64 = $pdf->base64(
    '<h1>Invoice</h1>'
);

"JVBERi0xLj...CiUlRU9GCg=="

$path = $pdf->tempPath(
    '<h1>Invoice</h1>'
);

"/tmp/pdf-abc123.pdf"

@unlink($path);