Dompdf - Simple Dompdf package for Laravel

Related tags

PDF pdf-l4
Overview

Dompdf

Simple Dompdf package for Laravel 4 This package uses the latest stable version (0.5)

Build Status

Installation

Run

composer require thujohn/pdf

OR

Add thujohn/pdf to composer.json.

"thujohn/pdf": "dev-master"

Run composer update to pull down the latest version of Pdf.

Now open up app/config/app.php and add the service provider to your providers array.

'providers' => array(
	'Thujohn\Pdf\PdfServiceProvider',
)

Now add the alias.

'aliases' => array(
	'PDF' => 'Thujohn\Pdf\PdfFacade',
)

Publish the config

php artisan config:publish thujohn/pdf

Usage

Show a PDF

Route::get('/', function()
{
	$html = ''
			. '

Put your html here, or generate it with your favourite ' . 'templating system.

'
. ''; return PDF::load($html, 'A4', 'portrait')->show(); });

Download a PDF

Route::get('/', function()
{
	$html = ''
			. '

Put your html here, or generate it with your favourite ' . 'templating system.

'
. ''; return PDF::load($html, 'A4', 'portrait')->download('my_pdf'); });

Returns a PDF as a string

Route::get('/', function()
{
	$html = ''
			. '

Put your html here, or generate it with your favourite ' . 'templating system.

'
. ''; $pdf = PDF::load($html, 'A4', 'portrait')->output(); });

Multiple PDFs

for ($i=1;$i<=2;$i++)
{
	$pdf = new \Thujohn\Pdf\Pdf();
	$content = $pdf->load(View::make('pdf.image'))->output();
	File::put(public_path('test'.$i.'.pdf'), $content);
}
PDF::clear();

Examples

Save the PDF to a file in a specific folder, and then mail it as attachement. By @w0rldart

define('BUDGETS_DIR', public_path('uploads/budgets')); // I define this in a constants.php file

if (!is_dir(BUDGETS_DIR)){
	mkdir(BUDGETS_DIR, 0755, true);
}

$outputName = str_random(10); // str_random is a [Laravel helper](http://laravel.com/docs/helpers#strings)
$pdfPath = BUDGETS_DIR.'/'.$outputName.'.pdf';
File::put($pdfPath, PDF::load($view, 'A4', 'portrait')->output());

