Send text to printer over image in python

Using python, wxpython and sqlite on a windows system. I am trying to print several certificates / diplomas / cards with the image in the background and the name of the person / text above it.

I know the basic steps for printing text using win32print from Pywin32, but:

  • I do not know how to add an image and set it in the 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 the while loop, which calls the name of each user from the sqlite database for each validation condition.

  • All database names were printed on one page. How do I make the printer pop 1 page per name from the database?

  • A simpler approach or module for working with printers (paper and / or pdf) would be welcome.

+4
source share
2 answers

I think this is possible with WxPython, but I don’t know enough to help you.

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

Code example:

 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

+2
source

I suggest you create a PDF file instead of reportlab , and then send this PDF document to the printer using gsprint.

See this answer: fooobar.com/questions/469002 / ...

0
source

Source: https://habr.com/ru/post/1444766/


All Articles