I have a project at work where we are using Pylons/paster as the web service provider. One of the “clients” of this service is written in Flex/Flash, and had as a component the AlivePDF AS3 library for generating a static PDF of the Flash content.
Unfortunately, because Flash cannot save content locally, in order to actually GET this PDF content back to the user, AlivePDF posts a byte array to the service and expects the service to bundle that as a PDF and send it back. They provide a “content.php” file as an example – which, frankly, is some pretty inscrutable code until you manage to figure out what it’s working around. So when one of my employees (the one who selected AlivePDF in the first place) sent me the PHP file, it took as long to understand what he wanted as it did to come up with a Pylons solution. You can find the latter bit below – replace ${service} and ${controller} with your actual values through-out, and trim the ellipses (they are there to indicate there may be additional context on either side of the line I’m giving you):
${service}/config/routing.py:
def make_map():
…
map.connect(’/${controller}/create.php’, controller=’${controller}’, action=‘pdf’) # put this before the default routes, if you have any
…
${service}/controllers/${controller}.py:
Class ${controller}(BaseController):
…
def pdf(self):
response.headers[‘Content-Type’] = request.environ[‘CONTENT_TYPE’]
response.headers[‘Content-Disposition’] = ‘inline; filename=”%s”’ % request.GET[‘name’]
return request.environ[‘wsgi.input’].read(int(request.environ[‘CONTENT_LENGTH’]))
…