The goal of this project is the attemp to provide a helper functionality for creating beautiful, printable and secure documents.
composer require ambersive/documentviewer
php artisan make:printable "Invoice"
Define a route in your desired router. Please be aware that default laravel middleware for web and api might require modifications there (eg for the post request).
$signed = false
Route::document(
"invoices/{id}",
"invoices",
\App\Printables\Invoice::class,
[
// Middleware for getting the document
],
$signed,
\App\Printables\Invoice::class, // for file upload handling
[
// Middleware for postback / upload the document
]
);
The signed attribute will always be in effect for the get request of the document.
If you do not want a upload leave the upload class empty or null.
The command above will create Printable Class in the folder Printable within app_path
First of all you should define data which is present or required in the specific blade file.
Then you should provide an uploadHandler. This will be required if you use our Laravel Package for Print generation and the Print-API.
use Illuminate\Http\Request;
use AMBERSIVE\DocumentViewer\Abstracts\DocumentAbstract;
class Invoice extends DocumentAbstract
{
public array $data = [];
// Define the blade you want to return as printable document
public String $blade = "ambersive.documentviewer::printable_default";
public bool $useValidationEndpoint = false;
public function setData(){
// Request is available in $this->request
// Save stuff in $this->data
// This function must return $this (= chainable)
// Params are provided in $this->params
return $this;
}
public function uploadDocumentHandler(Request $request) {
// Handle the file upload
// Requires a response (preferable json)
return ['status' => 200];
}
public function validateDocumentHandler(Request $request) {
// Handle the validation
// This information is a helper
// Requires a response (preferable json)
return ['status' => 200];
}
}
The make command also creates a blade file within the resource folder. It will come with some basic scaffold settings so you will be able to create beautiful documents in no time.
If you want to create a custom blade file make sure you extend it with our base blade. Otherwise the enhanced view optimizations won't work.
@extends('ambersive.documentviewer::printable')
A full example might look like:
@extends('ambersive.documentviewer::printable')
@section('styles')
<style>
body {
// Custom Page style goes here
}
</style>
@endsection
@section('document')
<div>Printable document</div>
@endsection
We created a microservice which is also open-source to create pdf files. If you need a smooth way to interact with this microservice you can use our package for that.
If you discover a security vulnerability within this package, please send an e-mail to Manuel Pirker-Ihl via manuel.pirker-ihl@ambersive.com. All security vulnerabilities will be promptly addressed.
This package is open-sourced software licensed under the MIT license.