tags: Python Software architecture / technology selection reptile linux
Official website: https://wkhtmltopdf.org/
wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely “headless” and do not require a display or display service.
WKHTMLTOPDF and WKHTMLTOIMAGE are open source (LGPLV3) command line tools, you can use the Qt Webkit rendering engine to render HTML to PDF and various image formats using the Qt WebKit rendering engine. These complete "Headless" runs without interface or interface services.
If you like, it is still a C library.
WKHTMLTOPDF is a "command line tool" that supports multiple platforms, which can be run under Win, Linux, OS X.
Download pre-compiledbinary fileOr fromSource codeConstruct
Create an HTML document to be converted to PDF (or images)
Run your HTML document through this tool.
Problem Description:
Execute WKHTMLTOPDF -V error error While Loading Shared Libraries: libjpeg.so.62: Cannot Open Shared Object File: No Such File or Directory
Solution:
apt-get install libjpeg62-dev
1Yum Install -Y Fontconfig Mkfontscale or
apt-get -y install fontconfig xfonts-utils
2 download font file (TTF file) put into / usr / share / fonts
3 implement three orders
mkfontscale
mkfontdir
fc-cache
pip3 install pdfkit
Note: PDFKit is a Python package based on Wkhtmltopdf, so you need to install WKHTMLTOPDF. WKHTMLTOPDF is a lightweight software, which is very easy to install.
Download address: https://wkhtmltopdf.org/downloads.html
#
import pdfkit
'' Generates the pdf file '' '
def url_to_pdf(url, to_file):
# Incorporate the WKHTMLTOPDF.EXE program absolute path to config object
path_wkthmltopdf = r'D:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
# Generate a PDF file, TO_FILE is the file path
pdfkit.from_url(url, to_file, configuration=config)
print('Finish')
# URL, convert to PDF
url_to_pdf(r'https://zhuanlan.zhihu.com/p/69869004', 'out_1.pdf')
#
import pdfkit
'' 'Generates the HTML file' '' '
def html_to_pdf(html, to_file):
# Incorporate the WKHTMLTOPDF.EXE program absolute path to config object
path_wkthmltopdf = r'D:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
# Generate a PDF file, TO_FILE is the file path
pdfkit.from_file(html, to_file, configuration=config)
print('Finish')
html_to_pdf('sample.html','out_2.pdf')
import pdfkit
def str_to_pdf(string, to_file):
# Incorporate the WKHTMLTOPDF.EXE program absolute path to config object
path_wkthmltopdf = r'D:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
# Generate a PDF file, TO_FILE is the file path
pdfkit.from_string(string, to_file, configuration=config)
print('Finish')
if __name__ == '__main__':
str_to_pdf('This is test!', 'out_str_to_pdf.pdf')
Python generates PDF (PDFKIT library)
Reference URL: https://www.jianshu.com/p/489c3aff61bd/
wkhtmltopdf download address Remember to install pdfkit pip install pdfkit Pay attention to the garbled characters in the following figure, it must be the following three wrong methods operatio...
First, style problem 1. When using Vue + Elementui, it is found that some components cannot export PDF, which can only use traditional HTML and CSS layout, which exported PDF clearer 2, you need to pu...
Convert html to pdf tool under python, personally think that pdfcrowd and pdfkit are better to use. Here we mainly introduce how to use it under mac, similar to other operating systems. One, pdfcrowd ...
When writing code documents in jupyter notebook, sometimes you need to export the pdf version, but jupyter will report an error. I was thinking that apart from the online debug method, there is no oth...
Problem Description Opened normally with a browser, but you can't see anything after converting to a PDF document using the tool wkhtmltopdf. The html code is as follows: The CSS code is as follows: O...
First, what is wkhtmltopdf? Wkhtmltopdf is an open source, command-line tool that uses Qt WebKit rendering engine to convert html to pdf files. Wkhtmltopdf There is also a twin brother, wkhtmltoimage,...
Water spinach Need to finish reading 5minute Speed reading only takes 2 minutes Here is a recommended tool for converting HTML to PDF, Wkhtmltopdf, which is installed and used as follows. 1 &...
The company needs to generate some of the part of the HTML page generate a PDF file, and then I will find some classes that use PHP to enclose the HTML page into a PDF file. The method is that it has ...
1, use the background Recently, the company needs to generate pdf and download the contents of the html page. I tried many methods and did not have satisfactory results. Later, I found the software wk...