LoginSignup
3
2

More than 1 year has passed since last update.

Excel文書のPDF変換で日本語フォントがおかしかった件

Last updated at Posted at 2022-08-11

はじめに

LibreOfficeのsofficeコマンドを使用し、Excel文書をPDFに変換時、
場合によっては、OSにフォント追加が必要だった、といった内容です。

LibreOfficeとsofficeコマンドとは

  • LibreOffice
    • オープンソースソフトの統合オフィスソフトウェア
  • sofficeコマンド
    • LibreOfficeに内蔵されたドキュメント変換コマンド

検証環境

  • AlmaLinux 8.6

LibreOfficeをインストール

まず、依存ライブラリをインストール

$ sudo dnf update
$ sudo dnf install dnf-plugins-core
$ sudo dnf install nss
$ sudo dnf install cups

つぎ、LibreOfficeパッケージと追加日本語パッケージをインストール

$ wget https://download.documentfoundation.org/libreoffice/stable/7.3.5/rpm/x86_64/LibreOffice_7.3.5_Linux_x86-64_rpm.tar.gz
$ wget https://download.documentfoundation.org/libreoffice/stable/7.3.5/rpm/x86_64/LibreOffice_7.3.5_Linux_x86-64_rpm_langpack_ja.tar.gz
$ sudo tar zxvf LibreOffice_7.3.5_Linux_x86-64_rpm.tar.gz
$ sudo tar xvf LibreOffice_7.3.5_Linux_x86-64_rpm_langpack_ja.tar.gz
$ sudo dnf localinstall LibreOffice_7.3.5.2_Linux_x86-64_rpm/RPMS/*.rpm -y
$ sudo dnf localinstall LibreOffice_7.3.5.2_Linux_x86-64_rpm_langpack_ja/RPMS/*.rpm -y

sofficeコマンドでExcelファイルをPDFに変換してみる

$ /opt/libreoffice7.3/program/soffice --headless --convert-to pdf test-font.xlsx

PDF変換はできましたが、漢字の書体がなんか変。

変換元Excel 変換後PDF
image.png image.png

必要フォントがOSに存在せず、別のフォントが使われた?

IPAフォントを入れてみる

$ wget https://moji.or.jp/wp-content/ipafont/IPAfont/IPAfont00303.zip
$ unzip IPAfont00303.zip
$ sudo cp -rf IPAfont00303 /usr/share/fonts/
$ fc-cache -fr
$ fc-list | grep -i IPA
/usr/share/fonts/IPAfont00303/ipag.ttf: IPAゴシック,IPAGothic:style=Regular
/usr/share/fonts/IPAfont00303/ipamp.ttf: IPA P明朝,IPAPMincho:style=Regular
/usr/share/fonts/IPAfont00303/ipam.ttf: IPA明朝,IPAMincho:style=Regular
/usr/share/fonts/IPAfont00303/ipagp.ttf: IPA Pゴシック,IPAPGothic:style=Regular

再度、変換を試みる

今度は書体が正しく変換できました。

変換元Excel 変換後PDF
image.png image.png

おわりに

sofficeコマンドでOffice文書をPDF変換時、
書体が変になったらフォント追加を試してみるとよいかもしれません。

3
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
3
2