Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

laravel-dompdf

A DOMPDF Wrapper for Laravel

Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682 (1 ratings)
Rated 2.0 out of 5
Subscribe to updates I use laravel-dompdf


Statistics on laravel-dompdf

Number of watchers on Github 1932
Number of open issues 268
Average time to close an issue 17 days
Main language PHP
Average time to merge a PR 4 days
Open pull requests 9+
Closed pull requests 8+
Last commit over 1 year ago
Repo Created over 6 years ago
Repo Last Updated over 1 year ago
Size 74 KB
Organization / Authorbarryvdh
Latest Releasev0.8.2
Contributors9
Page Updated
Do you use laravel-dompdf? Leave a review!
View open issues (268)
View laravel-dompdf activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating laravel-dompdf for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

DOMPDF Wrapper for Laravel 5

For Laravel 4.x, check the 0.4 branch!

Require this package in your composer.json and update composer. This will download the package and the dompdf + fontlib libraries also.

composer require barryvdh/laravel-dompdf

Installation

Laravel 5.x:

After updating composer, add the ServiceProvider to the providers array in config/app.php

Barryvdh\DomPDF\ServiceProvider::class,

You can optionally use the facade for shorter code. Add this to your facades:

'PDF' => Barryvdh\DomPDF\Facade::class,

Lumen:

After updating composer add the following lines to register provider in bootstrap/app.php

  $app->register(\Barryvdh\DomPDF\ServiceProvider::class);

To change the configuration, copy the config file to your config folder and enable it in bootstrap/app.php:

  $app->configure('dompdf');

Using

You can create a new DOMPDF instance and load a HTML string, file or view name. You can save it to a file, or stream (show in browser) or download.

$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->stream();

Or use the facade:

$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');

You can chain the methods:

return PDF::loadFile(public_path().'/myfile.html')->save('/path-to/my_stored_file.pdf')->stream('download.pdf');

You can change the orientation and paper size, and hide or show errors (by default, errors are shown when debug is on)

PDF::loadHTML($html)->setPaper('a4', 'landscape')->setWarnings(false)->save('myfile.pdf')

If you need the output as a string, you can get the rendered PDF with the output() function, so you can save/output it yourself.

Use php artisan vendor:publish to create a config file located at config/dompdf.php which will allow you to define local configurations to change some settings (default paper etc). You can also use your ConfigProvider to set certain keys.

Configuration

The defaults configuration settings are set in config/dompdf.php. Copy this file to your own config directory to modify the values. You can publish the config using this command:

php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"

You can still alter the dompdf options in your code before generating the pdf using this command:

PDF::setOptions(['dpi' => 150, 'defaultFont' => 'sans-serif']);

Available options and their defaults:

  • rootDir: {app_directory}/vendor/dompdf/dompdf
  • tempDir: /tmp (available in config/dompdf.php)
  • fontDir: {app_directory}/storage/fonts/ (available in config/dompdf.php)
  • fontCache: {app_directory}/storage/fonts/ (available in config/dompdf.php)
  • chroot: {app_directory} (available in config/dompdf.php)
  • logOutputFile: /tmp/log.htm
  • defaultMediaType: screen (available in config/dompdf.php)
  • defaultPaperSize: a4 (available in config/dompdf.php)
  • defaultFont: serif (available in config/dompdf.php)
  • dpi: 96 (available in config/dompdf.php)
  • fontHeightRatio: 1.1 (available in config/dompdf.php)
  • isPhpEnabled: false (available in config/dompdf.php)
  • isRemoteEnabled: true (available in config/dompdf.php)
  • isJavascriptEnabled: true (available in config/dompdf.php)
  • isHtml5ParserEnabled: false (available in config/dompdf.php)
  • isFontSubsettingEnabled: false (available in config/dompdf.php)
  • debugPng: false
  • debugKeepTemp: false
  • debugCss: false
  • debugLayout: false
  • debugLayoutLines: true
  • debugLayoutBlocks: true
  • debugLayoutInline: true
  • debugLayoutPaddingBox: true
  • pdfBackend: CPDF (available in config/dompdf.php)
  • pdflibLicense: ""
  • adminUsername: user
  • adminPassword: password

