コード例 #1
0
    def html_to_printhtml(
        self,
        req,
        html_pages,
        title='',
        subject='',
        version='',
        date='',
    ):

        self.env.log.debug('WikiPrint => Start function html_to_printhtml')

        page = Markup('<hr>'.join(html_pages))

        #TO-DO: Make a nice TOC for HTML printable output
        page = page.replace('[[pdf-toc]]', '')

        css_data = '<style type="text/css">%s</style>' % self.get_css(req)
        page = self.add_headers(req,
                                page,
                                book=False,
                                title=title,
                                subject=subject,
                                version=version,
                                date=date,
                                extra_headers=css_data)

        page = page.encode(self.default_charset, 'replace')

        return page
コード例 #2
0
ファイル: wikiprint.py プロジェクト: nyuhuhuu/trachacks
    def html_to_printhtml(self, req, html_pages, title='', subject='', version='', date='', ):
        
        self.env.log.debug('WikiPrint => Start function html_to_printhtml')

        page = Markup('<hr>'.join(html_pages))
        
        #TO-DO: Make a nice TOC for HTML printable output
        page = page.replace('[[pdf-toc]]','')        
        
        css_data = '<style type="text/css">%s</style>' % self.get_css(req)
        page = self.add_headers(req, page, book=False, title=title, subject=subject, version=version, date=date, extra_headers = css_data)

        page = page.encode(self.default_charset, 'replace')
        
        return page
コード例 #3
0
ファイル: wikiprint.py プロジェクト: nyuhuhuu/trachacks
    def html_to_pdf(self, req, html_pages, book=True, title='', subject='', version='', date=''):
        
        self.env.log.debug('WikiPrint => Start function html_to_pdf')

        page = Markup('\n<div><pdf:nextpage /></div>'.join(html_pages))
        
        #Replace PageOutline macro with Table of Contents
        if book:
            #If book, remove [[TOC]], and add at beginning
            page = page.replace('[[pdf-toc]]','')
            page = Markup(self.get_toc()) + Markup(page)
        else:
            page = page.replace('[[pdf-toc]]',self.get_toc())

        page = self.add_headers(req, page, book, title=title, subject=subject, version=version, date=date)
        page = page.encode(self.default_charset, 'replace')
        css_data = self.get_css(req)

        pdf_file = StringIO.StringIO()

        auth_cookie = hex_entropy()
        loader = linkLoader(self.env, req, auth_cookie)

        #Temporary authentication
        self.env.log.debug("Storing temporary auth cookie %s for user %s", auth_cookie, req.authname)
        db = self.env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute("INSERT INTO auth_cookie (cookie,name,ipnr,time) "
            "VALUES (%s, %s, %s, %s)", (auth_cookie, req.authname, '127.0.0.1', int(time.time())))
        db.commit()        
        
        pdf = pisa.CreatePDF(page, pdf_file, show_errors_as_pdf = True, default_css = css_data, link_callback = loader.getFileName)
        out = pdf_file.getvalue()
        pdf_file.close()
        
        cursor.execute("DELETE FROM auth_cookie WHERE cookie=%s", (auth_cookie,))
        db.commit()        

        self.env.log.debug('WikiPrint => Finish function html_to_pdf')

        return out
コード例 #4
0
    def html_to_pdf(self,
                    req,
                    html_pages,
                    book=True,
                    title='',
                    subject='',
                    version='',
                    date=''):

        self.env.log.debug('WikiPrint => Start function html_to_pdf')

        page = Markup('\n<div><pdf:nextpage /></div>'.join(html_pages))

        #Replace PageOutline macro with Table of Contents
        if book:
            #If book, remove [[TOC]], and add at beginning
            page = page.replace('[[pdf-toc]]', '')
            page = Markup(self.get_toc()) + Markup(page)
        else:
            page = page.replace('[[pdf-toc]]', self.get_toc())

        page = self.add_headers(req,
                                page,
                                book,
                                title=title,
                                subject=subject,
                                version=version,
                                date=date)
        page = page.encode(self.default_charset, 'replace')
        css_data = self.get_css(req)

        pdf_file = StringIO.StringIO()

        auth_cookie = hex_entropy()
        loader = linkLoader(self.env, req, auth_cookie)

        #Temporary authentication
        self.env.log.debug("Storing temporary auth cookie %s for user %s",
                           auth_cookie, req.authname)
        db = self.env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute(
            "INSERT INTO auth_cookie (cookie,name,ipnr,time) "
            "VALUES (%s, %s, %s, %s)",
            (auth_cookie, req.authname, '127.0.0.1', int(time.time())))
        db.commit()

        pdf = pisa.CreatePDF(page,
                             pdf_file,
                             show_errors_as_pdf=True,
                             default_css=css_data,
                             link_callback=loader.getFileName)
        out = pdf_file.getvalue()
        pdf_file.close()

        cursor.execute("DELETE FROM auth_cookie WHERE cookie=%s",
                       (auth_cookie, ))
        db.commit()

        self.env.log.debug('WikiPrint => Finish function html_to_pdf')

        return out