Python pdfkit.from_url() Examples
The following are 9
code examples of pdfkit.from_url().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pdfkit
, or try the search function
.
Example #1
Source File: url.py From yeti with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: wechat_public_account.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #3
Source File: restrict.py From python-automation-scripts with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: htmltopdf.py From Jarvis with MIT License | 5 votes |
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")
Example #5
Source File: geeks_for_geeks_dp.py From Scripting-and-Web-Scraping with MIT License | 5 votes |
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
Example #6
Source File: display.py From diogenes with MIT License | 5 votes |
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
Example #7
Source File: pdf_utils.py From django-htk with MIT License | 5 votes |
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
Example #8
Source File: report.py From elf_diff with GNU General Public License v3.0 | 5 votes |
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)
Example #9
Source File: html_to_pdf.py From python-tools with MIT License | 4 votes |
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)