HTMLをPDFに変換するためのライブラリ「xhtml2pdf」をインストールする

スポンサーリンク

HTMLをPDFに変換するためのライブラリ「xhtml2pdf」のインストールについて解説しています。

xhtml2pdfのライブラリは、Python、ReportLab Toolkit、html5lib及びPyPDF2を使用しHTMLからPDFへの変換できるライブラリです。Python2.7以降で使用することができます。

■Python

今回のPythonのバージョンは、「3.8.5」を使用しています。(Windows10)(pythonランチャーでの確認)

■xhtml2pdfをインストールする

xhtml2pdfをインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。

pip install xhtml2pdf

起動後、上記のコマンドを入力し、Enterキーを押します。

なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、pipを使う場合にはコマンドでの切り替えを行います。

py -3.8 -m pip install xhtml2pdf

切り替えるために、上記のコマンドを入力し、Enterキーを押します。

Defaulting to user installation because normal site-packages is not writeable
Collecting xhtml2pdf
Downloading xhtml2pdf-0.2.5.tar.gz (100 kB)
|████████████████████████████████| 100 kB 903 kB/s
Collecting html5lib>=1.0
Downloading html5lib-1.1-py2.py3-none-any.whl (112 kB)
|████████████████████████████████| 112 kB 1.7 MB/s
Requirement already satisfied: pyPdf2 in c:\users\user_\appdata\roaming\python\python38\site-packages (from xhtml2pdf) (1.26.0)
Requirement already satisfied: Pillow in c:\users\user_\appdata\roaming\python\python38\site-packages (from xhtml2pdf) (8.2.0)
Requirement already satisfied: reportlab>=3.3.0 in c:\users\user_\appdata\roaming\python\python38\site-packages (from xhtml2pdf) (3.5.67)
Requirement already satisfied: six in c:\users\user_\appdata\roaming\python\python38\site-packages (from xhtml2pdf) (1.15.0)
Collecting python-bidi>=0.4.2
Downloading python_bidi-0.4.2-py2.py3-none-any.whl (30 kB)
Collecting arabic-reshaper>=2.1.0
Downloading arabic_reshaper-2.1.3-py3-none-any.whl (20 kB)
Requirement already satisfied: webencodings in c:\users\user_\appdata\roaming\python\python38\site-packages (from html5lib>=1.0->xhtml2pdf) (0.5.1)
Requirement already satisfied: future in c:\users\user_\appdata\roaming\python\python38\site-packages (from arabic-reshaper>=2.1.0->xhtml2pdf) (0.18.2)
Requirement already satisfied: setuptools in c:\program files\python38\lib\site-packages (from arabic-reshaper>=2.1.0->xhtml2pdf) (47.1.0)
Building wheels for collected packages: xhtml2pdf
Building wheel for xhtml2pdf (setup.py) … done
Created wheel for xhtml2pdf: filename=xhtml2pdf-0.2.5-py3-none-any.whl size=234349 sha256=0c2c8cf6fb3190dfbc0b1130fa542aaef1588149a4c5d8b7322642a9ca401a03
Stored in directory: c:\users\user_\appdata\local\pip\cache\wheels\6d\a5\a7\30fb2322bd454ae3098b68e02649a57af0f8495737d00918c9
Successfully built xhtml2pdf
Installing collected packages: html5lib, python-bidi, arabic-reshaper, xhtml2pdf
Successfully installed arabic-reshaper-2.1.3 html5lib-1.1 python-bidi-0.4.2 xhtml2pdf-0.2.5

Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、xhtml2pdfが正常にインストールされたことになります。

なお、今回はxhtml2pdfのバージョン0.2.5をインストールしました。

コメント

タイトルとURLをコピーしました