コード例 #1
0
    def process_combinewiki(self, req, format, title, pages):
        # Dump all pages to HTML files
        files = [self._page_to_file(req, p) for p in pages]
        titlefile = self._page_to_file(req, title, self.TITLE_HTML % title)

        # File to write PDF to
        pfile, pfilename = mkstemp('tracpdf')
        os.close(pfile)

        # Render
        os.environ["HTMLDOC_NOCGI"] = 'yes'
        codepage = Mimeview(self.env).default_charset
        htmldoc_format = {'pdf': 'pdf14', 'ps': 'ps3'}[format]
        htmldoc_args = {
            'book': None,
            'format': htmldoc_format,
            'left': '1.5cm',
            'right': '1.5cm',
            'top': '1.5cm',
            'bottom': '1.5cm',
            'charset': codepage.replace('iso-', ''),
            'title': None,
            'titlefile': titlefile
        }
        htmldoc_args.update(dict(self.env.config.options('pagetopdf')))
        htmldoc_args.update(dict(self.env.config.options('combinewiki')))
        args_string = ' '.join([
            '--%s %s' % (arg, value or '')
            for arg, value in htmldoc_args.iteritems()
        ])
        cmd_string = 'htmldoc %s %s -f %s' % (args_string, ' '.join(files),
                                              pfilename)
        self.log.info('CombineWikiModule: Running %r', cmd_string)
        os.system(cmd_string)

        out = open(pfilename, 'rb').read()

        # Clean up
        os.unlink(pfilename)
        for f in files:
            os.unlink(f)
        os.unlink(titlefile)

        # Send the output
        req.send_response(200)
        req.send_header('Content-Type', {
            'pdf': 'application/pdf',
            'ps': 'application/postscript'
        }[format])
        req.send_header('Content-Length', len(out))
        req.end_headers()
        req.write(out)
        raise RequestDone
コード例 #2
0
ファイル: formats.py プロジェクト: nyuhuhuu/trachacks
 def process_combinewiki(self, req, format, title, pages):
     # Dump all pages to HTML files
     files = [self._page_to_file(req, p) for p in pages]
     titlefile = self._page_to_file(req, title, self.TITLE_HTML%title)
         
     # File to write PDF to
     pfile, pfilename = mkstemp('tracpdf')
     os.close(pfile)       
      
     # Render
     os.environ["HTMLDOC_NOCGI"] = 'yes'
     codepage = Mimeview(self.env).default_charset
     htmldoc_format = {'pdf': 'pdf14', 'ps':'ps3'}[format]
     htmldoc_args = { 'book': None, 'format': htmldoc_format, 'left': '1.5cm',
                      'right': '1.5cm', 'top': '1.5cm', 'bottom': '1.5cm',
                      'charset': codepage.replace('iso-', ''), 'title': None,
                      'titlefile': titlefile}
     htmldoc_args.update(dict(self.env.config.options('pagetopdf')))
     htmldoc_args.update(dict(self.env.config.options('combinewiki')))
     args_string = ' '.join(['--%s %s' % (arg, value or '') for arg, value
                             in htmldoc_args.iteritems()])
     cmd_string = 'htmldoc %s %s -f %s'%(args_string, ' '.join(files), pfilename)
     self.log.info('CombineWikiModule: Running %r', cmd_string)
     os.system(cmd_string)
         
     out = open(pfilename, 'rb').read()
         
     # Clean up
     os.unlink(pfilename)
     for f in files:
         os.unlink(f)
     os.unlink(titlefile)
           
     # Send the output
     req.send_response(200)
     req.send_header('Content-Type', {'pdf':'application/pdf', 'ps':'application/postscript'}[format])
     req.send_header('Content-Length', len(out))
     req.end_headers()
     req.write(out)
     raise RequestDone