当前位置: 首页>>代码示例>>Python>>正文


Python pdfkit.from_file方法代码示例

本文整理汇总了Python中pdfkit.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python pdfkit.from_file方法的具体用法?Python pdfkit.from_file怎么用?Python pdfkit.from_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pdfkit的用法示例。


在下文中一共展示了pdfkit.from_file方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_pdf_report

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def make_pdf_report(
        template_data,
        pdf_report_path):
    with tempfile.NamedTemporaryFile(mode='w', suffix='.html') as f:
        _make_report(template_data, f, 'templates/template.html')
        f.flush()

        options = {
            'zoom': 0.55,
            'margin-top': '20mm'
        }

        if sys.platform in ('linux', 'linux2'):
            # pdfkit uses wkhtmltopdf, which doesn't work on headless servers;
            # recommended workaround is to use xvfb, as documented here:
            # https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2037#issuecomment-62019521
            from xvfbwrapper import Xvfb
            logger.info('Running pdfkit inside xvfb wrapper')
            with Xvfb():
                pdfkit.from_file(f.name, pdf_report_path, options=options)

        else:
            pdfkit.from_file(f.name, pdf_report_path, options=options)
    logger.info('Wrote PDF report to %s', pdf_report_path) 
开发者ID:openvax,项目名称:vaxrank,代码行数:26,代码来源:report.py

示例2: create_report

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def create_report():
    report_text = read_report_html()
    fields = parse_report_fields_from_text(report_text)
    for field in fields:
        report_text = report_text.replace(
            '~{}~'.format(field), ReportsPanel.fields_values[bpy.context.scene.reports_files][field])
    new_html_fname = op.join(_addon().get_output_path(), '{}.html'.format(
        bpy.context.scene.reports_files.replace(' ', '_')))
    with open(new_html_fname, 'w') as html_file:
        html_file.write(report_text)
    output_fname = mu.change_fname_extension(new_html_fname, 'pdf')
    pdfkit.from_file(new_html_fname, output_fname)
    try:
        import webbrowser
        webbrowser.open_new(output_fname)
    except:
        print('The new report can be found here: {}'.format(output_fname))
        pass 
开发者ID:pelednoam,项目名称:mmvt,代码行数:20,代码来源:reports_panel.py

示例3: download

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def download(links):
    num = 1
    for i in links:
        xtm = requests.get(url = 'http://www.hzcourse.com/resource/readBook?path=' + str(i),headers=headers)
        soup = BeautifulSoup(xtm.text,'lxml')
        for img in soup.find_all('img'):
            img['src'] = 'http://www.hzcourse.com/resource/readBook?path=/openresources/teach_ebook/uncompressed/18563/OEBPS/Text/' + img['src']
        article = str(soup).encode('utf-8')
        with open(str(num) + '.html','wb') as f:
            f.write(article)
            f.close()
        try:
            pdfkit.from_file(str(num) + '.html',str(num) + '.pdf',configuration=config,options=options)
        except Exception as e:
            print('Error for ' + str(e) + ',Page :' + str(num))
        num += 1
        sleep(1) 
开发者ID:biubiuww,项目名称:spider,代码行数:19,代码来源:download.py

示例4: makePDF

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def makePDF(html,path):
    infile = path+"str.html"
    outfile = path+"tmp.pdf"
    with open(infile,'w') as f:
        f.write(html)
    pdfkit.from_file(infile, outfile)
    outbytes = ""
    with open(outfile, 'r') as f:
        outbytes = f.read()
    return outbytes 
开发者ID:rapid7,项目名称:insightconnect-plugins,代码行数:12,代码来源:action.py

示例5: html_to_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def html_to_pdf(input, output, type='string'):
    """Convert HTML/webpage to PDF. For linux, install: sudo apt-get install wkhtmltopdf.

    Args:
        input (str): HTML Text, URL or file.
        output (str): Output file (.pdf).
        type (str): Types can be 'string', 'url' or 'file'.

    """
    if type == 'url':
        pdfkit.from_url(input, output)
    elif type == 'file':
        pdfkit.from_file(input, output)
    else:
        pdfkit.from_string(input, output) 
开发者ID:lucasayres,项目名称:python-tools,代码行数:17,代码来源:html_to_pdf.py

示例6: generate_pdf_report

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def generate_pdf_report(session_name):
    html_filepath = generate_html_report(session_name)
    return pdfkit.from_file(html_filepath, ROOT_DIR + SEP + session_name + SEP + 'report' + SEP + 'report.pdf') 
开发者ID:scorelab,项目名称:OpenMF,代码行数:5,代码来源:report_helper.py

示例7: __call__

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def __call__(self, jarvis, s):
        if not s:
            jarvis.say("please enter a file name after calling the plugin")
        elif "html" not in s:
            jarvis.say("Your file must end with '.html'")
        else:
            try:
                pdfkit.from_file(s, s.replace('.html', '') + '.pdf')
            except OSError as err:
                jarvis.say("OS error: {0}".format(err) + "\nMake sur your file is in the source directory of Jarvis and is an html file") 
开发者ID:sukeesh,项目名称:Jarvis,代码行数:12,代码来源:htmltopdf.py

示例8: save_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def save_pdf(htmls, file_name):

    options = {

        'page-size': 'Letter',

        'margin-top': '0.75in',

        'margin-right': '0.75in',

        'margin-bottom': '0.75in',

        'margin-left': '0.75in',

        'encoding': "UTF-8",

        'custom-header': [

            ('Accept-Encoding', 'gzip')

        ],

        'cookie': [

            ('cookie-name1', 'cookie-value1'),

            ('cookie-name2', 'cookie-value2'),

        ],

        'outline-depth': 10,

    }

    pdfkit.from_file(htmls, file_name, options=options) 
