1
3

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.

Nginx+PHP-FPM+LibreOfficeで--convert-to pdfで失敗する時の対処法

Posted at

PHPExcel+LibreOfficeでエクセルファイルからPDFを生成する方法がありますが、WEBアプリケーションとして実行した場合に失敗するケースがありました。
その場合、nginx(もしくはapache)ユーザーのHOMEディレクトリに.config/libreofficeディレクトリへの書き込み権限があるかどうかを確認するとうまく行く場合があります。

以下のコマンドを叩いてcreateSettingsDocumentでエラーとなっていた場合は有効のようです。

$ sudo -u nginx libreoffice5.4 --headless --convert-to pdf --outdir /tmp /tmp/phpfoobarbaz.xlsx

[Java framework] Error in function createSettingsDocument (elements.cxx).
javaldx failed!
Warning: failed to read path from javaldx

nginxユーザーのHOMEディレクトリを確認します。

$ echo ~nginx

/var/cache/nginx

そのHOMEディレクトリ配下に、設定ファイルのディレクトリを作成します。

$ sudo mkdir -p /var/cache/nginx/.config/libreoffice
$ sudo chown -R nginx:nginx /var/cache/nginx/.config

再度実行して成功するかどうか確認します。

$ sudo -u nginx libreoffice5.4 --headless --convert-to pdf --outdir /tmp /tmp/phpfoobarbaz.xlsx

convert /tmp/phpfoobarbaz.xlsx -> /tmp/phpfoobarbaz.pdf using filter : calc_pdf_Export
1
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?