Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pdfkit/api.py : 46%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
3from .pdfkit import PDFKit
4from .pdfkit import Configuration
7def from_url(url, output_path, options=None, toc=None, cover=None,
8 configuration=None, cover_first=False):
9 """
10 Convert file of files from URLs to PDF document
12 :param url: URL or list of URLs to be saved
13 :param output_path: path to output PDF file. False means file will be returned as string.
14 :param options: (optional) dict with wkhtmltopdf global and page options, with or w/o '--'
15 :param toc: (optional) dict with toc-specific wkhtmltopdf options, with or w/o '--'
16 :param cover: (optional) string with url/filename with a cover html page
17 :param configuration: (optional) instance of pdfkit.configuration.Configuration()
18 :param configuration_first: (optional) if True, cover always precedes TOC
20 Returns: True on success
21 """
23 r = PDFKit(url, 'url', options=options, toc=toc, cover=cover,
24 configuration=configuration, cover_first=cover_first)
26 return r.to_pdf(output_path)
29def from_file(input, output_path, options=None, toc=None, cover=None, css=None,
30 configuration=None, cover_first=False):
31 """
32 Convert HTML file or files to PDF document
34 :param input: path to HTML file or list with paths or file-like object
35 :param output_path: path to output PDF file. False means file will be returned as string.
36 :param options: (optional) dict with wkhtmltopdf options, with or w/o '--'
37 :param toc: (optional) dict with toc-specific wkhtmltopdf options, with or w/o '--'
38 :param cover: (optional) string with url/filename with a cover html page
39 :param css: (optional) string with path to css file which will be added to a single input file
40 :param configuration: (optional) instance of pdfkit.configuration.Configuration()
41 :param configuration_first: (optional) if True, cover always precedes TOC
43 Returns: True on success
44 """
46 r = PDFKit(input, 'file', options=options, toc=toc, cover=cover, css=css,
47 configuration=configuration, cover_first=cover_first)
49 return r.to_pdf(output_path)
52def from_string(input, output_path, options=None, toc=None, cover=None, css=None,
53 configuration=None, cover_first=False):
54 """
55 Convert given string or strings to PDF document
57 :param input: string with a desired text. Could be a raw text or a html file
58 :param output_path: path to output PDF file. False means file will be returned as string.
59 :param options: (optional) dict with wkhtmltopdf options, with or w/o '--'
60 :param toc: (optional) dict with toc-specific wkhtmltopdf options, with or w/o '--'
61 :param cover: (optional) string with url/filename with a cover html page
62 :param css: (optional) string with path to css file which will be added to a input string
63 :param configuration: (optional) instance of pdfkit.configuration.Configuration()
64 :param configuration_first: (optional) if True, cover always precedes TOC
66 Returns: True on success
67 """
69 r = PDFKit(input, 'string', options=options, toc=toc, cover=cover, css=css,
70 configuration=configuration, cover_first=cover_first)
72 return r.to_pdf(output_path)
75def configuration(**kwargs):
76 """
77 Constructs and returns a :class:`Configuration` with given options
79 :param wkhtmltopdf: path to binary
80 :param meta_tag_prefix: the prefix for ``pdfkit`` specific meta tags
81 """
83 return Configuration(**kwargs)