midi/document-converter

将办公文档转换为图片/ PDF

v1.0.1 2022-08-12 01:36 UTC

This package is auto-updated.

Last update: 2024-09-12 06:07:51 UTC


README

LibreOffice 的 PHP 库

使用 LibreOffice 将办公文件转换为 PDF 或 JPG 或 PNG

支持的文件类型

pdf
pptx
ppt
docx
doc
wps
dotx
dotm
dot
odt
docm
ddt
xlsx
xls
log
txt

系统库安装

brew install ghostscript
brew install ImageMagick
brew install pkg-config
pecl install imagick
brew install libreoffice
  • centos
yum install ghostscript
yum install ImageMagick
yum install pkg-config
pecl install imagick
yum install libreoffice
  • ubuntu
apt-get install ghostscript
apt-get install ImageMagick
apt-get install pkg-config
pecl install imagick
apt-get install libreoffice

安装

在您的项目目录中运行此命令

composer require midi/document-converter

用法

以下是一些示例。

  • 将 PDF 转换为图像数组
$service = new DocumentConverter('/tmp/1.pdf');
$service->fileToImage()

// image save dir : /usr/tmp/a/dir
// image save ext : jpg
// image background : green
// image background : green
// read source file resolution : 100
// save image quality : 90
$service = new DocumentConverter('/tmp/1.pdf', '/usr/tmp/a/dir', 'jpg', 'green', 100, 90);
$service->fileToImage()
  • 将 doc 转换为图像数组
$service = new DocumentConverter('/tmp/1.docx');
$service->fileToImage()
  • 将 doc/ppt 转换为图像数组
$service = new DocumentConverter('/tmp/1.pptx');
$pdfPath = $service->fileToPdf()

方法返回结果

  • fileToImage
[
    'total_page' => 4,
    'success_total' => 3,
    'fail_total' => 1,
    'success_page' => [
        '/tmp/1.jpg',
        '/tmp/2.jpg',
        '/tmp/4.jpg',
    ],
    'success_page' => [
        '/tmp/1.jpg',
        '/tmp/2.jpg',
    ],
    'fail_page' => [
        '/tmp/3.jpg',
    ]
]
  • fileToPdf
'/tmp/a/b/c/d/1.pdf'
  • 异常
DocumentConverterException

许可证

OfficeConverter 软件包是开源软件,许可协议为 MIT 许可证

反馈 & 贡献

告诉我任何问题、错误或改进。谢谢。