where can I find the Styling of WKHTMLtoPDF?
I need to change some output options.


You mean generic styling? Here it is: http://wkhtmltopdf.org/usage/wkhtmltopdf.txt

yes and no.
I mean where to change the behavior of ERPNexts API Implementation.

You will have to be little bit more specific about what you want to change so that we can provide better answer.

Thanks for your reply.
What I want to do:

  • Add borderless background

Actually I “hacked” the “Fullpage” view to be borderless but the PDF output still got a 2 cm border. I want to get rid of that.

You can add something like this in your print format CSS.

.print-format {
margin-top: 0mm;
margin-left: 0mm;
margin-right: 0mm;

Hi @daniel,

Frappe uses the python-pdfkit library to communicate with wkhtmltopdf.

Please check the from_string method , in from_string you can send the css data as argument.

Thanks, Makarand


@makarand_b ,

thanks for your message. I read the docs and adjusted the settings accordingly.

Unfortunately it changed not much - see screenshot:

I would like to have the black box be borderless on the sheet.


Where did you change it?

I created a new css file called “borderless.css” with:

.print-format p {
margin-left: 1px;
margin-right: 1px;
.print-format {
background-color: white;
box-shadow: 0px 0px 9px rgba(0,0,0,0.5);
max-width: 8.3in;
min-height: 11.69in;
padding: 0.0in;

and edited the api.py with the file path:

r = PDFKit(input, ‘string’, options=options, toc=toc, cover=cover, css=‘/home/frappe/frappe-bench/apps/frappe/frappe/templates/styles/borderless.css’,

Try specifically:
margin-top: 0mm;
margin-bottom: 0mm;
margin-left: 0mm;
margin-right: 0mm;

wkhtmltopdf by default have some margin.

thank you.
Please see here:

But the output still looks different :frowning:

Change that background-color to black. :yum:

this would make the whole page black :wink:
But the “black box” is defined in standard.html as letterhead.

As described it works perfectly for “Fullpage” and when I export it in Safari using “Export as” but since we are also using Firefox and Chrome I would need the “original PDF API” to be changed to borderless.

Read this thread. Looks like it is WKHTMLtoPDF issue. http://stackoverflow.com/questions/6057781/wkhtmltopdf-with-full-page-background

I was able to print from Command Line without border as described in the net.
But I was not able to print over the api :confused:


thanks @all

I guess a deeper look solved the problem:

You can specify all wkhtmltopdf options. You can drop '--' in option name. If option without value, use None, False or '' for dict value:. For repeatable options (incl. allow, cookies, custom-header, post, postfile, run-script, replace) you may use a list or a tuple. With option that need multiple values (e.g. --custom-header Authorization secret) we may use a 2-tuple.

options = {
    'page-size': 'Letter',
    'margin-top': '0.75in',
    'margin-right': '0.75in',
    'margin-bottom': '0.75in',
    'margin-left': '0.75in',
    'encoding': "UTF-8",
    'cookies': [
        ('cookie-name1', 'cookie-value1'),
        ('cookie-name2', 'cookie-value2'),
    'no-outline': None

pdfkit.from_url('http://google.com', 'out.pdf', options=options) 

From here:


First of all thanks for reopening.

The documentation is very good and it works with command-line printing but the API does not allow to print borderless. Is there a chance to verify if i made a mistake?

What I tried so far:

def from_string(input, output_path, options='-T 0 -B 0 -L 0 -R 0', toc=None, cover=None, css=None,
    Convert given string or strings to PDF document

    :param input: string with a desired text. Could be a raw text or a html file
    :param output_path: path to output PDF file. False means file will be returned as string.
    :param options: (optional) dict with wkhtmltopdf options, with or w/o '--'
    :param toc: (optional) dict with toc-specific wkhtmltopdf options, with or w/o '--'
    :param cover: (optional) string with url/filename with a cover html page
    :param css: (optional) string with path to css file which will be added to a input string
    :param configuration: (optional) instance of pdfkit.configuration.Configuration()

    Returns: True on success

    options2 = {
    'page-size': 'A4',
    'margin-top': '0.0in',
    'margin-right': '0.0in',
    'margin-bottom': '0.0in',
    'margin-left': '0.0in',
    'encoding': "UTF-8",
    'no-outline': None

    r = PDFKit(input, 'string', options='-T 0 -B 0 -L 0 -R 0', toc=toc, cover=cover, css='/home/frappe/frappe-bench/apps/frappe/frappe/templates/styles/borderless.css',

    return r.to_pdf(output_path)

I also tried:
r = PDFKit(input, ‘string’, options=options2, toc=toc, cover=cover, css=‘/home/frappe/frappe-bench/apps/frappe/frappe/templates/styles/borderless.css’,

r = PDFKit(input, 'string', options=options, toc=toc, cover=cover, css='/home/frappe/frappe-bench/apps/frappe/frappe/templates/styles/borderless.css',