Python print pdf file with win32print
<p>I'm trying to print a pdf file from python with module win32print but the only way i can print success is a text.</p>

<pre><code>hPrinter = win32print.OpenPrinter("\\\\Server\Printer")
    filename = "test.pdf"
    try:
        hJob = win32print.StartDocPrinter(hPrinter, 1, ('PrintJobName',None,'RAW'))
        try:
            win32api.ShellExecute(0, "print", filename, None,  ".",  0)
            win32print.StartPagePrinter(hPrinter)
            win32print.WritePrinter(hPrinter, "test") #Instead of raw text is there a way to print PDF File ?
            win32print.EndPagePrinter(hPrinter)
        finally:
            win32print.EndDocPrinter(hPrinter)
    finally:
        win32print.ClosePrinter(hPrinter)
</code></pre>

<p>So instead of printing a text i need to print the "test.pdf" file.</p>

<p>I also tried with <strong><code>win32api.ShellExecute(0, "print", filename, None,  ".",  0)</code></strong> but is not working, after some test like (getprinter, getdefault, setprinter, setdefaultprinter) it seems not to be attaching the printer. So at this way i can't get working.</p>

<p>This is the code i used !</p>

<pre><code>win32print.SetDefaultPrinter(hPrinter)
win32api.ShellExecute(0, "print", filename, None,  ".",  0)
</code></pre>

<p>You can try</p>

<pre><code>win32print.SetDefaultPrinter("\\\\Server\Printer")
</code></pre>

<p>This method accepts a String, not the printer object you tried to pass it.</p>

python pdf printing