PHP code example of fruitcake / laravel-weasyprint
1. Go to this page and download the library: Download fruitcake/laravel-weasyprint 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/ */
fruitcake / laravel-weasyprint example snippets
namespace App\Http\Controllers;
use Pontedilana\PhpWeasyPrint\Pdf;
class PdfController extends Controller
{
public function __invoke(Pdf $weasyPrint)
{
//To file
$html = '<h1>Bill</h1><p>You owe me money, dude.</p>';
$weasyPrint->generateFromHtml($html, '/tmp/bill-123.pdf');
$weasyPrint->generate('https://laravel.com/docs/10.x', '/tmp/laravel-docs.pdf');
//Or output:
return response(
$weasyPrint->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
}
namespace Tests\Feature;
use Tests\TestCase;
use PDF;
class ExampleTest extends TestCase
{
public function testPrintOrderShipping()
{
PDF::fake();
// Perform order shipping...
PDF::assertViewIs('view-pdf-order-shipping');
PDF::assertSee('Name');
}
}