Printing a text over an image

Discussion in 'Python' started by Martha Morrigan, Nov 7, 2012.

  1. Hi guys,

    Using python, wxpython and sqlite in a windows system, Im trying to
    print some certificates/diplomas/cards with a image at background with
    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 i command
    the printer to spit out 1 page per name from the database?


    3) Any more simple approach or module to deals with printers (paper
    and/or pdf) will be welcome.

    Thanks in advance,

    Martha
    Martha Morrigan, Nov 7, 2012
    #1
    1. Advertising

  2. Martha Morrigan wrote:

    >
    > 3) Any more simple approach or module to deals with printers (paper
    > and/or pdf) will be welcome.


    For pdf, you can take a look at ReportLab's Toolkit. I used it to build a
    "trombinoscope" (ie an employee directory with each member's photo on top of
    his name and room number).

    http://www.reportlab.com/software/opensource/

    Once created the pdf, you must find a solution to send it to the printer...

    >
    > Thanks in advance,
    >
    > Martha


    A+
    Laurent.
    Laurent Pointal, Nov 7, 2012
    #2
    1. Advertising

  3. Martha Morrigan

    Marco Nawijn Guest

    On Wednesday, November 7, 2012 5:52:36 PM UTC+1, Martha Morrigan wrote:
    > Hi guys,
    >
    >
    >
    > Using python, wxpython and sqlite in a windows system, Im trying to
    >
    > print some certificates/diplomas/cards with a image at background with
    >
    > 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 i command
    >
    > the printer to spit out 1 page per name from the database?
    >
    >
    >
    >
    >
    > 3) Any more simple approach or module to deals with printers (paper
    >
    > and/or pdf) will be welcome.
    >
    >
    >
    > Thanks in advance,
    >
    >
    >
    > Martha


    Hi Martha,

    Since you are on windows, why don't you use MS/Word directly from Python. It has all the abstractions you need (documents, pages, tables, figures, printing etc.). Working with MS/Word through the win32 bindings is really simple.
    I have done this a while ago for some automatic report generation. The basic routine is to start recording your actions with the MS/Word macro recorder, do the things you want to do, stop recording, look at the VB code and guess the equivalent Python code. This is not as bad as it sounds. It normally is really straightforward.

    I am on Linux at the moment, so I cannot present any code examples. Feel free to try and post some example code if you get stuck.

    Marco
    Marco Nawijn, Nov 15, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Varangian

    Check Image is over another Image

    Varangian, Mar 31, 2006, in forum: ASP .Net
    Replies:
    9
    Views:
    366
    Varangian
    Apr 5, 2006
  2. Phillip Roncoroni
    Replies:
    6
    Views:
    6,187
  3. Greg N.
    Replies:
    9
    Views:
    572
    Roy Schestowitz
    Jul 29, 2005
  4. Replies:
    0
    Views:
    79
  5. Replies:
    5
    Views:
    137
Loading...

Share This Page