python - 将 tkinter Canvas 导出为 PDF
问题描述
我有一个想要存储为 PDF 的画布。我正在通过以下方式创建画布:
from tkinter import *
root = Tk()
root.geometry('1920x1200')
canvas = Canvas(master=root, width=1920, height=1200, bg='white')
canvas.place(x=0, y=0)
canvas.pack(expand=YES, fill=BOTH)
image = ImageTk.PhotoImage(file=picture_path)
canvas.create_image(0, 0, image=image, anchor=NW)
canvas.bind("<Button-1>", getorigin)
canvas.after(10000, add_line, canvas)
root.mainloop()
使用 create_image 我只是为画布设置背景图像。add_line 方法在画布(create_line)中绘制一些东西。绘图完成后,我尝试通过以下方式创建 PDF:
canvas.update()
canvas.postscript(file="tmp.ps", colormode="color")
process = subprocess.Popen(["ps2pdf", "tmp.ps", "result.pdf"], shell=True)
process.wait()
os.remove("tmp.ps")
PDF 已成功创建,但仅捕获了画布的一部分。看起来画布存储在 1200x1920 而不是 1920x1200 中。
我该如何解决?
解决方案
推荐阅读
- r - 根据最短字符串的长度修改列表
- c - 如何使用堆栈从函数返回值
- python - python中的时间比较,如果它是str格式
- java - 空值存储mysql
- jquery - 如何解决我的提交按钮问题,我无法移动到下一页
- python - 如何在python pandas中的数据框列中查找整数范围内的值的数量
- react-native - React Native/是否有任何 Npm 用于拖放匹配组件?
- entity-framework-core - 在 Entity Framework Core 中检测延迟加载
- jquery - 在 HTML 属性 Kendo UI 上编辑模板绑定
- c# - 如何使用 WPF 在列表视图上水平显示项目列表?