开发者ID:yyyy777,项目名称:crawler,代码行数:37,代码来源:liaoxuefeng_pdf.py

示例9: _call_pdfkit

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def _call_pdfkit(self, html_file, uuid_directory_name, uuid_file_name):
        """ Runs wkhtmltopdf to create a PDF file.

        :param html_file: the input HTML
        :param uuid_directory_name: the temporary directory on which we are working
        :param uuid_file_name: the XML UUID file name from which the HTML was derived
        :return: the output file path
        """
        pdfkit_options = {
            'margin-top': '0',
            'margin-right': '0',
            'margin-bottom': '0',
            'margin-left': '0',
            'encoding': 'UTF-8',
            'javascript-delay': '9000',
            'no-stop-slow-scripts': '',
        }

        pdfkit_config = pdfkit.configuration(
            wkhtmltopdf=bytes(os.path.join(self.current_path, 'cassius/' 'bin', 'wkhtmltopdf'), 'utf-8')
        )

        pdfkit_output_file = '{0}.pdf'.format(os.path.join(uuid_directory_name, uuid_file_name))

        pdfkit.from_file(html_file, pdfkit_output_file, options=pdfkit_options, configuration=pdfkit_config)

        return pdfkit_output_file 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:29,代码来源:logic.py

示例10: convert_html_to_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def convert_html_to_pdf(html_file,pdf_file):
    """ Converts html file to pdf file
    """
    options = {
        'page-size': 'A4',
        'margin-top': '0.1in',
        'margin-right': '0.1in',
        'margin-bottom': '0.1in',
        'margin-left': '0.1in',
        'encoding': "UTF-8",
        'no-outline': None
    }
    pdfkit.from_file(html_file,pdf_file,options)
    BuiltIn().log("Converted `%s` to `%s`" % (html_file,pdf_file)) 
开发者ID:bachng2017,项目名称:RENAT,代码行数:16,代码来源:Common.py

示例11: make_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def make_pdf(htmls):
    html_files = []
    for index, html in enumerate(htmls):
        file = str(index) + ".html"
        html_files.append(file)
        with open(file, "w", encoding="utf-8") as f:
            f.write(html)

    options = {
        "user-style-sheet": "test.css",
        "page-size": "Letter",
        "margin-top": "0.75in",
        "margin-right": "0.75in",
        "margin-bottom": "0.75in",
        "margin-left": "0.75in",
        "encoding": "UTF-8",
        "custom-header": [("Accept-Encoding", "gzip")],
        "cookie": [
            ("cookie-name1", "cookie-value1"), ("cookie-name2", "cookie-value2")
        ],
        "outline-depth": 10,
    }
    try:
        pdfkit.from_file(html_files, "电子书.pdf", options=options)
    except Exception as e:
        pass

    for file in html_files:
        os.remove(file)

    print("已制作电子书在当前目录!") 
开发者ID:96chh,项目名称:crawl-zsxq,代码行数:33,代码来源:crawl.py

示例12: create_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def create_pdf(self):
        """
        Convert HTML report to PDF
        """

        try:  # check if varcode and pyensembl is available (necessary for Windows)
            import pdfkit

        except ImportError:
            logger.warning('PDFKIT not available and hence no PDF of the HTML report was created.')
            return

        pdf_filepath = self.filepath.replace('.html', '.pdf')

        options = {
            'zoom': settings.ZOOM,
            'dpi': 400,
            # 'print-media-type': '',
            'page-size': 'Letter',
            'margin-top': '1in',
            'margin-right': '0.75in',
            'margin-bottom': '1in',
            'margin-left': '0.75in',
            'disable-smart-shrinking': '',
            'quiet': ''

            # 'encoding': "UTF-8",
            # 'custom-header': [
            #     ('Accept-Encoding', 'gzip')
            # ]
            # 'cookie': [
            #     ('cookie-name1', 'cookie-value1'),
            #     ('cookie-name2', 'cookie-value2'),
            # ],
            # 'no-outline': None
        }

        pdfkit.from_file(self.filepath, pdf_filepath, options=options) 
开发者ID:johannesreiter,项目名称:treeomics,代码行数:40,代码来源:html_report.py

示例13: create_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def create_pdf(html_fname, pdf_fname):
    pdfkit.from_file(html_fname, pdf_fname) 
开发者ID:pelednoam,项目名称:mmvt,代码行数:4,代码来源:create_report.py

示例14: make_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_file [as 别名]
def make_pdf(htmls):
    html_files = []
    for index, html in enumerate(htmls):
        file = str(index) + ".html"
        html_files.append(file)
        with open(file, "w", encoding="utf-8") as f:
            f.write(html)

    options = {
        "user-style-sheet": "temp.css",
        "page-size": "Letter",
        "margin-top": "0.75in",
        "margin-right": "0.75in",
        "margin-bottom": "0.75in",
        "margin-left": "0.75in",
        "encoding": "UTF-8",
        "custom-header": [("Accept-Encoding", "gzip")],
        "cookie": [
            ("cookie-name1", "cookie-value1"), ("cookie-name2", "cookie-value2")
        ],
        "outline-depth": 10,
    }
    try:
        pdfkit.from_file(html_files, PDF_FILE_NAME, options=options)
    except Exception as e:
        pass

    if DELETE_HTML_WHEN_DONE:
        for file in html_files:
            os.remove(file)

    print("电子书生成成功!") 
开发者ID:wbsabc,项目名称:zsxq-spider,代码行数:34,代码来源:crawl.py


注:本文中的pdfkit.from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。