PDF Printing support from Python

Discussion in 'Python' started by dcrespo, Apr 22, 2005.

  1. dcrespo

    dcrespo Guest

    Hi all... Is there a way to print a PDF file directly from Python
    without having Acrobat installed? I know about ReportLab. It's a python
    module that lets you create almost any PDF document, but I still don't
    know if it supports printing, so I'm looking for a Python module that
    could do it. I want to print a PDF file just like if I were doing it
    from Acrobat.

    Daniel.
     
    dcrespo, Apr 22, 2005
    #1
    1. Advertising

  2. On 2005-04-22, dcrespo <> wrote:

    > Hi all... Is there a way to print a PDF file directly from
    > Python without having Acrobat installed?


    Assuming your printing system was setup competently:

    os.system("lpr %s" % filename)

    > I know about ReportLab. It's a python module that lets you
    > create almost any PDF document, but I still don't know if it
    > supports printing, so I'm looking for a Python module that
    > could do it. I want to print a PDF file just like if I were
    > doing it from Acrobat.


    Not sure what you mean by "just like if I were doing it from
    Acrobat".

    --
    Grant Edwards grante Yow! I have seen these
    at EGG EXTENDERS in my
    visi.com Supermarket... I have read
    theINSTRUCTIONS...
     
    Grant Edwards, Apr 22, 2005
    #2
    1. Advertising

  3. dcrespo

    dcrespo Guest

    Hi Grant Edwards...

    Your solution requires a previous installation of Acrobat. Internally,
    the OS is sending the pdf file to the Acrobat PDF Driver and then it is
    sent to the printer. So you have to have Acrobat installed. Don't you?
    I want to avoid it installing a module that could do it (maybe I'm
    dreaming:( ). If there's no solution, then I will be very sad :-S

    This is what exactly I need to do:
    Generate an invoice of 216cm width and 93cm height (1/3 of the height
    of a letter paper size), and print it respecting these dimensions. So,
    when I print this page on a dot matrix printer, it stops at those 93cm
    of height for continuous printing.

    What I tried:
    I created a pdf file manually with these dimensions, and right-click on
    the pdf file, and selected "print". It just work under Windows XP with
    Acrobat Reader 7.0, but I want to do it from a Win98 as well.
    Unfortunately, there's no Acrobat version under Win98 (the maximun is
    5.1) that supports this kind of printing (what I had seen until now).
    It prints, but the all paper at letter size :(

    Any help? Any other tools? Any one like Cristal Report but for Python?
    I heard that wxPython supports some kind of reporting, but I don't know
    it. Anyone knows?

    Daniel
     
    dcrespo, Apr 22, 2005
    #3
  4. dcrespo

    Harry George Guest

    "dcrespo" <> writes:

    > Hi Grant Edwards...
    >
    > Your solution requires a previous installation of Acrobat. Internally,
    > the OS is sending the pdf file to the Acrobat PDF Driver and then it is
    > sent to the printer. So you have to have Acrobat installed. Don't you?
    > I want to avoid it installing a module that could do it (maybe I'm
    > dreaming:( ). If there's no solution, then I will be very sad :-S
    >
    > This is what exactly I need to do:
    > Generate an invoice of 216cm width and 93cm height (1/3 of the height
    > of a letter paper size), and print it respecting these dimensions. So,
    > when I print this page on a dot matrix printer, it stops at those 93cm
    > of height for continuous printing.
    >
    > What I tried:
    > I created a pdf file manually with these dimensions, and right-click on
    > the pdf file, and selected "print". It just work under Windows XP with
    > Acrobat Reader 7.0, but I want to do it from a Win98 as well.
    > Unfortunately, there's no Acrobat version under Win98 (the maximun is
    > 5.1) that supports this kind of printing (what I had seen until now).
    > It prints, but the all paper at letter size :(
    >
    > Any help? Any other tools? Any one like Cristal Report but for Python?
    > I heard that wxPython supports some kind of reporting, but I don't know
    > it. Anyone knows?
    >
    > Daniel
    >



    When you say "OS", are you talking MS Windows by any chance? On *NIX
    (e.g., CUPS+ghostview+foomatic), PDF printing is not via Adobe code.

    You could also consider pdf2ps, pdftops, and XPDF.


    --

    6-6M21 BCA CompArch Design Engineering
    Phone: (425) 294-4718
     
    Harry George, Apr 22, 2005
    #4
  5. On 2005-04-22, dcrespo <> wrote:

    > Your solution requires a previous installation of Acrobat.


    Probably not. Most printing systems I'm familiar with use
    ghostscript to render PDF into either postscript (the case on
    my machines at home) or whatever raster format the printer
    desires (the case at my office).

    > Internally, the OS is sending the pdf file to the Acrobat PDF
    > Driver and then it is sent to the printer.


    Nope. It's usnig the foomatic print filters which in turn use
    ghostscript to render PDF.

    > So you have to have Acrobat installed. Don't you?


    No you just need a good printing system. CUPS + foomatic works
    great for me. It knows what to do with postcript, text, PDF,
    dvi, and a whole boatload of other fileformats that I don't
    ever use.

    > I want to avoid it installing a module that could do it (maybe
    > I'm dreaming:( ). If there's no solution, then I will be very
    > sad :-S
    >
    > This is what exactly I need to do: Generate an invoice of
    > 216cm width and 93cm height (1/3 of the height of a letter
    > paper size), and print it respecting these dimensions. So,
    > when I print this page on a dot matrix printer, it stops at
    > those 93cm of height for continuous printing.
    >
    > What I tried: I created a pdf file manually with these
    > dimensions, and right-click on the pdf file, and selected
    > "print". It just work under Windows XP with Acrobat Reader
    > 7.0, but I want to do it from a Win98 as well.


    Ah. You're using Windows. I didn't know that. I've no clue
    what to do under Windows.

    --
    Grant Edwards grante Yow! .. someone in DAYTON,
    at Ohio is selling USED
    visi.com CARPETS to a SERBO-CROATIAN
     
    Grant Edwards, Apr 22, 2005
    #5
  6. Grant's example is not for Windows, Daniel, but it does illustrate a
    certain principle: if you have a printer driver that understands PDF,
    or some other external software such as Acrobat Reader that understands
    PDF, then printing the PDF is as simple as telling the OS to just print
    the file.

    If you are looking for some software that acts as a PDF-understanding
    interpreter, that must run under Windows 98, I don't know of any
    written in Python. However, you might want to research some of the
    available non-Python utilities. Ghostscript, for example, is available
    at http://www.cs.wisc.edu/~ghost/ and has a version for Win32. You
    could easily use Python to drive GhostScript.

    Does that fit your needs?

    ---Peter
     
    Peter Herndon, Apr 22, 2005
    #6
  7. dcrespo

    John J. Lee Guest

    "dcrespo" <> writes:

    > Hi Grant Edwards...
    >
    > Your solution requires a previous installation of Acrobat. Internally,
    > the OS is sending the pdf file to the Acrobat PDF Driver and then it is
    > sent to the printer. So you have to have Acrobat installed. Don't you?
    > I want to avoid it installing a module that could do it (maybe I'm
    > dreaming:( ). If there's no solution, then I will be very sad :-S

    [...]
    > Acrobat Reader 7.0, but I want to do it from a Win98 as well.
    > Unfortunately, there's no Acrobat version under Win98 (the maximun is
    > 5.1) that supports this kind of printing (what I had seen until now).
    > It prints, but the all paper at letter size :(


    That doesn't sound like a fundamental problem with AR 5.1 to me --
    sounds like you just need to ask it more nicely ;-)

    Have you tried the latest version of APFL ghostscript, though (8.51)?


    > Any help? Any other tools? Any one like Cristal Report but for Python?
    > I heard that wxPython supports some kind of reporting, but I don't know
    > it. Anyone knows?


    First, decide what qualities you need from your output format, then
    decide which format you want, and how to generate and print it. Is it
    important that you have one, other, or both of bitmap or vector
    output, for example?


    John
     
    John J. Lee, Apr 22, 2005
    #7
  8. dcrespo

    dcrespo Guest

    Thanks a lot... I'm attemping to give it a try :)
     
    dcrespo, Apr 22, 2005
    #8
  9. dcrespo

    dcrespo Guest

    > That doesn't sound like a fundamental problem with AR 5.1 to me --
    sounds like you just need to ask it more nicely ;-)

    AR 7.0 has the function to print exactly the page size you set. AR 5.1
    doesn't. Instead, it print it on an existing page size like letter, but
    without changing the relative layout of the each line of text respect
    each other.

    Daniel
     
    dcrespo, Apr 22, 2005
    #9
  10. dcrespo

    dcrespo Guest

    >> Your solution requires a previous installation of Acrobat.

    > Probably not. Most printing systems I'm familiar with use
    > ghostscript to render PDF into either postscript (the case on
    > my machines at home) or whatever raster format the printer
    > desires (the case at my office).


    Acrobat (windows) and Ghostscript are PDF drivers.

    >> Internally, the OS is sending the pdf file to the Acrobat PDF
    >> Driver and then it is sent to the printer.


    > Nope. It's usnig the foomatic print filters which in turn use
    > ghostscript to render PDF.


    What I mean is that the pdf file is sent to a pdf driver (some program
    to interpret it)... In your case is ghostscript, and in my case is
    Acrobat.

    > No you just need a good printing system. CUPS + foomatic works
    > great for me. It knows what to do with postcript, text, PDF,
    > dvi, and a whole boatload of other fileformats that I don't
    > ever use.


    CUPS + foomatic are the whole megadriver... So it's just a manner of
    saying PDF Driver for my study case.

    Really thanks for all the information :) I didn't know about
    Ghostscript.

    Daniel
     
    dcrespo, Apr 22, 2005
    #10
  11. On 2005-04-22, dcrespo <> wrote:
    >>> Your solution requires a previous installation of Acrobat.

    >
    >> Probably not. Most printing systems I'm familiar with use
    >> ghostscript to render PDF into either postscript (the case on
    >> my machines at home) or whatever raster format the printer
    >> desires (the case at my office).

    >
    > Acrobat (windows) and Ghostscript are PDF drivers.


    No, ghostscript isn't a "driver". it's a normal user-space
    application, but I'm not sure what you're point is. My
    statement that printing PDF doesn't depend on Acrobat is true
    regardless of whether ghostscript is a driver or application.

    >>> Internally, the OS is sending the pdf file to the Acrobat PDF
    >>> Driver and then it is sent to the printer.

    >
    >> Nope. It's usnig the foomatic print filters which in turn use
    >> ghostscript to render PDF.

    >
    > What I mean is that the pdf file is sent to a pdf driver (some
    > program to interpret it)... In your case is ghostscript, and
    > in my case is Acrobat.


    That's not a driver. At least not in my world. Drivers live
    in kernel space. Acrobat and ghostscript are just applications
    that run in user-space.

    >> No you just need a good printing system. CUPS + foomatic works
    >> great for me. It knows what to do with postcript, text, PDF,
    >> dvi, and a whole boatload of other fileformats that I don't
    >> ever use.

    >
    > CUPS + foomatic are the whole megadriver... So it's just a
    > manner of saying PDF Driver for my study case.


    You're use of the word "driver" is one with which I'm not
    familiar. But I don't really "do windows" so it's probably a
    Widnowism.

    > Really thanks for all the information :) I didn't know about
    > Ghostscript.


    I'm sure you can use ghostscript to do the same thing under
    Windows (render PDF into the raster format preferred by your
    printer), but I've no idea how one would go about it.

    --
    Grant Edwards grante Yow! Hmmm... a CRIPPLED
    at ACCOUNTANT with a FALAFEL
    visi.com sandwich is HIT by a
    TROLLEY-CAR...
     
    Grant Edwards, Apr 22, 2005
    #11
  12. dcrespo

    Mike Meyer Guest

    "dcrespo" <> writes:

    > Hi Grant Edwards...
    >
    > Your solution requires a previous installation of Acrobat. Internally,
    > the OS is sending the pdf file to the Acrobat PDF Driver and then it is
    > sent to the printer. So you have to have Acrobat installed. Don't you?


    No, you don't. My print system does that, and I don't have acrobat
    installed. I have ghostscript installed, which includes pdf2ps - which
    handles this particular translation.

    > This is what exactly I need to do:
    > Generate an invoice of 216cm width and 93cm height (1/3 of the height
    > of a letter paper size), and print it respecting these dimensions. So,
    > when I print this page on a dot matrix printer, it stops at those 93cm
    > of height for continuous printing.


    Ok, I'm a masochist. When I have problems like this (i.e. - printing
    CD labels, addressing envelopes, etc) I just have the python generate
    raw postscript. That gives you more than enough control over the
    output to solve the problem. Integrating it with a GUI is another
    matter, though.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Apr 22, 2005
    #12
  13. > You're use of the word "driver" is one with which I'm not
    > familiar. But I don't really "do windows" so it's probably a
    > Widnowism.


    It could be that he means that creating PDFs on windows is done using a fake
    printer that will produce the pdf when being printed to - and that fake
    printer is implemented as a driver.

    And traditionally in printing one often speaks of printer drivers - even if
    they are mere filters that can't be considered drivers in the kernel driver
    way.
    --
    Regards,

    Diez B. Roggisch
     
    Diez B. Roggisch, Apr 23, 2005
    #13
  14. On 2005-04-23, Diez B. Roggisch <> wrote:

    >> You're use of the word "driver" is one with which I'm not
    >> familiar. But I don't really "do windows" so it's probably a
    >> Widnowism.

    >
    > It could be that he means that creating PDFs on windows is
    > done using a fake printer that will produce the pdf when being
    > printed to - and that fake printer is implemented as a driver.
    >
    > And traditionally in printing one often speaks of printer
    > drivers - even if they are mere filters that can't be
    > considered drivers in the kernel driver way.


    I think it's the latter. I believe he wants to know how to
    print a PDF file without using any external programs (or
    "drivers") like Acrobat Reader or ghostscript that understand
    PDF. AFAIK, the only way to do what he wants would be for him
    to write a PDF engine in Python that renders PDF into whatever
    raw format is understood by his printer.

    --
    Grant Edwards grante Yow! I'LL get it!! It's
    at probably a FEW of my
    visi.com ITALIAN GIRL-FRIENDS!!
     
    Grant Edwards, Apr 23, 2005
    #14
  15. On Fri, 22 Apr 2005 17:41:22 -0500, Mike Meyer <> declaimed
    the following in comp.lang.python:

    > No, you don't. My print system does that, and I don't have acrobat
    > installed. I have ghostscript installed, which includes pdf2ps - which
    > handles this particular translation.
    >

    Okay, so you've converted one page layout language (PDF) to
    another (PS)... To actually print it you still need a RIP. A PostScript
    laser printer has the RIP built-in, but consumer level Windows printers
    do not have a PostScript RIP -- and some printers don't even have their
    own specific RIP built-in ("winprinters" put the RIP into the software
    driver that runs on the Windows machine, rather than sending drawing
    commands to the printer for rendering).

    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
     
    Dennis Lee Bieber, Apr 23, 2005
    #15
  16. dcrespo

    M.E.Farmer Guest

    > You're use of the word "driver" is one with which I'm not
    > familiar. But I don't really "do windows" so it's probably a
    > Widnowism.

    It is a windowism but not exclusively ;).
    http://www.collaborium.org/onsite/romania/UTILS/Printing-HOWTO/winprinters.html

    This is the first link I found that mentioned drivers, but the last
    time I installed Linux-Mandrake I saw a document that went into detail
    about CUPS and windows printing.
    It seems that cups is available for windows( they also use the word
    driver )
    http://www.cups.org/windows/index.php
    Ghostscript for windows available here
    http://www.ghostscript.com/
    http://www.cs.wisc.edu/~ghost/
     
    M.E.Farmer, Apr 23, 2005
    #16
  17. dcrespo

    Mike Meyer Guest

    Dennis Lee Bieber <> writes:

    > On Fri, 22 Apr 2005 17:41:22 -0500, Mike Meyer <> declaimed
    > the following in comp.lang.python:
    >
    >> No, you don't. My print system does that, and I don't have acrobat
    >> installed. I have ghostscript installed, which includes pdf2ps - which
    >> handles this particular translation.
    >>

    > Okay, so you've converted one page layout language (PDF) to
    > another (PS)... To actually print it you still need a RIP. A PostScript
    > laser printer has the RIP built-in, but consumer level Windows printers
    > do not have a PostScript RIP -- and some printers don't even have their
    > own specific RIP built-in ("winprinters" put the RIP into the software
    > driver that runs on the Windows machine, rather than sending drawing
    > commands to the printer for rendering).


    RIP? That term is to generic for google to be much use.

    If you're saying you need a tool to convert from PDF to whatever the
    printer understands, you're right. You can't avoid that. On Unix, PS
    is used as the "universal" printer language. Unix vendors selling
    printers sold PS printers 20 years ago. That's when apsfilter showed
    up on the scene, automatically converting everything to PS to send it
    to the printer. (These days, magicfilter is a much better tool than
    apsfilter, though it's harder to install). That's why a "competent"
    printer installation these days will include ghostscript (or something
    equivalent) to drive the printer, and why my primary printer speaks
    PostScript.

    I disagree with your description of WinPrinters. Those are printers to
    stupid to handle flat ASCII, so your computer has to convert flat
    ASCII files to postscript or some other graphics format before you can
    print them. (This is where magicfilter beats apsfilter - apsfilter
    converts ASCII to PS to graphics images, whereas magicfilter can pass
    the text straight through. This has caused apsfilter to fail on some
    systems where magicfilter would work like a charm). Such printers
    typically only come with drivers for Windows, and are completely
    useless - unable to even print flat ASCII text - on other systems,
    hence the moniker "WinPrinters". Non-winprinters can be used to print
    flat ASCII without a driver of any kind. GhostScript now includes
    graphics drivers for several winprinters.

    The only way to have Python render PDF (or PS, or JPEG, or any other
    graphics format) without a "driver" of some kind is to write the
    driver in Python. That's a pretty silly thing to want to do. For one
    thing, the performance will probably suck. For another, there are lots
    of drivers already written that you can use.

    The only thing better than writing it in Python is finding that
    someone else has already written it.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Apr 23, 2005
    #17
  18. On 2005-04-23, Mike Meyer <> wrote:

    >>> No, you don't. My print system does that, and I don't have
    >>> acrobat installed. I have ghostscript installed, which
    >>> includes pdf2ps - which handles this particular translation.
    >>>

    >> Okay, so you've converted one page layout language
    >> (PDF) to another (PS)... To actually print it you still need a
    >> RIP. A PostScript laser printer has the RIP built-in, but
    >> consumer level Windows printers do not have a PostScript RIP
    >> -- and some printers don't even have their own specific RIP
    >> built-in ("winprinters" put the RIP into the software driver
    >> that runs on the Windows machine, rather than sending drawing
    >> commands to the printer for rendering).

    >
    > RIP? That term is to generic for google to be much use.


    Raster Image Processor. It renders postscript into a raster
    image at the proper image.

    --
    Grant Edwards grante Yow! If this is the DATING
    at GAME I want to know your
    visi.com FAVORITE PLANET! Do I get
    th' MICROWAVE MOPED?
     
    Grant Edwards, Apr 24, 2005
    #18
  19. On Sat, 23 Apr 2005 17:31:22 -0500, Mike Meyer <> declaimed
    the following in comp.lang.python:

    >
    > RIP? That term is to generic for google to be much use.
    >

    Raster Image Processor -- on a PostScript compatible laser
    printer, this is the software and computer that converts PostScript
    programs into the actual bitmap needed to print the page. Used to cost
    extra to get PostScript capability on top of the printer native (HP PCL,
    for example). Normally it runs inside the printer itself.

    > I disagree with your description of WinPrinters. Those are printers to
    > stupid to handle flat ASCII, so your computer has to convert flat


    IE, absolutely NO RIP at all. Those that handle plain ASCII
    still have a RIP to convert ASCII bytecodes to bit patterns for the
    printhead.


    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
     
    Dennis Lee Bieber, Apr 24, 2005
    #19
  20. >>>>> "Diez B. Roggisch" <> (DBR) wrote:

    >>> You're use of the word "driver" is one with which I'm not
    >>> familiar. But I don't really "do windows" so it's probably a
    >>> Widnowism.


    >DBR> It could be that he means that creating PDFs on windows is done using
    >DBR> a fake printer that will produce the pdf when being printed to - and
    >DBR> that fake printer is implemented as a driver.


    But that is about creating a PDF file, whereas the OP was speaking about
    printing an existing PDF file, For that you need a PDF interpreter, not a
    PDF printer driver.
    --
    Piet van Oostrum <>
    URL: http://www.cs.uu.nl/~piet [PGP]
    Private email:
     
    Piet van Oostrum, Apr 27, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon B
    Replies:
    7
    Views:
    7,554
    =?Utf-8?B?SmFzb25DaG9p?=
    Jan 30, 2006
  2. JustSomeGuy
    Replies:
    13
    Views:
    519
    msalters
    Dec 9, 2004
  3. Donnal Walter

    printing HTML or PDF from Python

    Donnal Walter, Oct 26, 2004, in forum: Python
    Replies:
    5
    Views:
    1,453
    Peter Hansen
    Oct 27, 2004
  4. Ricardo Pog
    Replies:
    1
    Views:
    454
    Austin Ziegler
    Mar 26, 2008
  5. Sean Nakasone
    Replies:
    1
    Views:
    400
    Farrel Lifson
    Apr 14, 2008
Loading...

Share This Page