sglms/pdf 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sglms/pdf

最新稳定版本:0.4

Composer 安装命令:

composer require sglms/pdf

包简介

Simple Laravel wrapper for mPDF with fluent view rendering and signing helpers.

README 文档

README

Simple Laravel wrapper around mPDF with a fluent API for rendering Blade views, attaching headers/footers, and signing documents.

Requirements

  • PHP >= 8.3
  • Laravel 12
  • mPDF 8.2+

Installation

composer require sglms/pdf

Laravel package discovery registers the service provider and facade automatically.

Quick Start

use Sglms\Pdf\Facades\Pdf;

Pdf::view('pdf.invoice', ['order' => $order])->output('invoice.pdf');

Usage

Initialize with configuration

use Sglms\Pdf\Facades\Pdf;

$pdf = Pdf::init(
	config: ['format' => 'Letter'],
	stylesheet: 'css/pdf.css',
	header: 'pdf.header',
	footer: 'pdf.footer'
);

Render one or multiple views

$pdf->view('pdf.page-one', ['name' => 'Jane'])
	->view('pdf.page-two')
	->output('document.pdf');

Add logo for header/footer views

The logo is available in mPDF templates as var:logo.

$pdf->logo('images/logo.svg');

If your header or footer uses the logo, call logo() before header() / footer().

Add signature block

$pdf->sign(
	signature: 'pdf.signature',
	data: ['name' => 'John Doe'],
	x: 50,
	y: 100,
	width: 100
);

Sign existing PDF

$pdf->signFile('pdf.signature', storage_path('app/base.pdf'));

Output options

// Raw string — pass to Laravel's response() helper
$raw = $pdf->output('document.pdf');
$raw = $pdf->string();                   // alias, no filename context

// Write to an absolute file path
$pdf->save(storage_path('app/a.pdf'));

// Laravel Storage disk
$pdf->storeAs('a.pdf', 'public');

// Stream directly to the browser (bypasses Laravel response)
$pdf->inline('document.pdf');            // Content-Disposition: inline
$pdf->download('document.pdf');          // Content-Disposition: attachment

Access underlying mPDF instance

$mpdf = $pdf->get();

Controller Example

use App\Http\Controllers\Controller;
use Sglms\Pdf\Facades\Pdf;

class CustomController extends Controller
{
	public function render()
	{
		$bytes = Pdf::view('pdf.filename')
			->sign('pdf.signature')
			->output('document.pdf');

		return response($bytes, 200)
			->header('Content-Type', 'application/pdf')
			->header('Content-Disposition', 'inline; filename="document.pdf"');
	}
}

Notes

  • mPDF applies headers/footers from the point they are set. Set header/footer before the first rendered body view when possible.
  • This package is intentionally lightweight and optimized for straightforward document-generation workflows.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固