用Python打印图形

我需要从python中打印“Wheel Tags”.车轮标签将包含图像,线条和文字.

Python教程有两段关于使用图像lib创建postscript文件.看完之后我还是不知道如何布局数据.我希望有人可能有如何布局图像,文字和线条的样本?

谢谢你的帮助.

最佳答案
http://effbot.org/imagingbook/psdraw.htm

注意:

>自2005年以来,PSDraw模块似乎没有得到积极维护;我猜大多数努力都被重定向支持PDF格式.你可能会更喜欢使用pypdf;
>它在源代码中有’#FIXME:不完整’和’NOT YET IMPLEMENTED’之类的评论
>它似乎没有任何设置页面大小的方法 – 我记得它认为A4(8.26 x 11.69英寸)
>所有测量均以点为单位,每英寸72点.

您将需要执行以下操作:

import Image
import PSDraw

# fns for measurement conversion    
PTS = lambda x:  1.00 * x    # points
INS = lambda x: 72.00 * x    # inches-to-points
CMS = lambda x: 28.35 * x    # centimeters-to-points

outputFile = 'myfilename.ps'
outputFileTitle = 'Wheel Tag 36147'

myf = open(outputFile,'w')
ps = PSDraw.PSDraw(myf)
ps.begin_document(outputFileTitle)

ps现在是一个PSDraw对象,它将PostScript写入指定的文件,并且已经编写了文档标题 – 您已准备好开始绘制内容.

添加图像:

im = Image.open("myimage.jpg")
Box = (        # bounding-Box for positioning on page
    INS(1),# left
    INS(1),# top
    INS(3),# right
    INS(3)     # bottom
)
dpi = 300      # desired on-page resolution
ps.image(Box,im,dpi)

添加文字

ps.setfont("Helvetica",PTS(12))  # PostScript fonts only -
                                  # must be one which your printer has available
loc = (        # where to put the text?
    INS(1),# horizontal value - I do not kNow whether it is left- or middle-aligned
    INS(3.25)  # vertical value   - I do not kNow whether it is top- or bottom-aligned
)
ps.text(loc,"Here is some text")

添加一行:

lineFrom = ( INS(4),INS(1) )
lineto   = ( INS(4),INS(9) )
ps.line( lineFrom,lineto )

……我没有看到任何改变中风重量的选择.

完成后,您必须关闭文件,如:

ps.end_document()
myf.close()

编辑:我正在做一些关于设置笔触权重的阅读,我遇到了一个不同的模块,psfile:http://seehuhn.de/pages/psfile#sec:2.0.0模块本身看起来很小 – 他正在写很多原始的后记 – 但它应该让你更好地了解什么是在幕后进行.

相关文章

我最近重新拾起了计算机视觉,借助Python的opencv还有face_r...
说到Pooling,相信学习过CNN的朋友们都不会感到陌生。Poolin...
记得大一学Python的时候,有一个题目是判断一个数是否是复数...
文章目录 3 直方图Histogramplot1. 基本直方图的绘制 Basic ...
文章目录 5 小提琴图Violinplot1. 基础小提琴图绘制 Basic v...
文章目录 4 核密度图Densityplot1. 基础核密度图绘制 Basic ...