PHPackages                             alanalbert/office2pdf - 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. alanalbert/office2pdf

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

alanalbert/office2pdf
=====================

Office文件转PDF，基于COM，仅支持Windows系统

v0.0.4(5y ago)121962MITPHP

Since Jul 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/anhoder/office2pdf)[ Packagist](https://packagist.org/packages/alanalbert/office2pdf)[ RSS](/packages/alanalbert-office2pdf/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (5)Used By (0)

Office转PDF

> 该库基于Office(或WPS) COM组件，因此只支持Windows系统，其他系统可以考虑使用其他库，例如Open Office、PHPOffice。

安装
--

[](#安装)

- Microsoft Office或WPS
- PHP配置开启`com.allow_dcom = true`
- PHP配置`extension=php_com_dotnet.dll`（PHP 5.4.5之前的版本自带，不需要开启）

使用
--

[](#使用)

1. `composer require alanalbert/office2pdf`
2. 包含composer的自动加载文件`autoload.php`
3. 编写具体业务逻辑，如下（注意：Windows使用的中文编码为GBK，因此需要使用`iconv`函数进行编码转换）：

```
require '../vendor/autoload.php';

$source_path_utf8 = "E:/测试.doc";                           // Word文件路径
$source_path = iconv('UTF-8', 'GBK', $source_path_utf8);	// 转为GBK，防止中文乱码而找不到文件
$output_path = $source_path . '.pdf';                       // PDF目标文件路径

$office = new Office\OfficeCOM();
$office->run('word');
var_dump($office->word2Pdf($source_path, $output_path));
$office->close('word');
```

方法
--

[](#方法)

```
/*
 * @method boolean      run($type = 'all')                      运行应用, 参数: all|word|excel|ppt
 * @method boolean      close($type = 'all')                    关闭应用, 参数: all|word|excel|ppt
 * @method int|false    getPageNumFromDoc($file)                获取Word文档页数
 * @method int|false    getPageNumFromPpt($file)                获取PPT文档页数
 * @method int|false    getPageNumFromExcel($file)              获取Excel文档页数
 * @method int|false    getPageNumFromPdf($file)                获取PDF文件页数
 * @method boolean      word2Pdf($source_file, $output_file)    Word转PDF
 * @method boolean      excel2Pdf($source_file, $output_file)   Excel转PDF
 * @method boolean      ppt2Pdf($source_file, $output_file)     PPT转PDF
 */
```

更多
--

[](#更多)

如果需要使用更多功能，请参考[微软office开发文档](https://msdn.microsoft.com/vba/office-vba-reference)（适用于WPS）。

###  Health Score

28

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~90 days

Total

4

Last Release

2159d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dad4638c843a9c787c1225aec52ec22b386dd2de55af00f39a165fe83f693635?d=identicon)[anhoder](/maintainers/anhoder)

---

Top Contributors

[![anhoder](https://avatars.githubusercontent.com/u/27605589?v=4)](https://github.com/anhoder "anhoder (10 commits)")

---

Tags

excelofficeoffice-pdfpdfphppptwordwpspdfexcelwordofficeppt

### Embed Badge

![Health badge](/badges/alanalbert-office2pdf/health.svg)

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

###  Alternatives

[openspout/openspout

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

1.1k54.0M98](/packages/openspout-openspout)[gotenberg/gotenberg-php

A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!

3674.8M15](/packages/gotenberg-gotenberg-php)[vaites/php-apache-tika

Apache Tika bindings for PHP: extracts text from documents and images (with OCR), metadata and more...

1191.4M2](/packages/vaites-php-apache-tika)[mnvx/lowrapper

PHP wrapper over LibreOffice converter

129187.4k](/packages/mnvx-lowrapper)[jimmyjs/laravel-report-generator

Rapidly Generate Simple Pdf &amp; Excel Report on Laravel 5 (Using Barryvdh/DomPdf or Barryvdh/laravel-snappy &amp; maatwebsite/excel)

589154.9k1](/packages/jimmyjs-laravel-report-generator)[dcat/easy-excel

使用简单实用的语义化接口快速读写Excel文件

155367.9k21](/packages/dcat-easy-excel)

PHPackages © 2026

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