1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[PHP] WordをPDFに変換する

Posted at

 環境

centos 7
php 7.0
yumやcomposerはinstall済みとします

composer.json

composer.jsonを用意
{
    "require": {
       "phpoffice/phpword": "dev-master",
       "gears/pdf":"*"
    },
    "scripts":
    {
	"post-install-cmd": ["PhantomInstaller\\Installer::installPhantomJS"],
	"post-update-cmd": ["PhantomInstaller\\Installer::installPhantomJS"]
    }
}

cmdでの作業

$yum -y install libreoffice libreoffice-langpack-ja
$yum -y install php-pecl-zip.x86_64
$composer install #composer.jsonがあるディレクトリで行う

変換処理を行うphpを作る

convert.php
<?php
require './vendor/autoload.php';
Gears\Pdf::convert('./test.docx', './test.pdf');

※ test.docxは適当なテスト用のwordファイルです

convert.phpを実行すれば完了!

dockerで起動する

参考文献

https://packagist.org/packages/gears/pdf
https://www.ka-net.org/blog/?p=6952

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?