Tip: UTF-8 support

In your templates, set the UTF-8 Metatag:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

Tip: Page breaks

You can use the CSS page-break-before/page-break-after properties to create a new page.

<style>
.page-break {
    page-break-after: always;
}
</style>
<h1>Page 1</h1>
<div class="page-break"></div>
<h1>Page 2</h1>

License

This DOMPDF Wrapper for Laravel is open-sourced software licensed under the MIT license

laravel-dompdf open issues Ask a question     (View All Issues)
  • almost 3 years Need help to get high pdf automatically adapts to the content.
  • almost 3 years Fatal Error: Box property calculation requires containing block width
  • almost 3 years html/css not rendering properly
  • about 3 years Undefined variable from other Controller
  • about 3 years Cannot set file name
  • about 3 years Fresh installation laravel 5.2 throws this error
  • about 3 years Erro no work in laravel 5.3 "->setOrientation('landscape');"
  • about 3 years CSS Float doesn't work
  • about 3 years fopen(/var/www/public_html/woods/storage/fonts//5ab413ede0c0d14abbb48febee3bfdfb.ufm): failed to open stream: No such file or directory
  • about 3 years handleError('8', 'Undefined index: ', 'url/vendor/dompdf/dompdf/lib/Cpdf.php', '3547', array('size' => '12')) in
  • about 3 years DOMPDF_TEMP_DIR configuration ignored?
  • about 3 years Maximum execution time exceeded
  • about 3 years Maximum execution time of 60 seconds exceeded on `php artisan serve`
  • about 3 years Trying to render Lavacharts into PDF
  • about 3 years Failed to load PDF document
  • about 3 years class dompdf does not exist in laravel 4.2
  • about 3 years Default paper from config seems not to be working anymore since upgrade from 0.6 zo 0.7 (Letter instead of A4 as per config)
  • about 3 years Laravel Read.me Version Wrong
  • about 3 years Class dompdf.wrapper does not exist
  • about 3 years Font issue
  • about 3 years Combine orientation page
  • about 3 years Could not install Laravel-dompdf
  • about 3 years Laravel 5.3.2 : Cannot use Facade
  • about 3 years Your requirements could not be resolved to an installable set of packages. ---- Whats wrong ?
  • about 3 years laravel 5.3 support
  • about 3 years Installation
  • about 3 years Call to undefined method Page_Frame_Decorator::add_line()
  • over 3 years Second and others call to underlying PDF object cause uglify content for utf-8 fonts
  • over 3 years merge two pdf
  • over 3 years How to set PDF to print with no scaling ?
laravel-dompdf open pull requests (View All Pulls)
  • Adding setPublicPath method to change the base path
  • Uses Laravel's filesystem for save method (saving PDF file)
  • dompdf_config workaround if workbench vendor
  • make the service provider defered and add a custom font load command
  • Fix a few grammar/typos in config file
  • Added possibility to password protect the PDF
  • Append options to existing config
  • add passworded on opening file
  • Trailing slash isn't required and causes errors
laravel-dompdf questions on Stackoverflow (View All Questions)
  • Laravel 5.1 - barryvdh/laravel-dompdf, PDF file download not working properly
  • Laravel Dompdf generate pdf Error
  • Laravel DOMPDF not generating HTML pdf file with dynamic data
  • laravel dompdf - issue with font
  • laravel-dompdf how to get multiple records into the data array
  • Laravel-dompdf (0.4) does not display remote images
  • Laravel 5.1 - barryvdh/laravel-dompdf PDF Generation Error
  • Laravel DomPdf dont support UTF-8
  • Laravel dompdf errors
  • laravel-dompdf - Japanese IPAex gothic font is not working
  • How to insert page number using barryvdh/laravel-dompdf
  • Laravel-dompdf slow generate pdf
  • Laravel dompdf not accepting Tahoma font
  • laravel dompdf get pagenumber in view
  • utf-8 support for barryvdh/laravel-dompdf on laravel 4
  • DOMPDF: Image not readable or empty. (with barryvdh/laravel-dompdf)
laravel-dompdf list of languages used
Other projects in PHP