Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Printing an svg from withing PyQt5

Printing an svg from withing PyQt5

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 1 Posters 797 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DieterV
    wrote on last edited by
    #1

    Hi,

    I'm working on a system that scans barcodes on invitations at events and prints out the badges for the attendees.
    For my first version, I generated pdf's and printed those (the badge printer shows up as a regular printer). That worked under Linux, but under Windows, libcairo wasn't avaiable. I worked my way around using poppler that but it wasn't pretty.

    Now I'd need more flexibility in generating content (I'd need boxes with/without ticks and such) and I'd like to avoid pdf altogether.

    SVG seemed like a good format, using svgwrite. However, I can't seem to figure out how to send those to the printer.

    printer = QPrinter(QPrinter.HighResolution)
            printer.setOrientation(QPrinter.Landscape)
            printer.setPageSizeMM(QSizeF(54.19, 85.2))
    

    Sets up the printer correctly (it worked for the pdf).
    Then I would do:

    painter = QPainter()
    painter.begin(printer)
    

    To start "writing" to the printer and end with

    painter.end()
    

    In between that, I'm lost and I can't seem to find how to do it (so 2 svg files for front/back and being deployable on Linux and Windows).

    Does anyone have any pointers?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DieterV
      wrote on last edited by
      #2

      In case anyone comes looking with the same question, I managed to get it working using two pre-created svg files (test1.svg and test2.svg):

              printer = QPrinter(QPrinter.HighResolution)
              printer.setOrientation(QPrinter.Landscape)
              printer.setPageSizeMM(QSizeF(54.19, 85.2))
      
              painter = QPainter()
              painter.begin(printer)
              rend = QSvgRenderer('test1.svg')
              rend.render(painter)
              printer.newPage()
              rend = QSvgRenderer('test2.svg')
              rend.render(painter)
      
              painter.end()
      

      Keep in mind that this does not show the print dialog box but directly prints to the default printer with the default settings.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved