我需要帮助了解如何正确地将PDF打印到贴纸/标签打印机。 虽然每行有多个标签的打印机不能按预期工作,但每页一个标签打印机目前工作正常。 以下是生成PDF文件的代码:
from PIL import Image
import PyPDF2
img = Image.open('somelabelimage.png', 'r') # load the image
# calculate pixels from mm
def gpm(mm):
return round((72 * mm) / 25.4)
img = img.resize(
(
gpm(15)*10,gpm(5)*10 # 15mm X 5mm
),
Image.LANCZOS
)
img_w, img_h = img.size
# create empty new PIL.Image
pivot = Image.new('RGB', ( 4*(img_w+ (gpm(4)*10))-(gpm(4)*10), img_h), (255, 255, 255))
x = 0
# here we paste each label-image onto the new surface
for y in range(4):
pivot.paste(img,(x,0))
x += img_w + (gpm(4)*10) # 4 mm offset increased by factor 10
# save the image as pdf
pivot.save("new.pdf",resolution=200)
# code below resizes the pdf file to fit the mm specs
pr = PyPDF2.PdfFileReader(open('new.pdf','rb'))
pw = PyPDF2.PdfFileWriter()
def mti(mm):
return mm / 25.4
page = pr.getPage(0)
page.scaleTo(mti(15)*72*4,mti(5)*72)
pw.addPage(page)
pw.write(open("resized.pdf",'wb'))
这就是我实际打印的方式:
import subprocess
# pdftopriter.exe is an exe that lets me print to printers. Here is the link to theri page : # http://www.columbia.edu/~em36/pdftoprinter.html
command = [
"session/PDFtoPrinter.exe", "storage/storage_export.pdf",
self.printer if self.printer is not None else "None"
]
subprocess.Popen(command)
正如你所看到的,这项印刷工作已经完成了。但我想不出如何修复/调整它
目前没有回答
相关问题 更多 >
编程相关推荐