Mail::send('emails.pdf', $data, function($message) use ($pdfPath){
	$message->from('[email protected]', 'Laravel');
	$message->to('[email protected]');
	$message->attach($pdfPath);
});
Comments
  • How to change settings? Changing default encoding?

    How to change settings? Changing default encoding?

    I need to use scandinavian alphabets (UTF-8)... I'm actually using the view object, only with "print" asset set (with Basset) and that charset should be declared in the HTML already. So the change must be done with the renderer. I'm using the download method.

    Is there a way to publish settings to app/config via artisan?

    opened by ux-engineer 15
  • Unable to stream pdf: headers already sent

    Unable to stream pdf: headers already sent

    Hi.

    I download a pdf file from my dev server, everything goes fine, but, when i try to run in production, when i create the PDF file, i got an error:

    Unable to stream pdf: headers already sent

    And there's no more message. What can i do?

    thanks.

    opened by jpilldev 13
  • Call to a member function prepend_child() on a non-object

    Call to a member function prepend_child() on a non-object

    $view = View::make('account.order', array(
        'order' => Order::find($id)
    ));
    
    return PDF::load($view, 'A4', 'portrait')->download('my_pdf');
    
    [2014-07-29 22:25:08] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function prepend_child() on a non-object' in .../vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/frame_tree.cls.php:218
    Stack trace:
    #0 [internal function]: Illuminate\Exception\Handler->handleShutdown()
    #1 {main} [] []
    
    opened by dale-conroy 12
  • spits out unformatted code characters

    spits out unformatted code characters

    i tried simple example, it worked in local XAMP, but not working in production server (WHM cPanel)

    Route::get('tst',function () {
        $html = '<html><body>'
                . '<p>Put your html here, or generate it with your favourite '
                . 'templating system.</p>'
                . '</body></html>';
    
        return PDF::load($html, 'A4', 'portrait')->show();
    });
    
    

    it outputs

    %PDF-1.3 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R >> >> /MediaBox [0.000 0.000 595.280 841.890] >> endobj 4 0 obj [/PDF /Text ] endobj 5 0 obj << /Creator (DOMPDF) /CreationDate (D:20130711132815+05'30') /ModDate (D:20130711132815+05'30') >> endobj 6 0 obj << /Type /Page /Parent 3 0 R /Contents 7 0 R >> endobj 7 0 obj << /Length 139 >> stream 0.000 0.000 0.000 rg BT 34.016 784.469 Td /F1 12.0 Tf [(Put your html here, or generate it with your favourite templating system.)] TJ ET endstream endobj 8 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Times-Roman /Encoding /WinAnsiEncoding >> endobj xref 0 9 0000000000 65535 f 0000000008 00000 n 0000000073 00000 n 0000000119 00000 n 0000000273 00000 n 0000000302 00000 n 0000000416 00000 n 0000000479 00000 n 0000000669 00000 n trailer << /Size 9 /Root 1 0 R /Info 5 0 R >> startxref 778 %%EOF
    
    opened by hardevine 10
  • Multiple PDFs

    Multiple PDFs

    The library is working fine when generating a single PDF, however when generating two in succession I always get the "no block-level parent found" error, on the second generation, the first PDF is generated fine without incident. I've tried using the library in different ways (creating a class and using one object for each PDF, not even using the laravel autoloader etc) and have used PDF::clear(), but nothing seems to work.

    opened by itsjustk 8
  • Constant DOMPDF_TEMP_DIR already defined

    Constant DOMPDF_TEMP_DIR already defined

    I get the error: Constant DOMPDF_TEMP_DIR already defined. I solved it partly.

    //Just some sample code on how I use it

    $invoices = Invoices::All() foreach ($invoices as $invoice) { // The error occured here when the second invoice is handled $dompdf = new \Thujohn\Pdf\Pdf(); $dompdf->load($invoice->asHtml); $pdf = $dompdf->output();

    // First one succesfull
    

    }

    Inside the Pdf.php file I've added the !defined.

    if (!defined($conf)) {
      define($conf, Config::get('pdf::'.$conf));
    }
    

    After this I get this error.

    [ErrorException] unlink(C:\Users\HVSsoftware\AppData\Local\Temp\ca_742.tmp): No such file or directory

    Now I have solved it by generating one invoice at the time. Any other suggestions?

    opened by HVSoftware 8
  • How to set configuration?

    How to set configuration?

    I've been looking for way to set def("DOMPDF_ENABLE_REMOTE", true); in my Laravel config

    I've seen in the Pdf class

        $_conf = array('DOMPDF_TEMP_DIR', 'DOMPDF_UNICODE_ENABLED', ...);
    
        foreach ($_conf as $conf){
            if ((Config::has('pdf::'.$conf) || Config::get('pdf::'.$conf)) && !defined($conf))
                define($conf, Config::get('pdf::'.$conf));
        }
    

    I've never seen the the "pdf::" notation. Every example I can find is "app.something.somethingelse". How you use "pdf::something"? Should I create a pdf.php in config folder?

    Could you please provide an example in your README to set this up?

    Thank you for this great lib :)

    opened by Maximebpro 4
  • PDF Output Gibberish

    PDF Output Gibberish

    Note that this is working on my local environment. But when I've uploaded my site this is what shows up instead of the PDF:

    Can someone shed somelight what is happening? No logs detected though.

    opened by neutt22 3
  • Page header/footer

    Page header/footer

    Hi, I have seen that dompdf creates automatically new pages as text flows, and this is great; I was wondering if there's any way to implement some page header/footer feature, or the page numbering. There are some css rules for that I think.

    opened by esterisk 3
  • View::__toString() must not throw an exception

    View::__toString() must not throw an exception

    I've had PDF working on 2 other Servers (one Local Xampp and one Live) for 3 or 4 months with no worries. I have just moved my app to a new Server and am getting this error: 'Method Illuminate\View\View::__toString() must not throw an exception' in /home/***/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/dompdf.cls.php:0 Im just wondering if there is a PHP module or maybe a Permission problem? (Ive already set my /storage and subdirectories to 777.

    opened by Bulmer 3
  • Call to undefined method DOMText::getAttribute

    Call to undefined method DOMText::getAttribute

    In my controller I'm using:

    public function savePDF($user, $order, $cust)
        {
            $html = View::make('pdfs.invoicePdf', compact('order', 'user', 'cust'))->render();
            $name = str_random(10) . '-invoice.pdf';
            File::put(public_path('pdfs/' . $name), PDF::load($html, 'A4', 'portrait')->output());
        }
    

    When it's run, I'm getting a whoops screen with the following error: image

    The view does contain a bunch of tables as it is an invoice. Could the empty <td>s give it trouble?

    <tr>
        <td class="no-line"></td>
        <td class="no-line"></td>
        <td class="no-line text-center">Total</td>
        <td class="no-line text-right">${{ number_format($order->total_charged, 2) }}</td>
    </tr>
    

    Have you seen this particular error before?

    opened by heidilux 3
  • Problem with <head></head>

    Problem with

    When I generate the pdf from View which contains with and tags the process crashes because the load of the view fails. I attach here the error:

    Exception: exception 'ErrorException' with message 'Trying to get property of non-object' in /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/style.cls.php:482 Stack trace: #0 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/style.cls.php(482): Illuminate\Exception\Handler->handleError(8, 'Trying to get p...', '/var/www/app.ci...', 482, Array) #1 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/style.cls.php(2043): Style->length_in_pt('.75rem', 'auto') #2 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/style.cls.php(2082): Style->set_transform('translatex(.75r...') #3 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/style.cls.php(682): Style->set__webkit_transform('translatex(.75r...') #4 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/stylesheet.cls.php(1299): Style->__set('-webkit-transfo...', 'translateX(.75r...') #5 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/stylesheet.cls.php(1327): Stylesheet->_parse_properties('background-colo...') #6 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/stylesheet.cls.php(1077): Stylesheet->_parse_sections('.custom-switch ...') #7 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/stylesheet.cls.php(307): Stylesheet->_parse_css('/*!\n * Bootstra...') #8 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/dompdf.cls.php(570): Stylesheet->load_css_file('https://stackpa...', 3) #9 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/dompdf.cls.php(696): DOMPDF->_process_html() #10 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/Pdf.php(46): DOMPDF->render() #11 /var/www/app.civitfun.com/website/vendor/thujohn/pdf/src/Thujohn/Pdf/Pdf.php(65): Thujohn\Pdf\Pdf->render() #12 /var/www/app.civitfun.com/website/app/models/Checkin.php(409): Thujohn\Pdf\Pdf->output() #13 /var/www/app.civitfun.com/website/app/controllers/AppV3/AppWsV3CheckinController.php(2435): Checkin->generatePdfs('es') #14 /var/www/app.civitfun.com/website/app/controllers/AppV3/AppWsV3CheckinController.php(4735): AppWsV3CheckinController->checkinConfirm() #15 [internal function]: AppWsV3CheckinController->confirm() #16 /var/www/app.civitfun.com/website/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array) #17 /var/www/app.civitfun.com/website/app/controllers/AppV3/AppWsV3CheckinController.php(215): Illuminate\Routing\Controller->callAction('confirm', Array) #18 /var/www/app.civitfun.com/website/bootstrap/compiled.php(3819): AppWsV3CheckinController->callAction('confirm', Array) #19 /var/www/app.civitfun.com/website/bootstrap/compiled.php(3807): Illuminate\Routing\ControllerDispatcher->call(Object(AppWsV3CheckinController), Object(Illuminate\Routing\Route), 'confirm') #20 /var/www/app.civitfun.com/website/bootstrap/compiled.php(3012): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'AppWsV3CheckinC...', 'confirm') #21 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}() #22 /var/www/app.civitfun.com/website/bootstrap/compiled.php(3370): call_user_func_array(Object(Closure), Array) #23 /var/www/app.civitfun.com/website/bootstrap/compiled.php(3037): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request)) #24 /var/www/app.civitfun.com/website/bootstrap/compiled.php(3025): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) #25 /var/www/app.civitfun.com/website/bootstrap/compiled.php(702): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) #26 /var/www/app.civitfun.com/website/bootstrap/compiled.php(678): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request)) #27 /var/www/app.civitfun.com/website/bootstrap/compiled.php(5797): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true) #28 /var/www/app.civitfun.com/website/bootstrap/compiled.php(6404): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true) #29 /var/www/app.civitfun.com/website/bootstrap/compiled.php(6351): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true) #30 /var/www/app.civitfun.com/website/bootstrap/compiled.php(8367): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true) #31 /var/www/app.civitfun.com/website/bootstrap/compiled.php(639): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request)) #32 /var/www/app.civitfun.com/website/public/index.php(49): Illuminate\Foundation\Application->run() #33 {main}

    opened by Safi87 1
  • Frame not found in cellmap

    Frame not found in cellmap

    hello, some time created pdf . but some time large html and with tables in html that time that type of error show . C:\xampp\htdocs\ticketing\vendor\dompdf\dompdf\include\cellmap.cls.php line 244: Frame not found in cellmap.. please solve this issue. and i am using " return PDF::load($html1)->show(); " this function..

    opened by harshad-parex 0
  • Software license?

    Software license?

    There seems to be no indication of the software license of this project. As stated here (http://choosealicense.com/no-license/), it is better to have a license so there are no misconceptions about it. Would it be possible to add a license?

    opened by wimdeblauwe 0
  • stylesheet.cls.php err

    stylesheet.cls.php err

    Hey. I got this err : Argument 1 passed to Illuminate\Database\Eloquent\Model::__construct() must be of the type array, object given, called in /home/atef/public_html/seomara/vendor/thujohn/pdf/src/Thujohn/Pdf/dompdf/include/stylesheet.cls.php on line 1236 and defined. my test code is : $html = '<html><body>' . '<p>Put your html here, or generate it with your favourite ' . 'templating system.</p>' . '</body></html>'; $pdf = PDF::load($html, 'A4', 'portrait') ->download('my_pdf');. any ideas? thx!

    opened by atefBB 0
Owner
Jonathan Thuau
Jonathan Thuau
DOMPDF module for Laravel 5

pdf-laravel5 DOMPDF module for Laravel 5. Export your views as PDFs - with css support. Instalation Add: "vsmoraes/laravel-pdf": "^2.0" To your compo

Vinicius Moraes 88 Jul 25, 2022
Rapidly Generate Simple Pdf, CSV, & Excel Report Package on Laravel

Laravel Report Generators (PDF, CSV & Excel) Rapidly Generate Simple Pdf Report on Laravel (Using barryvdh/laravel-dompdf or barryvdh/laravel-snappy)

Jimmy Setiawan 513 Dec 31, 2022
Simple wrapper package around MPDF's setProtection method that allows you to set password on PDF files

Laravel PDF Protect (fork) Simple wrapper package around MPDF's setProtection method that allows you to set password on PDF files. Installation You ca

Raphael Planer 2 Jan 23, 2022
A Laravel package for creating PDF files using LaTeX

LaraTeX A laravel package to generate PDFs using LaTeX · Report Bug · Request Feature For better visualization you can find a small Demo and the HTML

Ismael Wismann 67 Dec 28, 2022
Laravel package to convert HTML to PDF, supporting multiple drivers.

eve/pdf-converter A Laravel package to help convert HTML to PDF. Supports multiple drivers. Requirements and Installation eve/pdf-converter requires L

eve.io 11 Feb 15, 2022
This package will generate PDFs and PNGs from websites.

This package will generate PDFs and PNGs from websites.

Appoly 0 Dec 3, 2021
Generate simple PDF invoices with PHP

InvoiScript Generate simple PDF invoices with PHP. Installation Run: composer require mzur/invoiscript Usage Example use Mzur\InvoiScript\Invoice; re

Martin Zurowietz 16 Aug 24, 2022
This is library with the objective of exporting information from the database in a simple way.

Symfony Entity Exporter Goldbach Algorithms Symfony Entity Exporter (fondly nicknamed Entity Exporter) is a library developed for the Symfony framewor

Goldbach Algorithms 1 Oct 30, 2021
Laravel Snappy PDF

Snappy PDF/Image Wrapper for Laravel 5 and Lumen 5.1 This package is a ServiceProvider for Snappy: https://github.com/KnpLabs/snappy. Wkhtmltopdf Inst

Barry vd. Heuvel 2.3k Jan 2, 2023
Adobe XDでデザインしてSVGでエクスポートしたテンプレートをもとに、A4サイズの帳票をHTMLで出力する機能のPHP(Laravel)による実装例です

svg-paper-example Adobe XDでデザインしてSVGでエクスポートしたテンプレートをもとに、A4サイズの帳票をHTMLで出力する機能のPHP(Laravel)による実装例です。 こちらで実際に動くデモが見られます ?? 実装内容についての詳細は こちらのブログ記事 で解説していま

Takashi Kanemoto 21 Dec 11, 2022
Generate PDFs in Laravel with Mpdf.

Laravel Mpdf: Using Mpdf in Laravel for generate Pdfs Easily generate PDF documents from HTML right inside of Laravel using this mpdf wrapper. Importa

Carlos Meneses 264 Jan 4, 2023
Generate PDF invoices for your customers in laravel

What is Invoices? Invoices is a Laravel library that generates a PDF invoice for your customers. The PDF can be either downloaded or streamed in the b

Erik C. Forés 399 Jan 2, 2023
⚡️ MIRROR — A feature-rich Laravel wrapper for the WeasyPrint Document Factory.

WeasyPrint for Laravel A feature-rich Laravel wrapper for the WeasyPrint Document Factory. This package requires Laravel 8.47+ running on PHP 8+ in or

Mike Rockétt 7 Dec 30, 2022
Browsershot wrapper for Laravel 5

Browsershot wrapper for Laravel 5 This package takes advantage of Google Chrome's Headless mode to take screenshots and generate PDFs from websites, v

VECO 108 Jul 25, 2022
Ce projet vous montre comment utiliser des fonts localement dans vos applications Laravel, avec ViteJS et Tailwind CSS

Laravel - use local fonts with Tailwind CSS and Vite Ce projet est né d'un constat: vous êtes souvent nombreuses et nombreux à galérer pour utiliser d

Fred Christian 2 Sep 20, 2022
A DOMPDF Wrapper for Laravel

DOMPDF Wrapper for Laravel Laravel wrapper for Dompdf HTML to PDF Converter Require this package in your composer.json and update composer. This will

Barry vd. Heuvel 5.6k Jan 7, 2023
DOMPDF module for Laravel 5

pdf-laravel5 DOMPDF module for Laravel 5. Export your views as PDFs - with css support. Instalation Add: "vsmoraes/laravel-pdf": "^2.0" To your compo

Vinicius Moraes 88 Jul 25, 2022
A DOMPDF Wrapper for Laravel

DOMPDF Wrapper for Laravel Laravel wrapper for Dompdf HTML to PDF Converter Require this package in your composer.json and update composer. This will

Barry vd. Heuvel 5.6k Dec 25, 2022
salah eddine bendyab 18 Aug 17, 2021