viterbit/liboffice-converter

LibreOffice转换器的PHP包装器

v2.0.0 2023-08-17 09:48 UTC

This package is auto-updated.

Last update: 2024-09-17 12:05:33 UTC


README

将文档转换为各种格式的简单方法。

例如:html -> docx, html -> pdf, docx -> html 以及更多。

用法

use Viterbit\LibOfficeConverter\Converter;
use Viterbit\LibOfficeConverter\Parameters;
use Viterbit\LibOfficeConverter\Format;

// Create converter
$converter = new Converter();

// Describe parameters for converter
$parameters = (new Parameters())
    // HTML document
    ->setInputFile('test.html')
    // Format of result document is docx
    ->setOutputFormat(Format::TEXT_DOCX)
    // Result file name
    ->setOutputFile('path-to-result-docx.docx');

// Run converter
$converter->convert($parameters);

需求

  • PHP 7+
  • 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 viterbit/liboffice-converter

将libreoffice安装到Docker容器中的示例

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

将libreoffice安装到mac中的示例

brew cask install libreoffice

note: bin located at /usr/local/bin/soffice

运行测试

./vendor/bin/phpunit

贡献

在提交之前,首先安装检查工具。需要Node。

npm install

许可证

在MIT许可证下发布