Skip to content
Library to help you build perfect print ready document
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Generate Print Ready Document

Latest Version on Packagist Software License


You can install this package via composer using this command:

composer require abcreche/print

The package will automatically register itself


This package uses "Print Document Template" classes to generate PDF that you can then print via the browser. These classes are filled with data that you position as you like. This is particularly helpful to fill in official document that rely on specific templates.

Make Print Templates

First, make a new print document:

php artisan make:print ReceiptTemplate

The file can be foudn in app/PrintTemplates:

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

In your controller you can generate the PDF for this print template now:


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');

Configure Print Templates

This is how your Print Template look by default:


namespace App\PrintTemplates;

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

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

Write data

Let's write some data on the document:

public function build()


    return $this;

You can also chain methods

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


You can choose the orientation of the document by setting the orientation property.

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

Page Margins

You can set the page margins.

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


You can preview any PrintTemplate by simply returning it from the controller

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

    return new App\PrintTemplates\ReceiptTemplate($receipt);

Then you can use chrome dev tools to render the print version of the page

Image from this stackoverflow post

Then switch the dev tools to device rendering and set the dimension of the page at

  • A4 : 595 x 842

Working with a preview like this will help you build your templates. When converting them to pdf, they will be exactly like the preview.



You can’t perform that action at this time.