save_web_page_as_pdf
- pyhelpers.store.save_web_page_as_pdf(web_page, path_to_pdf, page_size='A4', zoom=1.0, encoding='UTF-8', verbose=False, wkhtmltopdf_exe=None, **kwargs)
Save a web page as a PDF file by wkhtmltopdf.
- Parameters:
web_page (str) – URL of a web page or pathname of an HTML file
path_to_pdf (str) – path where a .pdf is saved
page_size (str) – page size, defaults to
'A4'
zoom (float) – a parameter to zoom in/out, defaults to
1.0
encoding (str) – encoding format defaults to
'UTF-8'
verbose (bool or int) – whether to print relevant information in console, defaults to
False
wkhtmltopdf_exe (str or None) – absolute path to ‘wkhtmltopdf.exe’, defaults to
None
; whenwkhtmltopdf_exe=None
, use the default installation path, e.g. (on Windows) “C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe”kwargs – [optional] parameters of pdfkit.from_url
Examples:
>>> from pyhelpers.store import save_web_page_as_pdf >>> from pyhelpers.dirs import cd >>> import subprocess >>> pdf_pathname = cd("tests\documents", "pyhelpers.pdf") >>> web_page_url = 'https://pyhelpers.readthedocs.io/en/latest/' >>> save_web_page_as_pdf(web_page_url, pdf_pathname) >>> # Open the PDF file using the system's default application >>> subprocess.Popen(pdf_pathname, shell=True) >>> web_page_file = cd("docs\build\html\index.html") >>> save_web_page_as_pdf(web_page_file, pdf_pathname, verbose=True) Updating "pyhelpers.pdf" at "tests\documents\" ... Done. >>> subprocess.Popen(pdf_pathname, shell=True) >>> save_web_page_as_pdf(web_page_file, pdf_pathname, verbose=2) Updating "pyhelpers.pdf" at "tests\documents\" ... Loading pages (1/6) Counting pages (2/6) Resolving links (4/6) Loading headers and footers (5/6) Printing pages (6/6) Done >>> subprocess.Popen(pdf_pathname, shell=True)