Use the Ruby Phantom object's to_string method to generate the pdf in the Middleware. This relieves the Middleware from having to read the contents of the pdf from a file.