PHP code example of abcreche / print

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

    

abcreche / print example snippets




namespace App\Http\Controllers;

use App\Receipt;
use ABCreche\Printer\Facades\Printer;
use App\PrintTemplates\ReceiptTemplate;

class ReceiptController extends Controller
{
    public function print(Receipt $receipt)
    {
        return Printer::download(new ReceiptTemplate($receipt), 'receipt.pdf');
    }
}



namespace App\PrintTemplates;

use App\Receipt;
use ABCreche\Printer\Printer;

class ReceiptTemplate implements PrintTemplate
{
    public function build()
    {
        $this->firstPage()->write('Hello There');
    }
}

public function build()
{
    $this->addPage();
}

public function build()
{
    $this->lastPage()->write('I will appear on the first page');
    $this->addPage();
    $this->lastPage()->write('I will appear on the second page');
}

public function build()
{
    $this->lastPage()
        ->write($receipt->number)
        ->top('10px')
        ->left('100px');

    $this->lastPage()
        ->write($receipt->total)
        ->bottom('35px')
        ->right('50%');

    return $this;
}

public function build()
{
    // Orders of direction is the same as in CSS for padding / margin properties
    return $this->lastPage()
        ->write($receipt->number, '10px', null, null, '100px')
        ->write($receipt->total, null, '35px', '50%', null);
}

// Default: portrait
// Options: 'portrait', 'landscape'
protected $orientation = 'portrait';

// Default: 25mm
protected $pageMargin = '25mm';

Route::get('printer', function () {
    $receipt = App\Receipt::find(1);

    return new App\PrintTemplates\ReceiptTemplate($receipt);
});
bash
php artisan make:print ReceiptTemplate

.
├── app
│   ├── PrintTemplates
│   │   ├── ReceiptTemplate.php
│
└── composer.json