print PDF on windows

63 views
Skip to first unread message

mettwoch

unread,
Aug 25, 2009, 11:38:33 AM8/25/09
to Django users
How do the Django people handle printing directly on Windows? I
remembered about http://timgolden.me.uk/python/win32_how_do_i/print.html,
but unfortunately his method for PDFs only print on the default
printer. I need the server to produce the PDF, save it (works already)
and send it to a specific shared printer on the network. The printer
should be determined from a table that holds 'host' - 'printer' pairs
e.g. ('PC01', '\\PC01\PR01'). The host ('PC01') determined from the
http request allows to choose the right printer ('\\PC01\PR01') from
that table.

Printing should be executed directly when the user has submitted the
request. Any solution that pops up the document locally in a PDFReader
and where the user has to hit the print button is not viable.

Kindly Yours
Marc

Peter Bengtsson

unread,
Aug 25, 2009, 12:16:45 PM8/25/09
to Django users
Suppose you have a PDF (generated or downloaded from the internet),
are you able to get it printed by scripting?

On Aug 25, 4:38 pm, mettwoch <mettw...@pt.lu> wrote:
> How do the Django people handle printing directly on Windows? I
> remembered abouthttp://timgolden.me.uk/python/win32_how_do_i/print.html,

Sam Lai

unread,
Aug 25, 2009, 7:46:22 PM8/25/09
to django...@googlegroups.com
Use python to call a PDF reader via the command line -

http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm

http://foxit.vo.llnwd.net/o28/pub/foxit/manual/enu/FoxitReader30_Manual.pdf
(see the Command Line section)

Depending on the complexity of your PDFs, I'd recommend using Foxit
instead; Adobe Reader on windows isn't the most stable especially when
it comes to open many PDFs - you might have to manually manage
instances to make sure it doesn't eat up all your memory. Foxit Reader
however doesn't render all PDFs perfectly, or at least the same way
that Adobe Reader does. YMMV though.

2009/8/26 mettwoch <mett...@pt.lu>:

mettwoch

unread,
Aug 26, 2009, 12:24:00 PM8/26/09
to Django users
I'm now using Foxit Reader. Thanks for the tip. The following works
perfectly in the Django shell and prints the document in
attachment.file.path to the specified network printer:

p = Popen (['C:\\Program Files\\Foxit Software\\Foxit Reader\\Foxit
Reader.exe',
'/t',
attachment.file.path,
'\\\\SM03\\HPCOMPTOIR0'])

The same code works silently in a Apache / mod_wsgi context but does
not produce any result on the printer. Do You have any ideas?

Marc

On Aug 26, 1:46 am, Sam Lai <samuel....@gmail.com> wrote:
> Use python to call a PDF reader via the command line -
>
> http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm
>
> http://foxit.vo.llnwd.net/o28/pub/foxit/manual/enu/FoxitReader30_Manu...
> (see the Command Line section)
>
> Depending on the complexity of your PDFs, I'd recommend using Foxit
> instead; Adobe Reader on windows isn't the most stable especially when
> it comes to open many PDFs - you might have to manually manage
> instances to make sure it doesn't eat up all your memory. Foxit Reader
> however doesn't render all PDFs perfectly, or at least the same way
> that Adobe Reader does. YMMV though.
>
> 2009/8/26 mettwoch <mettw...@pt.lu>:
>
>
>
> > How do the Django people handle printing directly on Windows? I
> > remembered abouthttp://timgolden.me.uk/python/win32_how_do_i/print.html,

Sam Lai

unread,
Aug 26, 2009, 8:42:56 PM8/26/09
to django...@googlegroups.com
2009/8/27 mettwoch <mett...@pt.lu>:
>
> I'm now using Foxit Reader. Thanks for the tip. The following works
> perfectly in the Django shell and prints the document in
> attachment.file.path to the specified network printer:
>
> p = Popen (['C:\\Program Files\\Foxit Software\\Foxit Reader\\Foxit
> Reader.exe',
>        '/t',
>        attachment.file.path,
>        '\\\\SM03\\HPCOMPTOIR0'])
>
> The same code works silently in a Apache / mod_wsgi context but does
> not produce any result on the printer. Do You have any ideas?

Could be a permissions issue - what user is apache running under?

Also, you might want to try enabling the 'allow service to interact
with desktop' option to see if that works. If it does, you might have
to look at another solution or somehow impersonating another user to
do the printing as there are security risks associated with this
option.

mettwoch

unread,
Aug 27, 2009, 3:36:39 AM8/27/09
to Django users
Apache is running under a system account. A quick test of running
Apache under my user account enabled printing indeed. I'll follow your
suggestion and create a dedicated user with restricted rights to run
Apache under.

Thanks so much for your help

Marc

On Aug 27, 2:42 am, Sam Lai <samuel....@gmail.com> wrote:
> 2009/8/27 mettwoch <mettw...@pt.lu>:

Sam Lai

unread,
Aug 28, 2009, 7:41:15 AM8/28/09
to django...@googlegroups.com
2009/8/27 mettwoch <mett...@pt.lu>:
>
> Apache is running under a system account. A quick test of running
> Apache under my user account enabled printing indeed. I'll follow your
> suggestion and create a dedicated user with restricted rights to run
> Apache under.

I'd leave Apache running under the system account - that's how it is
by default, and I would think that there are good reasons for it.

Try using python to impersonate another user to launch foxit/adobe
reader in another user account context, or the easier way is to
leverage the 'runas' command to run an app under another user account.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true
Reply all
Reply to author
Forward
0 new messages