PHP code example of hkwise / laravel-weasyprint

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

    

hkwise / laravel-weasyprint example snippets


composer 

php artisan vendor:publish --provider="HKWise\WeasyPrint\WeasyPrintServiceProvider"

sudo apt install weasyprint

sudo dnf install weasyprint

sudo pacman -S python-weasyprint

pip install weasyprint

brew install weasyprint

python3 -m venv venv
venv\Scripts\activate.bat
python3 -m pip install weasyprint
python3 -m weasyprint --info

use HKWise\WeasyPrint\Facades\WeasyPdf;

$data = ['name' => 'John Doe'];
return WeasyPdf::loadView('pdf.invoice', $data)->download('invoice.pdf');

use HKWise\WeasyPrint\Facades\WeasyPdf;

WeasyPdf::loadHTML('<h1>Hello, World!</h1>')->save(storage_path('app/example.pdf'));

use HKWise\WeasyPrint\Facades\WeasyPdf;

return WeasyPdf::generate('https://weasyprint.org')->inline();

use HKWise\WeasyPrint\Facades\WeasyPdf;

return WeasyPdf::loadFile(public_path('myfile.html'))->download('myfile.pdf');

use HKWise\WeasyPrint\Facades\WeasyPdf;

return WeasyPdf::loadHtml('<h1>Hello, WeasyPrint!</h1>')
    ->save(storage_path('app/pdfs/myfile.pdf'))
    ->download('myfile.pdf');

use HKWise\WeasyPrint\Facades\WeasyPdf;

return WeasyPdf::loadHTML('<h1>Test</h1>')
    ->setOptions([
        'custom-metadata' => 'metadata.json',
        'attachment' => ['note.txt', 'photo.jpg'],
    ])
    ->download('document.pdf');

'aliases' => [
    // Other aliases
    'WPdf' => HKWise\WeasyPrint\Facades\WeasyPdf::class,
],

use WPdf;

return WPdf::loadHTML('<h1>Hello, World!</h1>')->inline();

'aliases' => [
    // Other aliases
    'WeasyPdf' => HKWise\WeasyPrint\Facades\WeasyPdf::class,
    'WPdf' => HKWise\WeasyPrint\Facades\WeasyPdf::class,
],

use WeasyPdf;
use WPdf;

// Both will work
return WeasyPdf::loadHTML('<h1>Hello, World!</h1>')->inline();
return WPdf::loadHTML('<h1>Hello, World!</h1>')->inline();

pip install weasyprint

sudo apt install weasyprint

'enabled' => app()->environment(['production', 'prod']),

APP_ENV=local

APP_ENV=production