1# -*- coding: utf-8 -*-
2from .imgkit import IMGKit
3from .config import Config
4
5
6def from_url(url,
7             output_path,
8             options=None,
9             toc=None,
10             cover=None,
11             config=None,
12             cover_first=None):
13    """
14    Convert URL/URLs to IMG file/files
15
16    :param url: URL or list of URLs to be saved
17    :param output_path: path to output PDF file/files. False means file will be returned as string
18    :param options: (optional) dict with wkhtmltopdf global and page options, with or w/o '--'
19    :param toc: (optional) dict with toc-specific wkhtmltopdf options, with or w/o '--'
20    :param cover: (optional) string with url/filename with a cover html page
21    :param css: style of input
22    :param config: (optional) instance of imgkit.config.Config()
23    :param cover_first: (optional) if True, cover always precedes TOC
24    :return: True when success
25    """
26    rtn = IMGKit(url,
27                 'url',
28                 options=options,
29                 toc=toc, cover=cover,
30                 config=config,
31                 cover_first=cover_first)
32    return rtn.to_img(output_path)
33
34
35def from_file(filename,
36              output_path,
37              options=None,
38              toc=None,
39              cover=None,
40              css=None,
41              config=None,
42              cover_first=None):
43    """
44    Convert HTML file/files to IMG file/files
45
46    :param filename: path of HTML file or list with paths or file-like object
47    :param output_path: path to output PDF file/files. False means file will be returned as string
48    :param options: (optional) dict with wkhtmltopdf global and page options, with or w/o '--'
49    :param toc: (optional) dict with toc-specific wkhtmltopdf options, with or w/o '--'
50    :param cover: (optional) string with url/filename with a cover html page
51    :param css: style of input
52    :param config: (optional) instance of imgkit.config.Config()
53    :param cover_first: (optional) if True, cover always precedes TOC
54    :return: True when success
55    """
56    rtn = IMGKit(filename,
57                 'file',
58                 options=options,
59                 toc=toc,
60                 cover=cover,
61                 css=css,
62                 config=config,
63                 cover_first=cover_first)
64    return rtn.to_img(output_path)
65
66
67def from_string(string,
68                output_path,
69                options=None,
70                toc=None,
71                cover=None,
72                css=None,
73                config=None,
74                cover_first=None):
75    """
76    Convert given string/strings to IMG file
77
78    :param string:
79    :param output_path: path to output PDF file/files. False means file will be returned as string
80    :param options: (optional) dict with wkhtmltopdf global and page options, with or w/o '--'
81    :param toc: (optional) dict with toc-specific wkhtmltopdf options, with or w/o '--'
82    :param cover: (optional) string with url/filename with a cover html page
83    :param css: style of input
84    :param config: (optional) instance of imgkit.config.Config()
85    :param cover_first: (optional) if True, cover always precedes TOC
86    :return: True when success
87    """
88    rtn = IMGKit(string, 'string', options=options, toc=toc, cover=cover, css=css,
89                 config=config, cover_first=cover_first)
90    return rtn.to_img(output_path)
91
92
93def config(**kwargs):
94    """
95    Constructs and returns a :class:`Config` with given options
96
97    :param wkhtmltopdf: path to binary
98    :param meta_tag_prefix: the prefix for ``pdfkit`` specific meta tags
99    """
100
101    return Config(**kwargs)
102