1
5

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.

reportlab で 複数ページの PDF を作成

Posted at

例として、3ページのPDFファイルを作成する方法です。

gen_plural.py
#! /usr/bin/python
#
#	gen_plural.py
#
#						Jan/17/2019
#
# ------------------------------------------------------------------
import	sys
#
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("out01.pdf")
#
#
pdf_canvas.setFont(font_mincho, 30)
pdf_canvas.drawString(100, 700, "1ページ目です。")
str_out = "日本語でこんにちは! 明朝体"
pdf_canvas.drawString(100, 500, str_out)
#
str_out="2019年1月17日"
pdf_canvas.drawString(400, 200, str_out)
#
pdf_canvas.showPage()
#
pdf_canvas.setFont(font_mincho, 30)
pdf_canvas.drawString(100, 700, "2ページ目です。")
str_out = "日本語でこんにちは! 明朝体"
pdf_canvas.drawString(100, 500, str_out)
pdf_canvas.showPage()
#
pdf_canvas.setFont(font_mincho, 30)
str_out = "日本語でこんにちは! 明朝体"
pdf_canvas.drawString(100, 700, "3ページ目です。")
pdf_canvas.drawString(100, 500, str_out)
pdf_canvas.showPage()
#
pdf_canvas.save()
#
sys.stderr.write ("*** 終了 ***\n")
# ------------------------------------------------------------------
1
5
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
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?