[python-win32] Print PDF

Gerdus van Zyl gerdusvanzyl at gmail.com
Sun Feb 3 16:19:14 CET 2008


Thanks the SumatraPDF link is very useful. The following code is what
I came up with and is based on this msg:
http://two.pairlist.net/pipermail/reportlab-users/2003-February/001260.html

import win32ui
import dde
from win32api import FindExecutable
import os.path
from os import spawnl,P_NOWAIT,startfile
import time

pd = "C:/uxpython/fun/godsdebris.pdf"
pdbits = os.path.split(pd)
readerexe = FindExecutable(pdbits[1],pdbits[0])

spawnl(P_NOWAIT,readerexe[1])

time.sleep(2)

s = dde.CreateServer()
s.Create('')

c = dde.CreateConversation(s)

c.ConnectTo('acroview', 'control')

# driverName is optional (I think)
#c.Exec('[FilePrintTo("%s", "%s", "%s", "%s")]' % (filename, printerName,
#driverName, portName))

c.Exec('[DocOpen("%s")]' % (pd,))
#c.Exec('[FilePrint("%s")]' % (pd,))
#c.Exec('[FilePrintSilent("%s")]' % (pd,))

s.Destroy()

With the above you can open,print,print silent a PDF. I leave it as an
exercise to the reader to make the reader window hidden instead if so
desired.


~Gerdus van zyl

On Feb 3, 2008 1:29 AM, Michel Claveau <mc at mclaveau.com> wrote:
> Hi!
>
>
> Perso, I use Adobe-Reader AND SumatraPDF.
> And, SumatraPDF has command-line options for print directly a file.
> See : http://blog.kowalczyk.info/software/sumatrapdf/manual.html
>
>
> In Python, you can use system, popen, subprocess, etc.
>
>
> @-salutation
>
> Michel Claveau
>
>
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>


More information about the python-win32 mailing list