承接 oasys/chrome-pdf 相关项目开发

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

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

oasys/chrome-pdf

Composer 安装命令:

composer require oasys/chrome-pdf

包简介

Minimal Chrome/Chromium PHP wrapper for generating PDF files from HTML using headless mode

README 文档

README

Tests Latest Stable Version PHP Version Require License

Minimal Chrome/Chromium PHP wrapper for generating PDF files from HTML using headless mode

  • Save PDF to the filesystem
  • Get PDF contents as base64
  • Get PDF temporary file path
  • Uses local Chrome/Chromium
  • Configurable Chrome flags

Requirements

  • PHP 8.2+
  • Chrome or Chromium installed on the system

Installation

composer require oasys/chrome-pdf

Quick start

<?php declare(strict_types=1);

use Oasys\Pdf\ChromePdf;

$pdf = new ChromePdf();

$pdf->save(
    html: '<h1>Hello world</h1>',
    output: __DIR__ . '/document.pdf'
);

Binary

By default, the package uses google-chrome

$pdf = new ChromePdf();

On systems using Chromium:

$pdf = new ChromePdf(
    binary: 'chromium'
);

On Windows, pass the full executable path

$pdf = new ChromePdf(
    binary: 'C:\Program Files\Google\Chrome\Application\chrome.exe'
);

Chrome flags

Additional Chrome flags can be passed through the constructor

$pdf = new ChromePdf(
    flags: [
        'disable-gpu'   => true,
        'user-data-dir' => '/tmp/chrome'
    ]
);

Flags with true values are rendered as standalone flags

[
    'no-sandbox' => true
]
--no-sandbox

Standalone flags can also be passed as list values

[
    'no-sandbox',
    'disable-gpu'
]
--no-sandbox
--disable-gpu

Flags with scalar values are rendered as --key=value

[
    'user-data-dir' => '/tmp/chrome'
]
--user-data-dir=/tmp/chrome

Flags with array values are joined with commas

[
    'window-size' => [1280, 720]
]
--window-size=1280,720

Flags with false or null values are skipped

[
    'no-sandbox'  => false,
    'disable-gpu' => null
]

The following Chrome flags are controlled internally and cannot be passed manually:

  • headless
  • print-to-pdf
  • no-pdf-header-footer
  • print-to-pdf-no-header

Output methods

Save to file

$pdf->save(
    '<h1>Invoice</h1>',
    __DIR__ . '/invoice.pdf'
);

Base64

$base64 = $pdf->base64(
    '<h1>Invoice</h1>'
);
"JVBERi0xLj...CiUlRU9GCg=="

Temporary path

$path = $pdf->tempPath(
    '<h1>Invoice</h1>'
);
"/tmp/pdf-abc123.pdf"

The caller is responsible for deleting the returned file

@unlink($path);

Print CSS

Use standard print CSS to control page layout

<style>
    @page {
        size: A4;
        margin: 12mm;
    }

    body {
        font-family: sans-serif;
    }
</style>

<h1>Invoice</h1>

Design notes

  • Chrome/Chromium must be installed separately
  • HTML is written to a temporary .html file before rendering
  • Temporary HTML files are deleted automatically
  • Temporary PDF files from base64() are deleted automatically
  • Raw Chrome flags are also accepted, e.g. flags: ['--no-sandbox']
  • Header and footer generation is disabled

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固