PHP code example of gocanto / laravel-simple-pdf

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

    

gocanto / laravel-simple-pdf example snippets


use Gocanto\SimplePDF\Builder;
use Gocanto\SimplePDF\TemplateContext;

Route::get('default-template', function (Builder $builder) {

    $context = TemplateContext::make([
        'title' => 'foo',
        'name' => 'bar',
        'content' => '<h1>Some amazing content!</h1>',
    ]);

    $builder->make($context);

    return $builder->render();
});


use Gocanto\SimplePDF\Builder;
use Gocanto\SimplePDF\TemplateContext;

Route::get('custom-template', function (Builder $builder) {

    $context = TemplateContext::make([
        'title' => 'foo',
        'name' => 'bar',
        'content' => '<h1>Some amazing content!</h1>',
    ]);

    $builder->addLocation(resource_path('views/home'));
    $new = $builder->withTemplate('home');
    $new->make($context);

    return $new->render();
});

use Psr\Http\Message\StreamInterface;

$new->render(function (StreamInterface $stream) {
    //do something amazing with the stream
    echo $stream->getContents();
});