承接 curiousteam/laravel-pdf-drivers 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

curiousteam/laravel-pdf-drivers

最新稳定版本:v1.0.1

Composer 安装命令:

composer require curiousteam/laravel-pdf-drivers

包简介

Driver-based PDF generator for Laravel (mPDF, Dompdf, Html2Pdf) with a unified API.

README 文档

README

Latest Version on Packagist Total Downloads

A simple, driver-based PDF generation manager for Laravel.
Supports multiple PDF libraries (drivers) such as mPDF, Dompdf, TCPDF, and more.

Installation

You can install the package via composer:

composer require curiousteam/laravel-pdf-drivers

You can publish the config file with:

php artisan vendor:publish --provider="Curiousteam\LaravelPdfDrivers\PdfServiceProvider" --tag="config"

If you are on Laravel < 5.5, you need to manually register the service provider:

// config/app.php
'providers' => [
    Curiousteam\LaravelPdfDrivers\PdfServiceProvider::class,
],

Configuration

After publishing, you’ll get a config file at config/pdf.php:

return [

    'driver' => env('PDF_DRIVER', 'mpdf'), // dompdf|mpdf|html2pdf

    'drivers' => [

        'dompdf' => [
            'options' => [
                'isHtml5ParserEnabled' => true,
                'isRemoteEnabled' => true,
                'defaultFont' => 'DejaVu Sans',
            ],
            'paper' => ['size' => 'A4', 'orientation' => 'portrait'],
        ],

        'mpdf' => [
            'options' => [
                'mode' => 'utf-8',
                'format' => 'A4',
                'tempDir' => storage_path('app/mpdf-temp'),
                'default_font' => 'dejavusans',
            ],
            'paper' => ['size' => 'A4', 'orientation' => 'landscape'],
        ],

        'html2pdf' => [
            'options' => [
                'format' => 'A4',
                'orientation' => 'P',
                'language' => 'en',
                'unicode' => true,
                'encoding' => 'UTF-8',
                'margins' => [10, 10, 10, 10],
            ],
            'paper' => ['size' => 'A4', 'orientation' => 'portrait'],
        ],

    ],

];

Usage

Basic Example

use Curiousteam\LaravelPdfDrivers\Facades\Pdf;

Route::get('/download-report', function () {
    $html = view('templates.pdf.reports.example', ['title' => 'Laravel PDF Driver'])->render();

    return Pdf::loadHTML($html)
        ->download('report.pdf');
});

Streaming PDF in Browser

return Pdf::loadView('templates.pdf.reports.invoice', ['invoice' => $invoice])
    ->stream('invoice.pdf');

Saving PDF to Disk

Pdf::loadHTML('<h1>Hello CuriousTeam</h1>')
    ->save(storage_path('app/reports/hello.pdf'));

Switching Drivers

Default installed driver is: mpdf

To use other driver (Dompdf\Dompdf or Spipu\Html2Pdf), you need to install the package via composer first:

composer require dompdf/dompdf

Or,

composer require spipu/html2pdf

Then, you can easily switch drivers at runtime:

$pdf = Pdf::driver('dompdf')
    ->loadView('reports.test')
    ->download('test.pdf');

Or, even dynamically in .env:

PDF_DRIVER=dompdf

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-03