[mod_python] Server Side Printing

Graham Dumpleton grahamd at dscpl.com.au
Sat Aug 12 17:45:45 EDT 2006

On 12/08/2006, at 10:29 PM, S.R.Pardá wrote:

> Ok,
> Thank You Very Much, Graham.
> That looks a way to the solution.
> You understand me, and like you pointed, the idea is to print  
> content on
> the fly.
> And now you will understand I want to use HTML because at this  
> moment I
> would prefer not to get inside on another Page Description language to
> generate the documents.
> I know HTML itsn't WYSIWYG but in a Server Side printing environment I
> can have it controled, and I can change later to another document  
> format
> if needed with more time to develop it. So I will try html2ps first
> before pdf2ps.
> I will investigate further.
> I wonder if mod_python can get the own page as the onthefly source  
> after
> send the request.
> Or if the file can be something like:
> "http://server/printableBill.psp?num=0248;"

It is a more advanced area of mod_python but what you could do is  
an output filter to capture the HTML which is actually being sent  
back to
the client.

What you would do is in the request handler, you would set some special
header in the output, for example 'X-Printer'. The output filter when  
the first time could look for this header. If it doesn't see it, it  
would simply
call filter.pass_on() and thus it would ignore the response content.  
If the
header is there, it could take the value of the header as the printer  
save that away and then accumulate the content of the response until  
it is
complete. When it has the whole content, it could send it through  
and then also write it back to the client.

Thus have a look at output filters. Ensure you search back through the
mailing list archive as they have been good boiler plate examples posted
before for how to use it.


> Thank You again.
> 	S.R.Parda
> El sáb, 12-08-2006 a las 21:47 +1000, Graham Dumpleton escribió:
>> On 12/08/2006, at 9:39 PM, Graham Dumpleton wrote:
>>> Please keep discussion on the mailing list. I have forwarded your
>>> response back there.
>>> On 12/08/2006, at 9:18 PM, S.R.Pardá wrote:
>>>> Ok, I will try to explain it better.
>>>> I have now in the server a PDF (or HTML) that I can open with  
>>>> eVince.
>>>> How I send that document to a network printer from ModPython's
>>>> interpreted code when client user press PRINT button in one page.
>>>> So server receive a HTTP request for:
>>>> 	http://server/printBill.psp?doc=bill0248.pdf
>>>> So I want to code a printBill.psp page that prints like:
>>>> <%
>>>> PrinterName = "HP-4100"		#Thats the name of the printer for bills
>>>> DocumentToPrint = form('doc')   #The Document the user want to  
>>>> print
>>>> SendToPrint (PrinterName, DocumentToPrint)
>>>> %>
>>>> Now , how I code SendToPrint.
>>>> Do I need to use some library ?
>>>> Can I execute evince from shell indicating some parameter to print
>>>> on a
>>>> specified printer?
>> If the PDF were a file stored in the file system, in UNIX the command
>> to print it would be:
>>    pdf2ps somefile.pdf | lp -s -d HP-4100
>> In other words, convert to postscript and use 'lp' to spool to  
>> desired
>> printer. The '-s' option (may depend on platform), just tells lp  
>> to not
>> output status string about job number it was queued at.
>> This command could be invoked from Python using 'os.system()'.
>> Alternatively, if PDF content generated by Python code on the fly,
>> the you might want to use the 'popen2' module to create the command
>> as a pipe you can send data into in which case the command would
>> just be:
>>    pdf2ps | lp -s -d HP-4100
>> If you can't find pdf2ps, then get a copy of 'ghostscript' package  
>> for
>> your system and install that.
>> Graham
>>>> The principal problem is not be able to print from client if we  
>>>> can't
>>>> select the printer from the server , because user can't select  
>>>> every
>>>> time a printer for every kind of document he prints.
>>>> El sáb, 12-08-2006 a las 20:24 +1000, Graham Dumpleton escribió:
>>>>> On 12/08/2006, at 7:22 PM, S.R.Pardá wrote:
>>>>>> Hi all,
>>>>>> I'm considering solutions to print HTML pages served by some
>>>>>> Linux OS
>>>>>> with Apache and  Mod_Python.
>>>>>> I am looking a server side approach, that is: I want the server
>>>>>> send the
>>>>>> HTML output when required to one of varios network printers
>>>>>> installed in
>>>>>> the server.
>>>>>> I have not idea about linux printing , I would need an  
>>>>>> orientation
>>>>>> about
>>>>>> what have to know.
>>>>>> Are any python module for printing?
>>>>>> Must I execute some shell command to print inside python?
>>>>>> Must I generate a PostScript document from the HTML document to
>>>>>> print
>>>>>> it ?
>>>>>> More details:
>>>>>> Web Clients (Windows probably) will print some documents
>>>>>> received. But
>>>>>> the documents have diferent formats (size, orientation, duplex
>>>>>> option)
>>>>>> so it's desiderable the automatic printer/configuration selection
>>>>>> ( that
>>>>>> is: witout a printer selection dialog in IE or Firefox and the
>>>>>> default
>>>>>> printer isn't valid for all documents)
>>>>>> As I found in client window Javascript it's not capable of select
>>>>>> printers in client side, I have to investigate with VBscript, and
>>>>>> another possibility would be install an ActiveX control to do  
>>>>>> that
>>>>>> (restricting possible client options).
>>>>>> So I think the server approach, would be better because it
>>>>>> eliminates
>>>>>> printer management in client, and assures the same HTML render
>>>>>> configuration for all printings, independent of client
>>>>>> configuration /
>>>>>> browser.
>>>>> Not sure I really understand what you are trying to do, but if  
>>>>> your
>>>>> target
>>>>> is a printer, not sure why you would want to try and render to  
>>>>> HTML
>>>>> and then print that. Your better option would be target PDF as  
>>>>> your
>>>>> display format and then print the PDF file.
>>>>> Suggest you have a look at the following sites:
>>>>>    http://www.openreport.org
>>>>>    http://www.reportlab.org
>>>>>    http://www.reportlab.com
>>>>> With these solutions, one option is to describe documents as RML.
>>>>> This
>>>>> can be filled out with data from some source and then translated
>>>>> into
>>>>> PDF
>>>>> or HTML. Thus HTML becomes a screen representation but PDF what
>>>>> is used for printing.
>>>>> If you already have the document generation side worked out,  
>>>>> and are
>>>>> only really after solution for printing, not sure how Apache and
>>>>> mod_python
>>>>> comes in to it all.
>>>>> Anyway, hope the sites I reference might be of some help.
>>>>> Graham
>>> _______________________________________________
>>> Mod_python mailing list
>>> Mod_python at modpython.org
>>> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list