Laravel package to convert HTML to PDF, supporting multiple drivers.

Overview

eve/pdf-converter Main

A Laravel package to help convert HTML to PDF. Supports multiple drivers.

Requirements and Installation

eve/pdf-converter requires Laravel 8.x and PHP 8.x. You can install the package via Composer:

composer require eve/pdf-converter

Next, publish the config file:

php artisan vendor:publish --provider="Eve\PdfConverter\ServiceProvider"

A pdf_converter.php file will be copied into your application's config folder.

Usage

eve/pdf-converter supports 4 drivers, which can be configured in .env with the PDF_CONVERTER_DRIVER key:

  • dompdf: The default. Uses laravel-dompdf under the hood.
  • mock: Always returns a fixture PDF file. Doesn't do any actual conversion.
  • log: Logs the input HTML and the output path using Laravel's logger. Doesn't do any actual conversion.
  • pdfcrowd: Uses the commercial Pdfcrowd service. You'll have to set the PDFCROWD_USERNAME and PDFCROWD_API_KEY environment variables as well for this driver to work.

Of these drivers, mock and log are meant for development and/or testing purposes. dompdf can be used for production but will most likely require some heavy configuration, when pdfcrowd should be the best choice if you're willing to spend some bucks per month.

As eve/pdf-converter is developed first and foremost for eve's internal use, we don't have plans to add more drivers ourselves. PRs are welcome, though.

Once everything is set, the package is dead-boring. You can use either dependency injection or the facade (or both, depending on how silly you want your codebase to look).

Dependency Injection

Inject Eve\PdfConverter\PdfConverterInterface and use it:

public function __construct(private \Eve\PdfConverter\PdfConverterInterface $converter) 
{
    $this->converter->configure('key', 'value');
    
    // returns an \Illuminate\Http\File instance
    $this->converter->convertHtml('<p>Hello World</p>', '/path/to/output/file.pdf');
}

Facade

If you're a fan of Facades for whatever reason, eve/pdf-converter provides the \Eve\PdfConverter\Facades\PdfConverter facade. This facade is even aliased to \PdfConverter for your convenience.

public function generateInvoice(): void
{
    \PdfConverter::configure('key', 'value');
    \PdfConverter::convertHtml('<p>Free of charge</p>', '/my/invoice.pdf');
}

PDF Conversion Configuration

If you've been paying notice, the PDF conversion output can be tweaked via the configure method:

$converter->configure(array|string $key, ...$values);

Now, the configuration options for the PDF conversion vary from driver to driver. Specifically:

  • For log and mock drivers, the configurations are completely ignored.

  • For dompdf, refer to the available options supported by laravel-dompdf itself.

  • For pdfcrowd, refer to the official API reference. Look for the setX() functions. You can then use X as the $key argument for configure() method and whatever setX() takes as the $values. For example:

    Pdfcrowd's API eve/pdf-converter counterpart
    setPageSize('a4') configure('PageSize', 'a4')
    setFooterHeight('30mm') configure('FooterHeight', '30mm')
    setHttpAuth('hey', 'secret') configure('HttpAuth', 'hey', 'secret')

License

MIT.

You might also like...
plugin de criação de PDF através do HTML fácil

pluginmpdf plugin de criação de PDF através do HTML Para inciar nosso pluginmpdf devemos instalar a lib abaixo. mPDF is a PHP library which generates

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page.

Snappy Snappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. It uses the excellent webkit-based wkhtmltopd

A Laravel package for creating PDF files using LaTeX
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

Rapidly Generate Simple Pdf, CSV, & Excel Report Package on Laravel
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)

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

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

Generate PDF invoices for your customers in laravel
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

Official clone of PHP library to generate PDF documents and barcodes

TCPDF PHP PDF Library Please consider supporting this project by making a donation via PayPal category Library author Nicola Asuni [email protected] co

TCPDF - PHP PDF Library - https://tcpdf.org

tc-lib-pdf PHP PDF Library UNDER DEVELOPMENT (NOT READY) UPDATE: CURRENTLY ALL THE DEPENDENCY LIBRARIES ARE ALMOST COMPLETE BUT THE CORE LIBRARY STILL

Releases(v1.1.0)
Convert html to an image, pdf or string

Convert a webpage to an image or pdf using headless Chrome The package can convert a webpage to an image or pdf. The conversion is done behind the sce

Spatie 4.1k Jan 1, 2023
Convert HTML to PDF using Webkit (QtWebKit)

wkhtmltopdf and wkhtmltoimage wkhtmltopdf and wkhtmltoimage are command line tools to render HTML into PDF and various image formats using the QT Webk

wkhtmltopdf 13k Jan 9, 2023
Gravity PDF is a GPLv2-licensed WordPress plugin that allows you to automatically generate, email and download PDF documents using Gravity Forms.

Gravity PDF Gravity PDF is a GPLv2-licensed WordPress plugin that allows you to automatically generate, email and download PDF documents using the pop

Gravity PDF 90 Nov 14, 2022
Magento 2 Invoice PDF Generator - helps you to customize the pdf templates for Magento 2

Magento 2 Invoice PDF Generator - helps you to customize the pdf templates for Magento 2. If you have an enabled template and a default template for the store you need your template the system will print the pdf template.

EAdesign 64 Oct 18, 2021
A PHP tool that helps you write eBooks in markdown and convert to PDF.

Artwork by Eric L. Barnes and Caneco from Laravel News ❤️ . This PHP tool helps you write eBooks in markdown. Run ibis build and an eBook will be gene

Mohamed Said 1.6k Jan 2, 2023
Convert a pdf to an image

Convert a pdf to an image This package provides an easy to work with class to convert PDF's to images. Spatie is a webdesign agency in Antwerp, Belgiu

Spatie 1.1k Dec 29, 2022
HTML to PDF converter for PHP

Dompdf Dompdf is an HTML to PDF converter At its heart, dompdf is (mostly) a CSS 2.1 compliant HTML layout and rendering engine written in PHP. It is

null 9.3k Jan 1, 2023
PHP library generating PDF files from UTF-8 encoded HTML

mPDF is a PHP library which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancement

null 3.8k Jan 2, 2023
PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage

Snappy Snappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. It uses the excellent webkit-based wkhtmltopd

KNP Labs 4.1k Dec 30, 2022
PHP library allowing PDF generation or snapshot from an URL or an HTML page. Wrapper for Kozea/WeasyPrint

PhpWeasyPrint PhpWeasyPrint is a PHP library allowing PDF generation from an URL or an HTML page. It's a wrapper for WeasyPrint, a smart solution help

Pontedilana 23 Oct 28, 2022