FAQ
hello all,
I am stuck with a strange requirement.
I need a library that can help me display a pdf file as a report and
also want a way to print the same pdf file in a platform independent
way.
if that's not possible then I at least need the code for useing some
library for connecting to acrobat reader and giving the print command
on windows and some thing similar on ubuntu linux.
the problem is that I want to display reports in my application. the
user should be able to view the formatted report on screen and at his
choice click the print button on the screen to send it to the printer.
I have reportlab installed and that is sufficient to generate pdf reports.
but I still can't fine the way to display it directly and print it directly.
Please help me.
Krishnakant.

Search Discussions

  • Vishal Bhargava at Feb 11, 2007 at 6:47 am
    Use Report Lab...
    Cheers,
    Vishal

    -----Original Message-----
    From: python-list-bounces+vishal=veriwave.com at python.org
    [mailto:python-list-bounces+vishal=veriwave.com at python.org] On Behalf Of
    krishnakant Mane
    Sent: Saturday, February 10, 2007 10:46 PM
    To: python-list at python.org
    Subject: can't find a way to display and print pdf through python.

    hello all,
    I am stuck with a strange requirement.
    I need a library that can help me display a pdf file as a report and
    also want a way to print the same pdf file in a platform independent
    way.
    if that's not possible then I at least need the code for useing some
    library for connecting to acrobat reader and giving the print command
    on windows and some thing similar on ubuntu linux.
    the problem is that I want to display reports in my application. the
    user should be able to view the formatted report on screen and at his
    choice click the print button on the screen to send it to the printer.
    I have reportlab installed and that is sufficient to generate pdf reports.
    but I still can't fine the way to display it directly and print it directly.
    Please help me.
    Krishnakant.
  • krishnakant Mane at Feb 11, 2007 at 6:49 am

    On 11/02/07, Vishal Bhargava wrote:
    Use Report Lab...
    I mentioned in my first email that I am already using reportlab.
    but I can only generate pdf out of that.
    I want to display it on screen and I also will be giving a print
    button which should do the printing job.
    by the way I use wxpython for gui.
    Krishnakant.
  • Vishal Bhargava at Feb 11, 2007 at 7:06 am
    Are you trying to do real time or post real time.
    -Vishal

    -----Original Message-----
    From: krishnakant Mane [mailto:researchbase at gmail.com]
    Sent: Saturday, February 10, 2007 10:50 PM
    To: Vishal Bhargava
    Cc: python-list at python.org
    Subject: Re: can't find a way to display and print pdf through python.
    On 11/02/07, Vishal Bhargava wrote:
    Use Report Lab...
    I mentioned in my first email that I am already using reportlab.
    but I can only generate pdf out of that.
    I want to display it on screen and I also will be giving a print
    button which should do the printing job.
    by the way I use wxpython for gui.
    Krishnakant.
  • krishnakant Mane at Feb 11, 2007 at 7:23 am

    On 11/02/07, Vishal Bhargava wrote:
    Are you trying to do real time or post real time.
    -Vishal
    post real time.
    I want to first display the report on screen by default and the user
    at his choice will click the print button and the report will be
    printed.
    regards.
    Krishnakant.
  • Christian Stapfer at Feb 11, 2007 at 4:24 pm
    krishnakant Mane wrote in message
    news:mailman.3852.1171176596.32031.python-list at python.org...
    On 11/02/07, Vishal Bhargava wrote:
    Use Report Lab...
    I mentioned in my first email that I am already using reportlab.
    but I can only generate pdf out of that.
    I want to display it on screen and I also will be giving a print
    button which should do the printing job.
    by the way I use wxpython for gui.
    Under Windows you could do it by embedding Adobe's
    ActiveX control in your application. Don't know
    about Linux, though. Perhaps you could just convert
    your PDF to a raster image for display (eg. by
    using ImageMagick's convert) under Linux?

    Regards,
    Christian
  • Geoff Hill at Feb 11, 2007 at 7:51 am
    Are you trying to:
    a) Make the PDF file open in it's default application?
    b) Create a PDF-reader in Python?

    ...because your question is somewhat unclear. Report Lab has no PDF viewer.
    You would need a PDF/PostScript parser to do that and that's more of a job
    than I think you're looking for.
  • krishnakant Mane at Feb 11, 2007 at 5:37 pm
    well yes,
    I need to view reports on line and also print them from within my app.
    so yes I need to display the pdf in my app and print it as well.
    regards.
    Krishnakant

    From http Sun Feb 11 18:43:53 2007
    From: http (Paul Rubin)
    Date: 11 Feb 2007 09:43:53 -0800
    Subject: randomly generate n of each of two types
    References: <KdIzh.10199$Yn4.6813@trnddc03>
    Message-ID: <7x64a8vbc6.fsf@ruckus.brouhaha.com>

    "Alan Isaac" <aisaac at american.edu> writes:
    I need access to 2*n random choices for two types
    subject to a constraint that in the end I have
    drawn n of each. I first tried::
    You mean you basically want to generate 2*n bools of which exactly
    half are True and half are False? Hmm (untested):

    from random import random
    def random_types(n):
    total = 2*n
    trues_needed = n
    for i in xrange(total):
    if random() < float(trues_needed) / float(total):
    trues_needed -= 1
    yield True
    else:
    yield False
    total -= 1
  • Larry Bates at Feb 12, 2007 at 3:56 pm

    krishnakant Mane wrote:
    hello all,
    I am stuck with a strange requirement.
    I need a library that can help me display a pdf file as a report and
    also want a way to print the same pdf file in a platform independent
    way.
    if that's not possible then I at least need the code for useing some
    library for connecting to acrobat reader and giving the print command
    on windows and some thing similar on ubuntu linux.
    the problem is that I want to display reports in my application. the
    user should be able to view the formatted report on screen and at his
    choice click the print button on the screen to send it to the printer.
    I have reportlab installed and that is sufficient to generate pdf reports.
    but I still can't fine the way to display it directly and print it
    directly.
    Please help me.
    Krishnakant.
    Just let the registered .PDF viewer do it for you.

    os.start('myfile.pdf')

    Launches whatever is registered as .PDF viewer and user
    can then print, save, zoom, etc. on their own.

    -Larry
  • Grant Edwards at Feb 12, 2007 at 5:04 pm

    On 2007-02-12, Larry Bates wrote:

    I at least need the code for useing some library for
    connecting to acrobat reader and giving the print command on
    windows and some thing similar on ubuntu linux.
    Just let the registered .PDF viewer do it for you.

    os.start('myfile.pdf')
    Eh? I don't see os.start() it either 2.5 or 2.44
    documentation, and it's sure not there in 2.4.3:

    $ python
    Python 2.4.3 (#1, Dec 10 2006, 22:09:09)
    [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
    Type "help", "copyright", "credits" or "license" for more
    information.
    import os
    print os.start
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    AttributeError: 'module' object has no attribute 'start'

    I did find os.startfile() in the docs, but it's shown as
    windows-only (it's not present under Linux).
    Launches whatever is registered as .PDF viewer and user
    can then print, save, zoom, etc. on their own.
    Really?

    --
    Grant Edwards grante Yow! Civilization is
    at fun! Anyway, it keeps
    visi.com me busy!!
  • Larry Bates at Feb 12, 2007 at 6:04 pm

    Grant Edwards wrote:
    On 2007-02-12, Larry Bates wrote:

    I at least need the code for useing some library for
    connecting to acrobat reader and giving the print command on
    windows and some thing similar on ubuntu linux.
    Just let the registered .PDF viewer do it for you.

    os.start('myfile.pdf')
    Eh? I don't see os.start() it either 2.5 or 2.44
    documentation, and it's sure not there in 2.4.3:

    $ python
    Python 2.4.3 (#1, Dec 10 2006, 22:09:09)
    [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
    Type "help", "copyright", "credits" or "license" for more
    information.
    import os
    print os.start
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    AttributeError: 'module' object has no attribute 'start'

    I did find os.startfile() in the docs, but it's shown as
    windows-only (it's not present under Linux).
    Launches whatever is registered as .PDF viewer and user
    can then print, save, zoom, etc. on their own.
    Really?
    My bad. os.system()

    -Larry
  • Grant Edwards at Feb 12, 2007 at 6:29 pm

    On 2007-02-12, Larry Bates wrote:
    On 2007-02-12, Larry Bates wrote:

    I at least need the code for useing some library for
    connecting to acrobat reader and giving the print command on
    windows and some thing similar on ubuntu linux.
    Just let the registered .PDF viewer do it for you.

    os.start('myfile.pdf')
    Eh? I don't see os.start() it either 2.5 or 2.44
    documentation, and it's sure not there in 2.4.3:
    My bad. os.system()
    That doesn't work either:

    $ ls -l user.pdf
    -rw------- 1 grante users 35640 2005-11-21 14:33 user.pdf

    $ python
    Python 2.4.3 (#1, Dec 10 2006, 22:09:09)
    [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
    Type "help", "copyright", "credits" or "license" for more
    information.
    import os
    os.system('user.pdf')
    sh: user.pdf: command not found
    32512
    >>>

    --
    Grant Edwards grante Yow! Eisenhower!! Your
    at mimeograph machine upsets
    visi.com my stomach!!
  • Larry Bates at Feb 12, 2007 at 11:13 pm

    Grant Edwards wrote:
    On 2007-02-12, Larry Bates wrote:
    On 2007-02-12, Larry Bates wrote:
    I at least need the code for useing some library for
    connecting to acrobat reader and giving the print command on
    windows and some thing similar on ubuntu linux.
    Just let the registered .PDF viewer do it for you.

    os.start('myfile.pdf')
    Eh? I don't see os.start() it either 2.5 or 2.44
    documentation, and it's sure not there in 2.4.3:
    My bad. os.system()
    That doesn't work either:

    $ ls -l user.pdf
    -rw------- 1 grante users 35640 2005-11-21 14:33 user.pdf

    $ python
    Python 2.4.3 (#1, Dec 10 2006, 22:09:09)
    [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
    Type "help", "copyright", "credits" or "license" for more
    information.
    import os
    os.system('user.pdf')
    sh: user.pdf: command not found
    32512
    Works fine on my system. You linux guys just have it hard.
    The op said "windows". I can't answer for ubuntu linux but
    maybe you can help there?

    -Larry
  • Grant Edwards at Feb 13, 2007 at 3:35 am

    On 2007-02-12, Larry Bates wrote:
    Grant Edwards wrote:
    On 2007-02-12, Larry Bates wrote:
    On 2007-02-12, Larry Bates wrote:
    I at least need the code for useing some library for
    connecting to acrobat reader and giving the print command on
    windows and some thing similar on ubuntu linux.
    Just let the registered .PDF viewer do it for you.

    os.start('myfile.pdf')
    Eh? I don't see os.start() it either 2.5 or 2.44
    documentation, and it's sure not there in 2.4.3:
    My bad. os.system()
    That doesn't work either:

    $ ls -l user.pdf
    -rw------- 1 grante users 35640 2005-11-21 14:33 user.pdf

    $ python
    Python 2.4.3 (#1, Dec 10 2006, 22:09:09)
    [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
    Type "help", "copyright", "credits" or "license" for more
    information.
    import os
    os.system('user.pdf')
    sh: user.pdf: command not found
    32512
    Works fine on my system. You linux guys just have it hard.
    The op said "windows".
    The posting to which you replied specified Linux.
    I can't answer for ubuntu linux but maybe you can help there?
    I don't see how. Pdf files just aren't executable.

    --
    Grant Edwards grante Yow! FIRST, I'm covering
    at you with OLIVE OIL and
    visi.com PRUNE WHIP!!
  • Jussi Salmela at Feb 13, 2007 at 8:44 am

    Grant Edwards kirjoitti:
    On 2007-02-12, Larry Bates wrote:
    Grant Edwards wrote:
    On 2007-02-12, Larry Bates wrote:
    On 2007-02-12, Larry Bates wrote:
    I at least need the code for useing some library for
    connecting to acrobat reader and giving the print command on
    windows and some thing similar on ubuntu linux.
    Just let the registered .PDF viewer do it for you.

    os.start('myfile.pdf')
    Eh? I don't see os.start() it either 2.5 or 2.44
    documentation, and it's sure not there in 2.4.3:
    My bad. os.system()
    That doesn't work either:

    $ ls -l user.pdf
    -rw------- 1 grante users 35640 2005-11-21 14:33 user.pdf

    $ python
    Python 2.4.3 (#1, Dec 10 2006, 22:09:09)
    [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
    Type "help", "copyright", "credits" or "license" for more
    information.
    import os
    os.system('user.pdf')
    sh: user.pdf: command not found
    32512
    Works fine on my system. You linux guys just have it hard.
    The op said "windows".
    The posting to which you replied specified Linux.
    I can't answer for ubuntu linux but maybe you can help there?
    I don't see how. Pdf files just aren't executable.
    On Windows, this (where fileName is xyz.PDF, for example):
    webbrowser.open(r'file://' + fileName)
    starts Acrobat Reader with the document read in. I have no idea why,
    because Acrobat Reader sure ain't my browser;)

    Maybe someone could try this out on Linux.

    Cheers,
    Jussi
  • Peter at Feb 13, 2007 at 10:45 am

    On Feb 13, 7:44 pm, Jussi Salmela wrote:
    Grant Edwards kirjoitti:
    On 2007-02-12, Larry Bates wrote:
    Grant Edwards wrote:
    On 2007-02-12, Larry Bates wrote:
    On 2007-02-12, Larry Bates wrote:
    I at least need the code for useing some library for
    connecting to acrobat reader and giving the print command on
    windows and some thing similar on ubuntu linux.
    Just let the registered .PDF viewer do it for you.
    os.start('myfile.pdf')
    Eh? I don't see os.start() it either 2.5 or 2.44
    documentation, and it's sure not there in 2.4.3:
    My bad. os.system()
    That doesn't work either:
    $ ls -l user.pdf
    -rw------- 1 grante users 35640 2005-11-21 14:33 user.pdf
    $ python
    Python 2.4.3 (#1, Dec 10 2006, 22:09:09)
    [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
    Type "help", "copyright", "credits" or "license" for more
    information.
    import os
    os.system('user.pdf')
    sh: user.pdf: command not found
    32512
    Works fine on my system. You linux guys just have it hard.
    The op said "windows".
    The posting to which you replied specified Linux.
    I can't answer for ubuntu linux but maybe you can help there?
    I don't see how. Pdf files just aren't executable.
    On Windows, this (where fileName is xyz.PDF, for example):
    webbrowser.open(r'file://' + fileName)
    starts Acrobat Reader with the document read in. I have no idea why,
    because Acrobat Reader sure ain't my browser;)

    Maybe someone could try this out on Linux.

    Cheers,
    Jussi
    Works on Ubuntu -- this opens a tab in my browser and then launches
    Document Viewer to view the PDF.

    peter at astro:~$ python
    Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
    [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import webbrowser
    webbrowser.open(r'file:///home/peter/appa.pdf')
  • Jim-on-linux at Feb 13, 2007 at 4:13 pm
    I'm using Suse Linux which has five program that
    will open a pdf file from a shell command line.
    Acrobat Reader is one of the five.

    A right button click on the file should give a
    list of programs that will open a PDF file.

    Im using a KDE desktop
    Open a shell, add the path to the directory where
    the PDF file lives, and on the command line type;

    xpdf myfile.pdf ## may also work on a Gnome
    ## Desktop
    or any of these for the KDE desktop;

    kpdf myfile.pdf
    Kghostview myfile.pdf
    konqueror myfile.pdf ## my browser + myfile.

    Acrobat Reader is also listed on my system. It
    open files as adobe reader using the mouse to
    open a pdf file but not from the command line
    with an arg, and I haven't spent the time to
    figgure out why.


    You will have to import os and some combination of
    any of the exec.. args, or the popen, spawn, or
    system modules.

    os.execvep() ## or others like execl, execle ....
    os.spawnv(),
    os.spawnve(),
    os.popen()

    hope this give some direction.

    jim-on-linux







    On Tuesday 13 February 2007 03:44, Jussi Salmela
    wrote:
    Grant Edwards kirjoitti:
    On 2007-02-12, Larry Bates
    wrote:
    Grant Edwards wrote:
    On 2007-02-12, Larry Bates
    wrote:
    On 2007-02-12, Larry Bates
    wrote:
    I at least need the code for useing
    some library for connecting to acrobat
    reader and giving the print command on
    windows and some thing similar on
    ubuntu linux.
    Just let the registered .PDF viewer do
    it for you.

    os.start('myfile.pdf')
    Eh? I don't see os.start() it either 2.5
    or 2.44 documentation, and it's sure not
    there in 2.4.3:
    My bad. os.system()
    That doesn't work either:

    $ ls -l user.pdf
    -rw------- 1 grante users 35640
    2005-11-21 14:33 user.pdf

    $ python
    Python 2.4.3 (#1, Dec 10 2006, 22:09:09)
    [GCC 3.4.6 (Gentoo 3.4.6-r1,
    ssp-3.4.5-1.0, pie-8.7.9)] on linux2 Type
    "help", "copyright", "credits" or "license"
    for more information.
    import os
    os.system('user.pdf')
    sh: user.pdf: command not found
    32512
    Works fine on my system. You linux guys
    just have it hard. The op said "windows".
    The posting to which you replied specified
    Linux.
    I can't answer for ubuntu linux but maybe
    you can help there?
    I don't see how. Pdf files just aren't
    executable.
    On Windows, this (where fileName is xyz.PDF,
    for example): webbrowser.open(r'file://' +
    fileName) starts Acrobat Reader with the
    document read in. I have no idea why, because
    Acrobat Reader sure ain't my browser;)

    Maybe someone could try this out on Linux.

    Cheers,
    Jussi
  • Jussi Salmela at Feb 13, 2007 at 6:13 pm

    Dennis Lee Bieber kirjoitti:
    On Tue, 13 Feb 2007 08:44:18 GMT, Jussi Salmela
    <tiedon_jano at hotmail.com> declaimed the following in comp.lang.python:

    On Windows, this (where fileName is xyz.PDF, for example):
    webbrowser.open(r'file://' + fileName)
    starts Acrobat Reader with the document read in. I have no idea why,
    because Acrobat Reader sure ain't my browser;)
    Most likely Adobe installed the Acrobat plug-in for the browser...
    The browser identifies the file as PDF and passes it to the plug-in for
    rendering.
    I can read PDFs with the browser if I open them in there.

    But as I was trying to tell the line above starts the Acrobat Reader EXE
    in its own window. The mechanism is probably caused by something I must
    have done/installed, but I don't know what.

    Anyway: it works just as I want although this may not be the general
    behaviour.

    (OS: Win XP SP2, Python 2.4.3)


    Cheers,
    Jussi
  • Jim-on-linux at Feb 14, 2007 at 4:04 am
    For those who care,
    the file below should run on a unix/ linux style
    system. And "xpdf", amoung others, will run a pdf
    file.


    import os
    def Printpdf():
    os.system( 'xpdf form.pdf' )

    if __name__ == '__main__' :
    Printpdf()

    jim-on-linux


    On Tue, 13 Feb 2007 08:44:18 GMT, Jussi Salmela

    <tiedon_jano at hotmail.com> declaimed the
    following in comp.lang.python:
    On Windows, this (where fileName is xyz.PDF,
    for example): webbrowser.open(r'file://' +
    fileName) starts Acrobat Reader with the
    document read in. I have no idea why, because
    Acrobat Reader sure ain't my browser;)
    Most likely Adobe installed the Acrobat
    plug-in for the browser... The browser
    identifies the file as PDF and passes it to the
    plug-in for rendering.
    --
    Wulfraed Dennis Lee Bieber KD6MOG
    wlfraed at ix.netcom.com wulfraed at bestiaria.com
    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support
    Staff: web-asst at bestiaria.com)
    HTTP://www.bestiaria.com/
  • krishnakant Mane at Feb 12, 2007 at 6:06 pm
    os.start does not work.. attribute error.
    regards.
    Krishnakant.
  • Patricio Olivares at Feb 12, 2007 at 10:41 pm

    On Feb 12, 3:06 pm, "krishnakant Mane" wrote:
    os.start does not work.. attribute error.
    regards.
    Krishnakant.
    It's os.system('thefile') or os.system('start thefile') but
    that's windows only. It seems like there's no
    platform-independent way to launch a preferred application to open
    a file, but...

    based on <http://cweiske.de/howto/launch/allinone.html>
    I would suggest (by looking at sys.platform) to use "start" on
    windows, "open" on mac, and on linux to use the xdg-open shell
    script which is part of XdgUtils...
    <http://portland.freedesktop.org/wiki/>

    It works standalone. Even seems it would not take too much
    effort to port it to python if you want.
  • XBello at Feb 13, 2007 at 2:41 pm

    On Feb 12, 4:56 pm, Larry Bates wrote:
    krishnakant Mane wrote:
    hello all,
    I am stuck with a strange requirement.
    I need a library that can help me display a pdf file as a report and
    also want a way to print the same pdf file in a platform independent
    way.
    if that's not possible then I at least need the code for useing some
    library for connecting to acrobat reader and giving the print command
    on windows and some thing similar on ubuntu linux.
    the problem is that I want to display reports in my application. the
    user should be able to view the formatted report on screen and at his
    choice click the print button on the screen to send it to the printer.
    I have reportlab installed and that is sufficient to generate pdf reports.
    but I still can't fine the way to display it directly and print it
    directly.
    Please help me.
    Krishnakant.
    Just let the registered .PDF viewer do it for you.

    os.start('myfile.pdf')

    Launches whatever is registered as .PDF viewer and user
    can then print, save, zoom, etc. on their own.

    -Larry

    os.startfile('pathToTheFile') should work. Under Library Reference- >
    os -> Process Management
  • Antoon Pardon at Feb 13, 2007 at 3:24 pm

    On 2007-02-11, krishnakant Mane wrote:
    hello all,
    I am stuck with a strange requirement.
    I need a library that can help me display a pdf file as a report and
    also want a way to print the same pdf file in a platform independent
    way.
    if that's not possible then I at least need the code for useing some
    library for connecting to acrobat reader and giving the print command
    on windows and some thing similar on ubuntu linux.
    the problem is that I want to display reports in my application. the
    user should be able to view the formatted report on screen and at his
    choice click the print button on the screen to send it to the printer.
    I have reportlab installed and that is sufficient to generate pdf reports.
    but I still can't fine the way to display it directly and print it directly.
    Please help me.
    Krishnakant.
    I think the best way to handle this under a unix like system is by using
    the mailcap module, something like the following:

    import mailcap
    import os

    mc = mailcap.getcaps()
    cmd = mailcap.findmatch(mc, 'image/pdf' , filename='/tmp/dummy')[0]
    os.system(cmd)

    --
    Antoon Pardon

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 11, '07 at 6:45a
activeFeb 14, '07 at 4:04a
posts23
users12
websitepython.org

People

Translate

site design / logo © 2022 Grokbase