-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
40 lines (33 loc) · 1.24 KB
/
test.py
File metadata and controls
40 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import subprocess
import winreg
import win32print
import printergui
# Show all the printers
def getAllPrinters():
printers = win32print.EnumPrinters(2)
output = tuple(zip(*printers))[2]
return output
def generatePrint(filename):
# get printerName from the list
printerName = printergui.Ui_MainWindow.getPrinterName()
if (printerName == None):
return
print(printerName)
baseGS = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\GPL Ghostscript")
version = winreg.EnumKey(baseGS, 0)
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\GPL Ghostscript\\{0}".format(version))
gsFolder, _ = winreg.QueryValueEx(key, "GS_DLL")
gspath = os.path.dirname(gsFolder)
args = '"{0}\gswin64c" ' \
'-sDEVICE=mswinpr2 ' \
'-dBATCH ' \
'-dNOPAUSE ' \
'-dFitPage ' \
'-sOutputFile="%printer%{1}" '.format(gspath ,printerName)
ghostscript = args + os.path.join(os.getcwd(), '{0}.ps'.format(filename))
ghostscript = ghostscript.replace('\\', '\\\\')
p = subprocess.Popen(ghostscript, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
print(stdout, stderr, sep="\n")