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


Python pdfkit.configuration方法代码示例

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


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

示例1: generatePdfFromUrl

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

示例2: download

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

示例3: pdf

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

示例4: _call_pdfkit

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


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