PHPackages                             oyswonder/html2pdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. oyswonder/html2pdf

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

oyswonder/html2pdf
==================

A Simple package for easily generating PDF documents from HTML.This package is specially for laravel but you can use this without laravel.

1.5.0(3y ago)0112↓100%MITPHP

Since Mar 29Pushed 3y agoCompare

[ Source](https://github.com/oyswonder/laravel-pdf)[ Packagist](https://packagist.org/packages/oyswonder/html2pdf)[ RSS](/packages/oyswonder-html2pdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)DependenciesVersions (22)Used By (0)

Laravel-Html2Pdf
================

[](#laravel-html2pdf)

[![Latest Stable Version](https://camo.githubusercontent.com/dc3577b6d332014e18353cb47acbda6ef6a585e27f38bda29496570631adf07e/68747470733a2f2f706f7365722e707567782e6f72672f6f7973776f6e6465722f68746d6c327064662f762f737461626c65)](https://packagist.org/packages/oyswonder/html2pdf)[![Total Downloads](https://camo.githubusercontent.com/592ab9a4c43205bc6bf07fe60773df8f26ea75a07678b744145c516af6ac5ef5/68747470733a2f2f706f7365722e707567782e6f72672f6f7973776f6e6465722f68746d6c327064662f646f776e6c6f616473)](https://packagist.org/packages/oyswonder/html2pdf)[![Latest Unstable Version](https://camo.githubusercontent.com/3c52ed3b732ffe6a78246ae8828852b85928f16f80e47730acb4b2c4e187f384/68747470733a2f2f706f7365722e707567782e6f72672f6f7973776f6e6465722f68746d6c327064662f762f756e737461626c65)](https://packagist.org/packages/oyswonder/html2pdf)[![License](https://camo.githubusercontent.com/912ec2c15ad55ba6a39bb0811b460ff739e0930cb78d132bf517a622095d26cd/68747470733a2f2f706f7365722e707567782e6f72672f6f7973776f6e6465722f68746d6c327064662f6c6963656e7365)](https://packagist.org/packages/oyswonder/html2pdf)

> 一个简单的包，用于把HTML页面生成为PDF文档。该程序包专门用于laravel，但您可以在不使用laravel的情况下使用。 此包是基于 [nahidulhasan/laravel-pdf](https://github.com/nahidulhasan/laravel-pdf) 上修改的。

安装
--

[](#安装)

#### 安装 wkhtmltopdf

[](#安装-wkhtmltopdf)

经以下系统测试:

- Ubuntu 18.04.3 x64
- Windows 10 x64

wkhtmltopdf ≥ 0.12.5

#### 可在官网直接下载安装包安装（推荐）

[](#可在官网直接下载安装包安装推荐)

官网安装包包含 qt，可以直接运行 wkhtmltopdf 而不需要额外安装 vxfb

#### 通过 apt 安装

[](#通过-apt-安装)

```
sudo apt-get update
sudo apt-get install xvfb libfontconfig wkhtmltopdf
```

#### For docker

[](#for-docker)

```
RUN apt-get update && apt-get install xvfb libfontconfig wkhtmltopdf

```

#### Upddate Composer

[](#upddate-composer)

```
composer require oyswonder/html2pdf

```

如果 laravel 版本&lt;5.5，请将 ServiceProvider 添加到 config/app.php 中的 providers 数组中

```
oyswonder\Html2pdf\Html2pdfServiceProvider::class,

```

您可以选择将 facade 用于较短的代码。把这个加到你的 facades 上:

```
'Pdf'  => oyswonder\Html2pdf\Facades\Pdf::class,

```

基础用法
----

[](#基础用法)

要创建PDF，请向您的一个 Controller 中添加类似的内容。

```
use oyswonder\Html2pdf\Facades\Pdf;

$document = Pdf::generatePdf('http://bantouren.com/html/table/sample.html');
```

### 下载 pdf

[](#下载-pdf)

将PDF保存到特定文件夹中的文件中，然后下载

```
use oyswonder\Html2pdf\Pdf;

$obj = new Pdf();

$url = 'http://bantouren.com/html/table/sample.html';

$invoice = $obj->generatePdf($url);

define('INVOICE_DIR', public_path('uploads/invoices'));

if (!is_dir(INVOICE_DIR)) {
    mkdir(INVOICE_DIR, 0755, true);
}

$outputName = str_random(10);
$pdfPath = INVOICE_DIR.'/'.$outputName.'.pdf';

File::put($pdfPath, $invoice);

$headers = [
    'Content-Type' => 'application/pdf',
    'Content-Disposition' =>  'attachment; filename="'.'filename.pdf'.'"',
];

return response()->download($pdfPath, 'filename.pdf', $headers);

```

### Other Usage

[](#other-usage)

也可以使用以下方法 :

`pdf::stream('http://bantouren.com/html/table/sample.html') ` 在浏览器中打开PDF文件

### Running without Laravel

[](#running-without-laravel)

您可以不在 Laravel 上使用此库。

例如:

```
use oyswonder\Html2pdf\Pdf;

$obj = new Pdf();
$document = $obj->generatePdf('http://bantouren.com/html/table/sample.html');

```

### License

[](#license)

Html2PDF for Laravel 是根据 [MIT license](http://opensource.org/licenses/MIT) 许可证许可的。

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 81.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~78 days

Recently: every ~194 days

Total

21

Last Release

1392d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4552568feedea40044fabefd3930650324f89b3e807b9fc59303f8b4f24a898f?d=identicon)[oyswonder](/maintainers/oyswonder)

---

Top Contributors

[![nahidulhasan](https://avatars.githubusercontent.com/u/3033344?v=4)](https://github.com/nahidulhasan "nahidulhasan (48 commits)")[![oyswonder](https://avatars.githubusercontent.com/u/8193354?v=4)](https://github.com/oyswonder "oyswonder (9 commits)")[![Wilson-NIT](https://avatars.githubusercontent.com/u/97659000?v=4)](https://github.com/Wilson-NIT "Wilson-NIT (2 commits)")

### Embed Badge

![Health badge](/badges/oyswonder-html2pdf/health.svg)

```
[![Health](https://phpackages.com/badges/oyswonder-html2pdf/health.svg)](https://phpackages.com/packages/oyswonder-html2pdf)
```

###  Alternatives

[phpoffice/phpspreadsheet

PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine

13.9k293.5M1.2k](/packages/phpoffice-phpspreadsheet)[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M100](/packages/spatie-browsershot)[smalot/pdfparser

Pdf parser library. Can read and extract information from pdf file.

2.7k34.5M216](/packages/smalot-pdfparser)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M128](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
