2012-11-08 45 views
4

在Windows系统中使用python,wxpython和sqlite。我试图在背景中打印一些带有图像的证书/文凭/卡片以及其上的人物/文字的名称。发送给打印机python中的图像上的文本

我知道的基本步骤使用win32print从Pywin32打印文本,但:

  1. 我不知道如何添加图像并将其设置为背景。

    while ..... 
    
        ..... 
    
        # Query sqlite rows and collumn name and set the self.text for each certificate 
    
        ..... 
    
        # Now send to printer 
    
        DC = win32ui.CreateDC() 
        DC.CreatePrinterDC(win32print.GetDefaultPrinter()) 
    
        DC.SetMapMode(win32con.MM_TWIPS) 
    
        DC.StartDoc("Certificates Job") 
    
        DC.StartPage() 
    
        ux = 1000 
        uy = -1000 
        lx = 5500 
        ly = -55000 
    
        DC.DrawText(self.text, (ux, uy, lx, ly),win32con.DT_LEFT) 
    
        DC.EndPage() 
        DC.EndDoc() 
    

    这个打印机代码是在一个while循环内调用sqlite数据库每个检查条件的每个人的名字。

  2. 数据库的所有名称都打印在同一页上。如何命令打印机从数据库中为每个名称吐出1页?

  3. 一个更简单的方法或模块来处理打印机(纸和/或pdf)将受到欢迎。

回答

2

我认为这对WxPython是可行的,但我不知道足以帮助你。

但是,你可以尝试看看到Python Image Library

示例代码:

import sys 
from PIL import Image,ImageDraw 

txt = 'C\'est mon texte!' 
txt2 = '??,??!' 


im = Image.new("RGBA",(300,200),(100,155,100)) 

draw = ImageDraw.Draw(im) 

draw.text((0,50), txt) 
draw.text((0,100), txt2) 
del draw 

im.save('font.png', "PNG") 

和结果:

enter image description here

+0

赫姆...我看到现在如何把一个文本在图像。但如何将其发送到默认打印机?以及如何提高分辨率/质量? –

0

我建议你改用reportlab来创建PDF,然后使用gsprint将该PDF发送到打印机。

看到这个答案:https://stackoverflow.com/a/4498956/3571

+0

对不起。不......我不想或不认为我需要使用任何外部EXE文件。如果情况很简单,只需将默认打印机设置为primopdf或其他任何虚拟pdfprinter即可。 –

相关问题