I have this code that doesn't work too well...


import os
import sys
pdf = receipt_PDF()
pdf.add_page()
rcpt_filename = "RCPT_%s_%s.pdf" % (session.rcpt_number, session.rcpt_recipient)
rcpt_filename = rcpt_filename.replace( ' ', '_' )
if sys.platform.startswith( "linux" ) :
    os.system( "xdg-open ./%s" %(rcpt_filename) )
else :
    os.system( "./%s" %(rcpt_filename) )
#print "<pdf_invoice> inv_filename=%s" %(inv_filename)
response.headers['Content-Type'] = 'application/pdf'
#response.headers['Content-disposition'] = 'attachment; filename=%s' % 
rcpt_filename
pdf.output( rcpt_filename, dest='F' )


as it stands the code... 

   - writes the PDF to disk with the required filename (path is simply the 
   web2py directory) - this file can be readily opened later in Adobe Reader 9
   - it also opens a *blank* document in a browser reader (with information 
   message - this PDF doc may not be displayed correctly) (user has lost Nav 
   bar options)
   - finally it opens the requested document in Adobe Reader 9 (appears 
   perfect i.e. no error messages)
   - the user has to use Adobe's 'page save as'  to save the file in their 
   desired location
   - the user has to close Adobe and use 'Go Back' in the browser to clear 
   the browser reader and return to viewing the original request page 
   
what I would like it to do is... 

   - leave the browser on the original page used to call the function
   - open the o/s' download/open dialogue box prompting the user to save 
   the file (wherever they desire)
   - once the file is downloaded the user simply returns to the browser 
   where they left off (without using 'Go Back')


FPDF is a brilliant contribution to the web2py armoury and again I am 
chuffed to have gotten this far with it. The blockage for me is that the 
documentation is somewhat disconnected in that none of the examples are in 
the context of web2py environment e.g.whether and how to use  pdf.output vs 
response.stream 


I have been reading as much as I can find but nothing seems to match 
exactly what I want to do and despite trying dozens of variations nothing 
gets me closer without breaking something else.

It seems I need to drop the xdg portion, that the header's content type = 
attachment will force the download dialogue, and,  I think, I need to be 
using file-like object (but is the FPDF object not this?) with Stringio in 
the mix?


Any assistance with the specifics needed to accomplish what I am looking 
for above would be appreciated!  



Peter







-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to