Try specifically:
margin-top: 0mm;
margin-bottom: 0mm;
margin-left: 0mm;
margin-right: 0mm;
wkhtmltopdf by default have some margin.
Try specifically:
margin-top: 0mm;
margin-bottom: 0mm;
margin-left: 0mm;
margin-right: 0mm;
wkhtmltopdf by default have some margin.
Change that background-color to black.
this would make the whole page black
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
Hi,
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,
configuration=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',
configuration=configuration)
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â,
configuration=configuration)
r = PDFKit(input, 'string', options=options, toc=toc, cover=cover, css='/home/frappe/frappe-bench/apps/frappe/frappe/templates/styles/borderless.css',
configuration=configuration)
Thanks!
Can you check if body have some margin or padding?
Set body { padding: 0; margin 0; }
in CSS.
it is set, yes
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
execute_cmd(cmd)
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
configuration=configuration)
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,
configuration=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',
configuration=configuration)
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â,
configuration=configuration)
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
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) }}
</div>
{% if print_settings.repeat_header_footer %}
<div id="footer-html">
{% if not no_letterhead and footer %}
<div class="letter-head-footer">
</div>
{% endif %}
<p class="text-center small page-number visible-pdf">
{{ _("Page {0} of {1}").format('<span class="page"></span>', '<span class="topage"></span>') }}
</p>
</div>
{% 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 %}
</div>
{% endfor %}
</div>
{% endfor %}
{{ add_header(loop.index, layout|len, doc) }}
</div>
</div>
</td></tr></table>
<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%">
<tbody>
<tr style="background-color: #000000 !important;">
<td align="left" style="padding-left: 50px;" width="50%; background-color: #000000 !important;">
<br>
<br>
<img src="xxxx">
<br>
<br>
</td>
<td align="right" style="padding-right: 50px;" width="50%; background-color: #000000 !important;">
<br>
<br>
<img src="xxxx">
<br>
<br>
</td>
</tr>
</tbody>
</table>
</div>