我正在寻找一个python库,我可以用它来绘制简单的形状和字符,然后保存到一个文件(格式可转换为pdf).如果我不需要运行X-server,我更愿意.
例如,看起来像这样
import drawing_lib
obj = drawing_lib.Object()
for i in range(5):
obj.draw_line(from=(i*10, 20), to=(i*10+10, 35))
obj.save_pdf('five_inclined_lines.pdf')
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
你可以用cairo做到这一点.
import math,cairo
width, height = 768,768
surface = cairo.PDFSurface ("circle.pdf", width, height)
ctx = cairo.Context (surface)
ctx.set_source_rgb(1,1,1)
ctx.rectangle(0,0,width,height)
ctx.fill()
ctx.set_source_rgb(1,0,0)
ctx.move_to(width/2,height/2)
ctx.arc(width/2,height/2,512*0.25,0,math.pi*2)
ctx.fill()
ctx.show_page()
Run Code Online (Sandbox Code Playgroud)
也可以看看:
| 归档时间: |
|
| 查看次数: |
6994 次 |
| 最近记录: |