darkdarin / lowrapper
LibreOffice转换器的PHP封装
v2.0.0
2024-05-01 13:04 UTC
Requires
- php: 8.2.*|8.3.*
- psr/log: ^1|^2|^3
- symfony/process: ^6.0|^7.0
Requires (Dev)
- laravel/pint: ^1.10
- phpunit/phpunit: ^10.0
- vimeo/psalm: ^5.23
This package is auto-updated.
Last update: 2024-08-31 00:44:08 UTC
README
LibreOffice转换器的PHP封装
将文档转换为各种格式的简单方式。
例如:html -> docx,html -> pdf,docx -> html 以及更多。
使用方法
use DarkDarin\Lowrapper\Converter; use DarkDarin\Lowrapper\LowrapperParameters; use DarkDarin\Lowrapper\Format\TextFormatEnum; // Create converter $converter = new Converter(); // Describe parameters for converter $parameters = (new LowrapperParameters(TextFormatEnum::DOCX)) // HTML document ->setInputFile('test.html') // Result file name ->setOutputFile('path-to-result-docx.docx'); // Run converter $converter->convert($parameters);
更多 示例
要求
- PHP 5.5+
- libreoffice-core
安装
sudo add-apt-repository ppa:libreoffice/ppa sudo apt-get update sudo apt-get install default-jdk -y sudo apt-get install python-software-properties -y sudo apt-get install software-properties-common -y sudo apt-get install libreoffice-core --no-install-recommends sudo apt-get install libreoffice-writer composer require mnvx/lowrapper
在Docker容器中安装libreoffice的示例
FROM php:7.2-fpm WORKDIR /var/www/html # Install libreoffice headless RUN apt update -y \ && mkdir -p /usr/share/man/man1 \ && apt -y install default-jdk-headless libreoffice-core libreoffice-writer libreoffice-calc RUN mkdir -p /var/www/.cache/dconf \ && mkdir -p /var/www/.config/libreoffice \ && chmod -R ugo+rwx /var/www/.cache \ && chmod -R ugo+rwx /var/www/.config
运行测试
./vendor/bin/phpunit
许可证
在MIT许可证下发布