画像の特性
$ identify fuji_mod.jpg
fuji_mod.jpg JPEG 320x238 320x238+0+0 8-bit sRGB 17971B 0.010u 0:00.000
Arch Linux でのライブラリーのインストール
sudo pacman -S python-pillow
sudo pacman -S python-reportlab
jpg_import.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# jpg_import.py
#
# Nov/19/2018
#
# ------------------------------------------------------------------
import sys
from PIL import Image
#
from reportlab.pdfgen import canvas
from reportlab.pdfbase.pdfmetrics import registerFont
from reportlab.pdfbase.cidfonts import UnicodeCIDFont
# ------------------------------------------------------------------
sys.stderr.write ("*** 開始 ***\n")
#
font_mincho = "HeiseiMin-W3"
#
registerFont(UnicodeCIDFont (font_mincho))
#
pdf_canvas = canvas.Canvas("fuji.pdf")
#
ypos = 800
pdf_canvas.setFont(font_mincho, 30)
str_out = "富士山の写真です。"
pdf_canvas.drawString(100, ypos, str_out)
#
image =Image.open('fuji_mod.jpg')
pdf_canvas.drawInlineImage(image,100,ypos - 260)
#
str_out="2018年11月19日"
pdf_canvas.setFont(font_mincho, 15)
pdf_canvas.drawString(300, ypos - 300, str_out)
#
pdf_canvas.showPage()
pdf_canvas.save()
#
sys.stderr.write ("*** 終了 ***\n")
# ------------------------------------------------------------------
実行結果
$ ./jpg_import.py
*** 開始 ***
*** 終了 ***
次のバージョンで確認しました。
$ python --version
Python 3.10.4