本文整理汇总了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)
示例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)
示例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)
示例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")
示例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
示例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
示例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
示例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
示例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)