Python Forum
Trying to send file to printer with no results.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to send file to printer with no results.
#3
Most printers can handle pdfs no trouble I think.

Why don't you make a pdf, then print that? Quick and easy!!

Also, if they are not throwaway barcodes, you can print them again and again!

#! /usr/bin/python3
from reportlab.pdfgen import canvas # need this here
from reportlab.lib.pagesizes import A4  # need this here
from reportlab.pdfbase.ttfonts import TTFont # need this here
from reportlab.pdfbase import pdfmetrics # need this here
from reportlab.lib.units import mm
import glob
# to help you locate objects on the page
# a reportlab page is in points of 1/72nd inch
print('1mm is', mm, 'page points')
# 2.834645669291339
# the sizes in points of an A4 page
print('An A4 page is', A4, 'width by height in points.')
fontpath = '/home/pedro/.local/share/fonts/'
path2pdf = '/home/pedro/pdfs/'
path2QRcodes = '/home/pedro/temp/QRcodes/'
mypdf = 'mysizePDF.pdf'

# this is the name of the pdf window
title = 'A custom size pdf'
# for Chinese
ttfFile = os.path.join(fontpath, 'DroidSansFallbackFull.ttf')
pdfmetrics.registerFont(TTFont("Droid", ttfFile))

qrcodes = glob.glob(path2QRcodes + '*.png')
# insert the QR code
def putQRcode(qrcode, myCanvas):    
    # put the qr code on the page    
    myCanvas.drawImage(qrcode, 350, 350, 100, 100, mask='auto')    
    return myCanvas

# bottom left corner is x=0, y=0
# c.showPage() puts a page break
# set any custom pagesize with pagesize(x, y)
def makePDF():
    c = canvas.Canvas(path2pdf + mypdf, pagesize=(500, 500))
    c.setTitle(title)
    # for Chinese
    #c.setFont('Droid', 18)
    c.setFont('Times-Roman', 14)
    for q in qrcodes:    
        c.drawString(50, 400, "Welcome to Reportlab!")
        c.drawString(50, 380, "This is my custom pdf size")
        c = putQRcode(q, c) 
        c.showPage()    
    c.save()

if __name__ == '__main__':
    makePDF()
Gribouillis and chob_thomas like this post
Reply


Messages In This Thread
RE: Trying to send file to printer with no results. - by Pedroski55 - Dec-21-2022, 07:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating sharepoint excel file odd results cubangt 1 963 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,506 Sep-27-2022, 01:38 PM
Last Post: buran
  How do you marshal the default printer setup to print? hammer 0 1,323 May-29-2022, 02:54 PM
Last Post: hammer
  Can you print a string variable to printer hammer 2 2,038 Apr-30-2022, 11:48 PM
Last Post: hammer
  [split] Results of this program in an excel file eisamabodian 1 1,641 Feb-11-2022, 03:18 PM
Last Post: snippsat
  How to save some results in .txt file with Python? Melcu54 4 7,504 May-26-2021, 08:15 AM
Last Post: snippsat
  Running A Parser In VSCode - And Write The Results Into A Csv-File apollo 5 4,804 Jan-14-2021, 08:58 PM
Last Post: snippsat
  Writing unit test results into a text file ateestructural 3 4,895 Nov-15-2020, 05:41 PM
Last Post: ateestructural
  capture pytest results to a file maiya 2 5,954 Oct-17-2020, 03:42 AM
Last Post: maiya
  Printing to a printer connected to pi 4 alan 2 2,552 Oct-04-2020, 10:08 PM
Last Post: alan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020