Python pdfkit.configuration() Examples

The following are 4 code examples of pdfkit.configuration(). 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: restrict.py    From python-automation-scripts with GNU General Public License v3.0 6 votes vote down vote up
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 #2
Source File: download.py    From spider with MIT License 6 votes vote down vote up
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) 
Example #3
Source File: geeks_for_geeks_dp.py    From Scripting-and-Web-Scraping with MIT License 5 votes vote down vote up
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 #4
Source File: logic.py    From janeway with GNU Affero General Public License v3.0 5 votes vote down vote up
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