[reportlab-users] General questions about ReportLab

Andy Robinson andy at reportlab.com
Wed Aug 27 03:28:03 EDT 2014


On 27 August 2014 07:42, Frank Millman <frank at chagford.com> wrote:
> Hi all
>
> 1. As I understand it, RL allows a user to generate a report in PDF format
> and save it to a file. If they want to print it they must call up Acrobat
> Reader and print it from there.
>
> There are times when a user wants to run a report and send it to a printer
> straight away. I have read a bit about installing GhostScript, using it to
> convert PDF to PostScript, and sending it to a PostScript printer. Is this
> the recommended solution? Are there any examples?

Hi Frank,

I originally conceived of reportlab to be the print engine for an
accounting system, about 15 years ago, so I know exactly where you are
coming from.  Unfortunately the answers to your problems vary by
platform and I suspect by operating system, and it's all moved on
since we last had to deal with it.

I don't think you will be able to write a program that runs on all
platforms, automatically figures out what printers are attached and
can just drive them without any setup or testing.  You say your system
uses Javascript - is it a typical web application, with a remote
server and users interacting through a browser?  Or, if it installs on
the client, what platforms do you support and what GUI toolkits are
you using?

> What if the printer does not accept PostScript? I use an HP1150 LaserJet,
> which uses PCL5. Acrobat Reader can print to it with no problem. Would I be
> able to do the same from RL?

Every OS has some ways to print PDF files, whether through using
Acrobat Reader or an open source or free competitor.  The trick is to
find one with a command line API to send it to the printer, and then
to know what printers are there and working.   The xpdf utility is
widely available on Linux and we found it to be a very good PDF
viewer, handling many Asian-language test cases which Acroread didn't,
rather a long time ago.   It can send postscript output to lpr below.


> 2. In order for me to print directly to a printer, I need to know which
> printers are available. Is there a cross-platform way of enquiring from the
> system which printers are installed? If not I can create a database table to
> store printer information which the user must fill in manually. At a minimum
> I would need printer name and page size. Has anyone done this?

I don't know of a cross-platform way.  On Windows, there are APIs.  On
Linux, read through the CUPS manual which encompasses lpr and a bunch
of related utilities and covers most of what you are asking.

    http://www.cups.org/doc-1.1/sum.html#3_2


> 3. Is there a cross-platform way of actually sending a stream of bytes to
> the print spooler. Is 'lpr' the answer? Does it work on Windows?

See above.  Windows has some support for the protocol behind CUPS
these days but I haven't worked with it.

> 4. Some users still want to print invoices on multi-part paper on a
> dot-matrix printer. Can PDF be used for this at all, or must I come up with
> some other solution?

No idea, personally.  I haven't had to interact with fanfold paper
since the early 90s.  From what I recall from my very early days in
computing in the 1980s, a page break would cause the multi-part paper
to roll on down to the next perforation or just leave some space.

> 5. Print previews - I have written the client side of my application in
> Javascript, so that it will run in any browser. Is there a way of generating
> a PDF file from RL and displaying it in the browser, without writing it to a
> file?

Yes.  Assuming you have a web server on the back end running, say,
Django, you would generate a response like this to open in the
browser:

    return HTTPResponse(my_pdf_file_content, content_type="application/pdf")

and to have it downloaded to desktop, you add a header like this:

  response = HTTPResponse(my_pdf_file_content, content_type="application/pdf")
  response[['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
  return response


> P.S. I see that ReportLab's offices are in Thornton Road, Wimbledon. I was
> brought up in Worple Road, and I went to school in Edge Hill. Small world

If you're back in the neighbourhood, please do give us a ring and drop
in for coffee...

(Ditto for any other users of ours)


- Andy


More information about the reportlab-users mailing list