serve a stringIO (pdf) as download python -


i have cgi python script saves matplotlib generated picture pdf stringio , png stringio. png picture shown on new page works well.

sio = cstringio.stringio() pylab.savefig(sio, format='pdf') sio.close()  sio =cstringio.stringio() print "content-type:text/html\r\n\r\n" pylab.savefig(sio, format='png', bbox_inches='tight') print "<html>" ... print "<img id='plot' src='data:image/png;base64,%s'/>" % sio.getvalue().encode('base64').strip() ... 

is there way serve pdf in stringio download. know there examples http download headers, when file located on server.

print "content-type:application/download; name=\"filename\""; print "content-disposition: attachment; filename=\"filename\""; print  f=open("filename", "rb") str = f.read(); print str f.close() 

so guess need second cgi-script download. don't know how pass stringio make downloadable pdf without saving on server.

thanks help

same exact way serving png should work (if example complete). here second snippet sent modified fit example:

fn = 'mydownload.pdf' print 'content-type:application/pdf'; print 'content-disposition: attachment; filename="%s"' %(fn); print print sio.getvalue() 

if using wsgi instead of cgi, can write straight stream.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -