Can you check if body have some margin or padding?
Set body { padding: 0; margin 0; } in CSS.

it is set, yes :confused:

Did you try --zoom 1.045?

Yes right now in the R= options after the T 0 B 0 … or where would you put it ?

Put it like this options='-T 0 -B 0 -L 0 -R 0 --zoom 1.045'

Now he says:

Server Error
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 60, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 49, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 19, in handle
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 36, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 879, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/print_format.py", line 50, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 16, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/api.py", line 76, in from_string
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/pdfkit.py", line 46, in __init__
    if options is not None: self.options.update(options)
ValueError: dictionary update sequence element #0 has length 1; 2 is required

With doing this:

def from_string(input, output_path, options=None, 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)

Where did you put zoom, I cant see it in code.

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

Sorry. Pasted the wrong Element from clipboard

hey @KanchanChauhan

I managed to let it look like this:

I don’t know why the first image looks different as the settings are margin and padding 0 everywhere but I will report. It looks now as expected. Will share information if I proceed :wink:

1 Like

Hello all,

I want to come back to you again.
I have now managed to get everything on the top into place and managed to get the margins adjusted. But now I think it lacks some css and html knowledge when refining and finishing my work.

This is the PDF output of the API:

As you can see here I have a “black box” also at the bottom, defined as “footer”. I want this footer to be displayed at the end of the page. What I did so far:

adjusting the “height” of every object leading to the footer element to 100%. Which does not help. when I place the footer at 11.69in, there is a blank page between page 1 of the document and page 2. Is there a chance to avoid this?

Here is my “standard.html”:

{%- from "templates/print_formats/standard_macros.html" import add_header2,
add_header,  render_field, add_letterhead, add_foot, add_header3 -%}

{% for page in layout %}

<div class="page-break" style="width: 100% !important; padding: 0.0in; margin: 0.0in;">
<table width="100%" style="height:100% !important;" padding="0" margin="0" cellspacing="0">
  <tr style="height:100% !important; vertical-align:bottom !important;">
  <td style="vertical-align:bottom !important; padding:0px !important; height:100% !important;">
    <table width="100%" padding="0" margin="0" cellspacing="0"><tr>
      <td width="100%" style="padding:0px !important">
  <div {% if print_settings.repeat_header_footer %} id="header-html" class="" {% endif %}>
    {{ add_header3(loop.index, layout|len, doc, letter_head, no_letterhead, footer) }}

  {% if print_settings.repeat_header_footer %}
  <div id="footer-html">
    {% if not no_letterhead and footer %}
    <div class="letter-head-footer">

    {% endif %}
    <p class="text-center small page-number visible-pdf">
      {{ _("Page {0} of {1}").format('<span class="page"></span>', '<span class="topage"></span>') }}
  {% endif %}
<div style="padding:0.75in;">
    <div style="margin: 0cm; margin-right: 0cm;"><br><br><br> {{ add_header2(doc)}}

    {% for section in page %}
    <div class="row section-break">
        {% for column in section %}
        <div class="col-xs-{{ (12 / section|len)|int }} column-break">
            {% for df in column %}
                {{ render_field(df, doc) }}
            {% endfor %}

        {% endfor %}

    {% endfor %}

{{ add_header(loop.index, layout|len, doc) }}


<div style="vertical-align:bottom !important; padding:0px !important; height:100% !important;">{{ footer }}</div></td></tr></table></div>
{% endfor %}

and this is the footer:

<div height="" style="" width="100%">
    <table style="background-color: #000000 !important;" width="100%">
            <tr style="background-color: #000000 !important;">
                <td align="left" style="padding-left: 50px;" width="50%; background-color: #000000 !important;">
                    <img src="xxxx">
                <td align="right" style="padding-right: 50px;" width="50%; background-color: #000000 !important;">
                    <img src="xxxx">

Hello there,

I am using WKHTMLTOPDF with laravel and I need a background image on all pdf pages. I have checked a lot of web but did not found any solution.

here is my output pdf file I just need a background image. Please help. Thanks

try customizing your print format and add this css code

background-image: url(‘http://your.image.link.here.jpg’);

Thanks for your help. But I have fixed the issue by using PDFTK. It is an awesome tool. Thanks

Check my output generated PDF with PDFTK. :slight_smile:

How can i do this without command line. I want to achieve this in header itself.