1. Go to this page and download the library: Download netflex/renderer 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/ */
netflex / renderer example snippets
use Netflex\Render\PDF;
$pdf = PDF::from('<h1>Hello, World!</h1>');
use Netflex\Render\PDF;
$pdf = PDF::view('templates.example', ['foo' => 'bar']);
use Netflex\Render\PDF;
use App\Models\Product;
$pdf = PDF::route('products.show', ['product' => Product::first()]);
use Netflex\Render\PDF;
// Internal URL (must be publicly reachable)
$pdf = PDF::url('/test');
// External URL
$pdf = PDF::url('https://www.apility.no');
use Netflex\Render\PDF;
$pdf = PDF::from('<h1>Hello, World!</h1>');
$pdf->devicePixelRatio(2.0);
use Netflex\Render\PDF;
$pdf = PDF::from('<h1>Hello, World!</h1>');
// Only allow the request to load for 5 seconds, then time out.
$pdf->timeout(5000);
use Netflex\Render\PDF;
$pdf = PDF::from('<h1>Hello, World!</h1>');
// Waits until the whole page has loaded, including all dependent resources such as stylesheets and images.
$pdf->waitUntilLoaded();
// Waits until fired the page DOM has been loaded, without waiting for resources to finish loading.
$pdf->waitUntilDOMContentLoaded();
// Waits until there has not been any network requests for at least 500ms
$pdf->waitUntiNetworkIdle()
// Waits until there has not been more than 2 network requests for at least 500ms
$pdf->waitUntiNetworkSettled();
use Netflex\Render\PDF;
// As a Laravel response:
$response = $pdf->toResponse();
// As a file handle
$file = $pdf->stream();
// As a link
$url = $file->link();
// As a string
$str = $file->blob();
use Netflex\Render\PDF;
Route::get('example.pdf', function () {
return PDF::from('<h1>Hello, World!</h1>');
});
namespace App\Http\Controllers;
use App\Models\Product;
use Netflex\Render\PDF;
class ExampleController extends Controller
{
public function show (Product $product)
{
return PDF::view('product', ['product' => $product]);
}
}
use Netflex\Render\PDF;
$pdf = PDF::view('templates.example', ['foo' => 'bar']);
$pdf->printBackground();
use Netflex\Render\PDF;
$pdf = PDF::view('templates.example', ['foo' => 'bar']);
$pdf->marginTop('1cm');
$pdf->marginRight('100mm');
$pdf->marginBottom('128px');
$pdf->marginLeft(200);
// ... or
$pdf->marginTop(1, PDF::UNIT_CM);
$pdf->marginRight(100, PDF::UNIT_MM);
$pdf->marginBottom(128, PDF::UNIT_PX);
$pdf->marginLeft(200); // Let the backend decide the unit
// Or specify them like you would in CSS
$pdf->margin('1cm'); // All margings set to 1cm
$pdf->margin('1cm', '2cm'); // Top and bottom set to 1cm, Left and right to 2cm
use Netflex\Render\PDF;
$pdf = PDF::view('templates.example', ['foo' => 'bar']);
$pdf->scale(1.5); // Scale factor between 0.1 and 2.0
use Netflex\Render\PDF;
$pdf = PDF::view('templates.example', ['foo' => 'bar']);
$pdf->width('100cm');
$pdf->height('200cm');
use Netflex\Render\PDF;
$pdf = PDF::view('templates.example', ['foo' => 'bar']);
$pdf->format(PDF::FORMAT_A3);
$pdf->landscape();
use Netflex\Render\PDF;
$pdf = PDF::view('templates.example', ['foo' => 'bar']);
$pdf->preferCSSPageSize();
use Netflex\Render\PDF;
$pdf = PDF::view('templates.example', ['foo' => 'bar']);
// If you just would like to enable the default header and footer
// Not needed if you specify a custom header or footer.
$pdf->displayHeaderFooter();
$pdf->headerTemplate('blocks.pdf.header', ['hello' => 'world']);
$pdf->footerTemplate('blocks.pdf.header', ['hello' => 'world']);
// Or from raw markup
$pdf->headerTemplateFrom('<div><span class="date"></span></div>');
$pdf->footerTemplateFrom('<div><span class="date"></span></div>');
use Carbon\Carbon;
use Netflex\Render\PDF;
$pdf = PDF::url('https://www.google.com');
$pdf->author('John Doe');
$pdf->title('Hello World!');
$pdf->keywords(['foo', 'bar', 'baz']);
$pdf->description('Lorem ipsum dolor sit amet, consectetur adipiscing elit');
$pdf->creator('Example Company Inc.');
// You can also override the creation and modified dates
$now = Carbon::now();
$pdf->created($now);
$pdf->modified($now);
use Netflex\Render\PNG;
$png = PNG::view('templates.example', ['foo' => 'bar']);
// Viewport size 2560x1440 at 2x devicePixelRatio
$png->width(2560);
$png->height(1440)
$png->devicePixelRatio(2.0);
use Netflex\Render\PNG;
$png = PNG::view('templates.example', ['foo' => 'bar']);
// Extract a 256x256 image starting from x:10, y:10 offsets from the document top
$png = $png->clip(10, 10, 256, 256);
namespace App\Http;
use Netflex\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'ssr' => \Netflex\Render\Http\Middleware\SSR::class,
];
Route::group(['middleware' => 'ssr'], function () {
Route::get('/example', 'ExampleController@show');
});
use Netflex\Render\MJML;
$html = MJML::from('<mjml><mj-body><mj-text>Hello World</mj-text></mj-body</mml>')
->blobl();
namespace App\Mail;
use Illuminate\Mail\Mailable;
use Netflex\Render\Mail\MJML;
class ExampleMail extends Mailable
{
use MJML;
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->mjml('mail.example', ['message' => 'Hello World'])
->subject('Rendered with MJML!');
}
}
use Illuminate\Support\Facades\View;
View::make('example')->renderPDF();
View::make('example')->renderJPG();
View::make('example')->renderPNG();
View::make('example')->renderHTML();
// You can also chain all the other options
View::make('example')->renderPDF()
->printBackground(); // ...etc