# -*- coding: utf-8 -*-
# 康虎软件工作室
# http://www.khcloud.net
# QQ: 360026606
# wechat: 360026606
#######################
# 用Python在PDF右下角插入图片的例子
import fitz # <-- PyMuPDF
margin_top = 70 # 图片下边空白
margin_right = 10 # 图片右边空白
imgw = 50 # 显示图片宽度
imgh = 50 # 显示图片调试
doc = fitz.open("test.pdf") # 载入源PDF
img = open("test.png", "rb").read() # 载入图片
for page in doc:
pw = page.rect.width
ph = page.rect.height
x0 = pw - imgw - margin_right
y0 = ph - imgh - margin_top
rect = fitz.Rect(x0, y0, x0 + imgw, y0 + imgh)
if not page._isWrapped:
page._wrapContents()
page.insertImage(rect, stream=img)
doc.save(filename="test3.pdf") # 输出PDF