Beispiel #1
0
 def deliver(self, pdf_filename):
     """Stream generated PDF file back to client.
     """
     log.info("Deliver %s" % pdf_filename)
     request = self.request.RESPONSE
     request.setHeader("content-type", "application/pdf")
     request.setHeader("content-length", os.stat(pdf_filename)[6])
     request.setHeader("content-disposition", "attachment; filename=%s" % pdf_filename)
     return filestream_iterator(pdf_filename, "rb")
Beispiel #2
0
    def convert(self, fo_filename, output_filename=None):

        if not output_filename:
            output_filename = newTempfile(suffix='.pdf')

        cmd = 'fop -fo "%s" -pdf "%s"' % (fo_filename, output_filename)

        status, output = runcmd(cmd)
        if status != 0:
            raise RuntimeError('Error executing: %s\n\n%s' % (cmd, output))
        log.info("\n")

        return output_filename
Beispiel #3
0
def runcmd(cmd):
    """ Execute a command using the subprocess module """


    stdin = open('/dev/null')
    stdout = stderr = PIPE

    p = Popen(cmd,
              shell=True,
              stdin=stdin,
              stdout=stdout,
              stderr=stderr,
              )

    status = p.wait()
    stdout_ = p.stdout.read().strip()
    stderr_ = p.stderr.read().strip()

    if stdout_:
        log.info(stdout_)
    if stderr_:
        log.info(stderr_)
    return status, stdout_ + stderr_