4

Using python, wxpython and sqlite in a windows system. I'm trying to print some certificates/diplomas/cards with an image in the background and the name of person/text over it.

I know the basic steps to print the text using win32print from Pywin32 but:

  1. I dont know how to add an image and set it to background.

    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()
    

    This printer-code is inside a while loop calling each people name from a sqlite database per check condition.

  2. All the names of database was printed at same page. How do I command the printer to spit out 1 page per name from the database?

  3. A simpler approach or module to deal with printers (paper and/or pdf) will be welcome.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Martha Morrigan
  • 109
  • 1
  • 7

2 Answers2

2

I think it can be feasable with WxPython, but I do not know enough to help you.

However, you can try to take a look into Python Image Library :

Example code :

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")

and the result :

enter image description here

lucasg
  • 10,734
  • 4
  • 35
  • 57
  • Humm... i see now how to put a text over a image. But how to send it to the default printer? And how to improve the resolution/quality? – Martha Morrigan Nov 08 '12 at 11:27
0

I suggest you instead use reportlab to create a PDF and then send that PDF to a printer using gsprint.

See this answer: https://stackoverflow.com/a/4498956/3571

Community
  • 1
  • 1
codeape
  • 97,830
  • 24
  • 159
  • 188
  • Sorry. No... I dont want or think I need use any external EXE file for that. If was the case is simple just set as default printer a virtual pdfprinter like primopdf or any other. – Martha Morrigan Nov 08 '12 at 12:20