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


Python pdfkit.from_url方法代码示例

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


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

示例1: save_as_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_url [as 别名]
def save_as_pdf(self, results, url):
        tmpdir = mkdtemp()

        try:
            options = {"load-error-handling": "ignore"}

            pdfkit.from_url(url, path.join(tmpdir, 'out.pdf'), options=options)

            with open(path.join(tmpdir, 'out.pdf'), 'rb') as pdf:
                pdf_import = AttachedFile.from_content(
                    pdf, 'import.pdf', 'application/pdf')

            results.investigation.update(import_document=pdf_import)
        except Exception as e:
            print(e)

        rmtree(tmpdir) 
开发者ID:yeti-platform,项目名称:yeti,代码行数:19,代码来源:url.py

示例2: get_list_data

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_url [as 别名]
def get_list_data(offset):
    res = requests.get(base_url, headers=headers, params=get_params(offset), cookies=cookies)
    data = json.loads(res.text)
    can_msg_continue = data['can_msg_continue']
    next_offset = data['next_offset']

    general_msg_list = data['general_msg_list']
    list_data = json.loads(general_msg_list)['list']

    for data in list_data:
        try:
            if data['app_msg_ext_info']['copyright_stat'] == 11:
                msg_info = data['app_msg_ext_info']
                title = msg_info['title']
                content_url = msg_info['content_url']
                # 自己定义存储路径
                pdfkit.from_url(content_url, '/home/wistbean/wechat_article/'+title+'.pdf')
                print('获取到原创文章:%s : %s' % (title, content_url))
        except:
            print('不是图文')

    if can_msg_continue == 1:
        time.sleep(1)
        get_list_data(next_offset) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:26,代码来源:wechat_public_account.py

示例3: html_to_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_url [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

示例4: __call__

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_url [as 别名]
def __call__(self, jarvis, s):
        if not s:
            jarvis.say("please enter an url after calling the plugin")
        elif '.' not in s:
            jarvis.say("please make sur your url is valid")
        else:
            try:
                pdfkit.from_url(s, s + '.pdf')
            except IOError as err:
                jarvis.say("IO error: {0}".format(err) + "\nMake sure your URL is valid and that you have access to the internet") 
开发者ID:sukeesh,项目名称:Jarvis,代码行数:12,代码来源:htmltopdf.py

示例5: pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_url [as 别名]
def pdf(type, data):
    current_dir = os.getcwd()
    folder = os.path.join(current_dir, type)
    if not os.path.exists(folder):
        os.mkdir(folder)

    for problem_name in data[type]:
        link = data[type][problem_name]
        pdf_name = problem_name + ".pdf"
        try:
            pdfkit.from_url(link, os.path.join(folder, pdf_name), configuration=config)
        except:
            pass 
开发者ID:umangahuja1,项目名称:Scripting-and-Web-Scraping,代码行数:15,代码来源:geeks_for_geeks_dp.py

示例6: to_pdf

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_url [as 别名]
def to_pdf(self, options={}, verbose=True):
        """Generates a pdf

        Parameters
        ----------
        options : dict
            options are pdfkit.from_url options. See 
            https://pypi.python.org/pypi/pdfkit
        verbose : bool
            iff True, gives output regarding pdf creation 

        Returns
        -------
        Path of generated pdf
        """

        if verbose:
            print 'Generating report...'
        with open(self.__html_src_path, 'w') as html_out:
            html_out.write(self.__get_header())
            html_out.write('\n'.join(self.__objects))
            html_out.write(self.__get_footer())
        if not verbose:
            options['quiet'] = ''
        pdfkit.from_url(self.__html_src_path, self.__report_path, 
                        options=options)
        report_path = self.get_report_path()
        if verbose:
            print 'Report written to {}'.format(report_path)
        return report_path 
开发者ID:dssg,项目名称:diogenes,代码行数:32,代码来源:display.py

示例7: generatePdfFromUrl

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_url [as 别名]
def generatePdfFromUrl():
	options = {
            'quiet':'',
            'page-size':'A4',
            'dpi':300,
            'disable-smart-shrinking':'',
        }

	path_wkthmltopdf=b'C:\\Program Files (x86)\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'  #can also be done via Envt. Settings in windows!
	config=pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
	inFile="trimmed.txt"
	count=countLines(inFile)
	#print(count)
	with open(inFile,"r") as url_read:
		for i in range(2,count-209):
			urlLine=url_read.readline()
			trimmedUrlLineList=urlLine.rsplit('/',1)
			trimmedUrlLineWithoutStrip=str(trimmedUrlLineList[-1])
			trimmedUrlLine=trimmedUrlLineWithoutStrip.rstrip()
			#print(trimmedUrlLine)  #phew! finally extracted the url content!!
			if checkFileExists(trimmedUrlLine,i)==True:
				print("Pdf Already Generated")
			else:
				print("Generating pdf for URL:\n"+urlLine)
				#pdfkit.from_url(url=urlLine, output_path=str(i)+". "+trimmedUrlLine+'.pdf',configuration=config,options=options)
				time.sleep(3)
			i=i+1 
开发者ID:avidLearnerInProgress,项目名称:python-automation-scripts,代码行数:29,代码来源:restrict.py

示例8: render_url_to_pdf_response

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_url [as 别名]
def render_url_to_pdf_response(url):
    from htk.lib.slack.utils import webhook_call
    webhook_call(text=url)
    import pdfkit
    pdf = pdfkit.from_url(url, False, options=WKHTMLTOPDF_OPTIONS)
    if pdf:
        response = HttpResponse(pdf, content_type='application/pdf')
    else:
        response = HttpResponseServerError('Error generating PDF file')
    return response 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:12,代码来源:pdf_utils.py

示例9: generate

# 需要导入模块: import pdfkit [as 别名]
# 或者: from pdfkit import from_url [as 别名]
def generate(self):
      
      import codecs
            
      if self.settings.html_file:
         html_file = self.settings.html_file
      else:
         html_file = "elf_diff_" + self.getReportBasename() + ".html"
         
      print("Writing html file " + html_file)
      with codecs.open(html_file, "w", "utf-8") as f:
         self.writeHTML(f)
         
      if self.settings.pdf_file:
         
         import tempfile
         
         tmp_html_file = tempfile._get_default_tempdir() + \
            "/" + next(tempfile._get_candidate_names()) + ".html"
                
         with codecs.open(tmp_html_file, "w", "utf-8") as f:
            self.writeHTML(f, skip_details = True)
         
         import pdfkit
         pdfkit.from_url(tmp_html_file, self.settings.pdf_file)
         
         import os
         os.remove(tmp_html_file) 
开发者ID:CapeLeidokos,项目名称:elf_diff,代码行数:30,代码来源:report.py


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