LoginSignup
6
6

More than 5 years have passed since last update.

AWSでExcelからPDF変換を行う

Posted at

Excelの見た目のままPDFを作成するために、libreconvを使用してExcelからPDFへconvertをしてみた

環境

  • Amazon Linux
  • Ruby 2.3.0
  • Ruby on Rails 5.0.1

AWSにLibreOfficeをインストールする

$ sudo wget http://ftp.yz.yamagata-u.ac.jp/pub/tdf/libreoffice/stable/5.3.3/rpm/x86_64/LibreOffice_5.3.3_Linux_x86-64_rpm.tar.gz
$ tar xvzf LibreOffice_5.3.3_Linux_x86-64_rpm.tar.gz
$ cd LibreOffice_5.3.3.2_Linux_x86-64_rpm/
$ cd RPMS/
$ sudo yum install *.rpm
$ sudo yum install dbus-glib

gemのインストール

Gemfileに下記を追加
gem 'libreconv'

実装

  require 'libreconv'

  def convert_pdf
    Libreconv.convert('public/sample.xlsx', 'public/sample.pdf')
  end

出力されるpdfはxlsxで指定した印刷イメージで作成されるようだが、指定のフォントがない場合は、多少印刷イメージがずれることがある。
印刷イメージがずれる場合は適宜フォントをインストールする必要がある。

6
6
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
6
6