Search code examples
pythoncmdexewkhtmltopdfpython-pdfkit

Package pdfkit opening windows cmd window during execution


I have a "strange" question. This is my working python code, it creates a PDF and writes a string on it.

import pdfkit
pdf_name = "abc.pdf"
path_wkhtmltopdf = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
res="string"
pdfkit.from_string(res, pdf_name, configuration=config)

The problem is that in some computers, during the execution of this code, appears a blank screen (cmd window), named wkhtmlpdf.exe, like the path in the code. This cmd window appears for 1-2 seconds, and after that, the PDF is created, with the string on it. On my computer, this is not happening, but in another one, with the same spec (i7 and good video card) it happens. How can I get rid of this (is annoying to see..)? Thank you! Screenshot


Solution

  • Looking at the code for the python-pdfkit package, they use Subprocess.Popen(), which can be given arguments to hide the cmd prompt, see: How do I hide the console when I use os.system() or subprocess.call()? and Executing subprocess from Python without opening Windows Command Prompt [duplicate]. You will want to either modify the source code yourself, or maybe ask the package maintainer(s) at their github page.