How To Stop Wkhtmltopdf.exe Pop-up While Running It With Python
I am using wkhtmltopdf.exe for converting html to pdf using python. The pop-up window of wkhtmltopdf.exe making it very difficult for me to work on any other things while running i
Solution 1:
So I solved the problem! made my python file executable using py2exe and used the .py file.
http://www.py2exe.org/index.cgi/Tutorial
It is no more popping the command prompt window.
Solution 2:
- Use pythonw.exeto start your script (works with.pyand.pywextensions)
- or use .pywextension for your your script (works withpython.exeandpythonw.exe)
In the second case make sure the .pyw extension is handled by pythonw.exe (right click your .pyw script > Open With and make sure pythonw.exe is the default handler for .pyw files).
edit
You can also pass the CREATE_NO_WINDOW flag to the creationflags argument if you use subprocess.Popen to start your executable. This flag is a flag that can be passed to the Win32 CreateProcess API and is documented here.
Here's an example that doesn't create any console on my computer (make sure to name it with a .pyw extension) :
#!/usr/local/bin/python3
# -*- coding: utf8 -*-
import subprocess
import urllib.parse as urlparse # import urlparse for python 2.x
CREATE_NO_WINDOW = 0x08000000 # do not create a new window !
def is_url(url):
    parts = urlparse.urlsplit(url)  
    return parts.scheme and parts.netloc
def main(url, output):
    print(url, output)
    if not is_url(url):
        return -1
    proc = subprocess.Popen(["wkhtmltopdf.exe", url, output],
        creationflags=CREATE_NO_WINDOW)
    proc.wait()
    return proc.returncode
if __name__ == "__main__":
    url = "https://www.example.com"
    output = r"c:\tmp\example.pdf"
    rval = main(url, output)
    sys.exit(rval)
Post a Comment for "How To Stop Wkhtmltopdf.exe Pop-up While Running It With Python"