With this:    
...
s_io = pdf.output(dest='S')
response.headers['Content-Type']='application/pdf'
response.headers['Content-Disposition'] = 'attachment; filename="%s"' % 
file_name
raise HTTP(200, s_io, **response.headers)
You get the same you have now with response.stream but it's cleaner.
Without setting the 'Content-disposition' the pdf will be opened in the 
browser.

Paolo

On Sunday, October 16, 2016 at 7:42:29 PM UTC+2, Peter wrote:
>
>
> So this is better but I still need some direction... 
>
> (thanks to Paul Rykiel's post 
> <https://groups.google.com/forum/#%21searchin/web2py/fpdf%7Csort:relevance/web2py/OZkBWOtwtdQ/gBFdrmMmdOMJ>
>  
> re labels and responders including one Mariano Reingart)...and hope it 
> helps someone else down the road.
>
>
> pdf = receipt_PDF()
> pdf.add_page()
>
> rcpt_filename = "RCPT_%s_%s.pdf" % (session.rcpt_number, 
> session.rcpt_recipient)
> rcpt_filename = rcpt_filename.replace( ' ', '_' )
>
> rcpt_filepath = request.folder + '/static/temp/%s'%(rcpt_filename)
>
> if sys.platform.startswith( "linux" ) :
>     os.system( "xdg-open %s" %(rcpt_filepath) )
> else :
>     os.system( "%s" %(rcpt_filepath) )
>
> pdf.output(rcpt_filepath,dest='S')
> response.headers['Content-Type'] = 'application/pdf'
> return response.stream(rcpt_filepath, chunk_size=4096, request=request, 
> attachment=True, filename=rcpt_filename)
>
>
>
> so this code... 
>
>    - no longer opens the browser pdf reader,  user page does not change! 
>    - opens the open/save dialogue box with appropriate filename and 
>    allows user to save wherever desired!
>    
> but it still has one issue...
>    
>    - as well as opening the open/save dialogue box it automatically opens 
>    Adobe Reader as well and displays the file (a little overkill!)
>
> (It also creates temp files on the system that may/may not need to be 
> cleaned up - but that's for another day.)
>
>
> *Can I stop it automatically opening the file in Adobe and if so how?*
>
>
> Peter  
>
>
>
> [edit]
> There is an added bonus that kicked in somewhere the file size is 
> approximately 30% of what it was before...
>
>
>
>
> <https://lh3.googleusercontent.com/--jRqs2MNXmQ/WAPCqrSfTuI/AAAAAAAAAIw/BUYphSouFwkQV4HL61HggeRgB1lkeNT9gCLcB/s1600/file_sizes.png>
>
>
>  
>
>
>

-- 
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