PDF in invoice email

324 views
Skip to first unread message

John Hooks

unread,
Jul 25, 2014, 2:48:47 PM7/25/14
to erpnext-dev...@googlegroups.com
I installed wkhtmltopdf and copied the fonts from the repo (I'm using ubuntu) but I get Error generating PDF, attachment sent as HTML.  Is there something else I have to do?  thanks!

Pratik Vyas

unread,
Jul 25, 2014, 2:51:46 PM7/25/14
to erpnext-dev...@googlegroups.com
Hi John,

wkhtmltopdf might not be in the path. If `which wkhtmltopdf` returns a
path in /usr/local/bin then, either you'll have to add it in the PATH
in supervisor or symlink it in /usr/bin

eg,

ln -s /usr/local/bin/wkhtmltopdf /usr/bin/wkhtmltopdf


> --
> Note:
>
> If you are posting an issue,
>
> 1. ERPNext is a free and open source software and support is given on this
> forum by a team (https://frappe.io/webnotes). So please consider donating if
> you find this forum useful (https://frappe.io/buy). Even a small amount
> would be helpful.
> 2. We should be able to replicate it at our end. So please give us as much
> information as you can. Please see it from the point of view of the person
> receiving the communication.
> 3. Paste your code at http://pastebin.com or http://gist.github.com and send
> only the URL via email
> 4. For sending images, use http://imgur.com or other similar services. Do
> not send images as attachments. Links are good. Same goes for any file you
> are going to send.
>
> End of Note
> ---
> You received this message because you are subscribed to the Google Groups
> "ERPNext Developer Forum" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to erpnext-developer...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/erpnext-developer-forum/4361fa63-9ae9-45ca-8ddd-25b51ea7f1bb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Pratik
erpnext

John Hooks

unread,
Jul 25, 2014, 2:58:34 PM7/25/14
to erpnext-dev...@googlegroups.com
Pratik,
    which wkhtmltopdf reports /usr/bin/wkhtmltopdf.  I also cleared the cache to make sure that wasn't the issue.  Still gives me the same error.  Is there anything else to try?

Pratik Vyas

unread,
Jul 25, 2014, 3:15:09 PM7/25/14
to erpnext-dev...@googlegroups.com
On Sat, Jul 26, 2014 at 12:28 AM, John Hooks <hook...@gmail.com> wrote:
> Pratik,
> which wkhtmltopdf reports /usr/bin/wkhtmltopdf. I also cleared the
> cache to make sure that wasn't the issue. Still gives me the same error.
> Is there anything else to try?

You could try restarting gunicorn

You can also run `wkhtmltopdf https://en.wikipedia.org /dev/null` to
see if it's producing any errors (maybe missing some dependencies like
libxext or libxrender).
>> > email to erpnext-developer...@googlegroups.com.
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/erpnext-developer-forum/4361fa63-9ae9-45ca-8ddd-25b51ea7f1bb%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> Pratik
>> erpnext
>
> --
> Note:
>
> If you are posting an issue,
>
> 1. ERPNext is a free and open source software and support is given on this
> forum by a team (https://frappe.io/webnotes). So please consider donating if
> you find this forum useful (https://frappe.io/buy). Even a small amount
> would be helpful.
> 2. We should be able to replicate it at our end. So please give us as much
> information as you can. Please see it from the point of view of the person
> receiving the communication.
> 3. Paste your code at http://pastebin.com or http://gist.github.com and send
> only the URL via email
> 4. For sending images, use http://imgur.com or other similar services. Do
> not send images as attachments. Links are good. Same goes for any file you
> are going to send.
>
> End of Note
> ---
> You received this message because you are subscribed to the Google Groups
> "ERPNext Developer Forum" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to erpnext-developer...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/erpnext-developer-forum/cb7a2380-a0a2-444a-a000-f75522ad9981%40googlegroups.com.

John Hooks

unread,
Jul 25, 2014, 3:50:20 PM7/25/14
to erpnext-dev...@googlegroups.com
Ah thanks so much.  I got a cannot connect to x server error.  I installed from apt-get and that must have been the issue.  I downloaded it from wkhtmltopdf.org and manually installed it and all is good.  Thanks so much!!  This is great.  For some reason when I sent people the html invoices they didn't know what to do with them.  This will make everything easier.  Thanks again!

John Hooks

unread,
Jul 26, 2014, 7:31:00 PM7/26/14
to erpnext-dev...@googlegroups.com
Pratik,
  I did an update and noticed that the pdf now isn't pulling in the html formatting correctly.  The preview on the print screen looks correct but the pdf comes out with everything aligned on the left and the table has no borders.  

John Hooks

unread,
Jul 26, 2014, 7:36:06 PM7/26/14
to erpnext-dev...@googlegroups.com
By the way, the new print preview looks awesome!

Anand Doshi

unread,
Jul 26, 2014, 11:48:34 PM7/26/14
to erpnext-dev...@googlegroups.com
John. Are you using bench/honcho start or production setup?

It not prod setup,
set "host_name": "http://yoursite:8000" I'm site_config.json and try. 

Sent from my phone
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6cf2027d-f6d8-423d-a98e-a073ae26efdd%40googlegroups.com.

John Hooks

unread,
Jul 27, 2014, 4:27:07 PM7/27/14
to erpnext-dev...@googlegroups.com
I'm using production.  I was going to to stop nginx and supervisor but I didn't see where site_config.json is?


You received this message because you are subscribed to a topic in the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/erpnext-developer-forum/AOz790DYP_4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/A3F422A4-4DA0-4B97-8AC8-15447C2BFF52%40iwebnotes.com.

Pratik Vyas

unread,
Jul 27, 2014, 4:30:13 PM7/27/14
to erpnext-dev...@googlegroups.com


On 28 Jul 2014 01:57, "John Hooks" <hook...@gmail.com> wrote:
>
> I'm using production.  I was going to to stop nginx and supervisor but I didn't see where site_config.json is?

It's at frappe-bench/sites/SITENAME/site_config.json

You don't have restart gunicorn to change the site config.

>>>>> >> > email to erpnext-developer...@googlegroups.com.
>>>>> >> > To view this discussion on the web visit
>>>>> >> >

> To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CAK6hC1WB0rksPgLzSXSBf%2ByiiShp5agwWqvBRbFZBoYWbTeOAg%40mail.gmail.com.

John Hooks

unread,
Jul 27, 2014, 4:41:39 PM7/27/14
to erpnext-dev...@googlegroups.com
Thanks Pratik,
  Do I still add this if I'm in production mode?


Pratik Vyas

unread,
Jul 28, 2014, 4:25:02 AM7/28/14
to erpnext-dev...@googlegroups.com
On Mon, Jul 28, 2014 at 2:11 AM, John Hooks <hook...@gmail.com> wrote:
> Thanks Pratik,
> Do I still add this if I'm in production mode?
>
>

Yes, you can set it to "http://hostname". It should be able to resolve
the css files.


--
Pratik
erpnext

John Hooks

unread,
Jul 28, 2014, 5:04:57 PM7/28/14
to erpnext-dev...@googlegroups.com
Pratik,
   In site_config.json I added the line "host_name": and then the host in quotes after.  If I do this I get errors in the site and then if I click the download pdf button it won't connect to the database.  If I take that out of the site_config.json file I get this error:

Traceback (innermost last):
  File "/home/john/frappe-bench/apps/frappe/frappe/app.py", line 54, in application
    response = frappe.api.handle()
  File "/home/john/frappe-bench/apps/frappe/frappe/api.py", line 42, in handle
    return frappe.handler.handle()
  File "/home/john/frappe-bench/apps/frappe/frappe/handler.py", line 66, in handle
    execute_cmd(cmd)
  File "/home/john/frappe-bench/apps/frappe/frappe/handler.py", line 84, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/john/frappe-bench/apps/frappe/frappe/__init__.py", line 524, in call
    return fn(*args, **newargs)
  File "/home/john/frappe-bench/apps/frappe/frappe/templates/pages/print.py", line 91, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/john/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 28, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/john/frappe-bench/env/local/lib/python2.7/site-packages/pdfkit/api.py", line 68, in from_string
    return r.to_pdf(output_path)
  File "/home/john/frappe-bench/env/local/lib/python2.7/site-packages/pdfkit/pdfkit.py", line 109, in to_pdf
    raise IOError('wkhtmltopdf reported an error:\n' + stderr.decode('utf-8'))
 IOError: wkhtmltopdf reported an error:
Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[=========>                                                  ] 16%
Warning: Failed to load http://site1.local/assets/frappe/css/bootstrap.css (ignore)
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Resolving links (4/6)                                                       
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
Printing pages (6/6)
[>                                                           ] Preparing
[==============================>                             ] Page 1 of 2
[============================================================] Page 2 of 2
Done                                                                      
Exit with code 1 due to network error: HostNotFoundError




John Hooks

unread,
Jul 28, 2014, 5:20:43 PM7/28/14
to erpnext-dev...@googlegroups.com
Pratik,
  I apologize the other errors I was getting on the site were because I forgot a comma in the site_config.json file.  However after I put in the correct host I still get this error from the download pdf option:

Traceback (innermost last):
  File "/home/john/frappe-bench/apps/frappe/frappe/app.py", line 54, in application
    response = frappe.api.handle()
  File "/home/john/frappe-bench/apps/frappe/frappe/api.py", line 42, in handle
    return frappe.handler.handle()
  File "/home/john/frappe-bench/apps/frappe/frappe/handler.py", line 66, in handle
    execute_cmd(cmd)
  File "/home/john/frappe-bench/apps/frappe/frappe/handler.py", line 84, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/john/frappe-bench/apps/frappe/frappe/__init__.py", line 524, in call
    return fn(*args, **newargs)
  File "/home/john/frappe-bench/apps/frappe/frappe/templates/pages/print.py", line 91, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/john/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 28, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/john/frappe-bench/env/local/lib/python2.7/site-packages/pdfkit/api.py", line 68, in from_string
    return r.to_pdf(output_path)
  File "/home/john/frappe-bench/env/local/lib/python2.7/site-packages/pdfkit/pdfkit.py", line 109, in to_pdf
    raise IOError('wkhtmltopdf reported an error:\n' + stderr.decode('utf-8'))
 IOError: wkhtmltopdf reported an error:
Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[=========>                                                  ] 16%
[=========================>                                  ] 43%
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Resolving links (4/6)                                                       
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
Printing pages (6/6)
[>                                                           ] Preparing
[============================================================] Page 1 of 1
Done                                                                      
Exit with code 1 due to network error: HostNotFoundError

Anand Doshi

unread,
Jul 29, 2014, 11:07:24 AM7/29/14
to ERPNext Developer's Forum
Hi John,

You need to put it as http://site1.local:8000, if it runs on port 8000.

Essentially, the port should also be part of host_name.

Hmm. Should the key be base_url instead of host_name? @pdvyas what do you say?

Thanks,
Anand Doshi.


On Tue, Jul 29, 2014 at 2:50 AM, John Hooks <hook...@gmail.com> wrote:
Pratik,
--
Note:
 
If you are posting an issue,
 
1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.

John Hooks

unread,
Jul 29, 2014, 5:08:34 PM7/29/14
to erpnext-dev...@googlegroups.com
Thank you so much guys for your help.  I feel like such a moron.  It was an issue with my DNS settings.  I figured it out when I couldn't send an email as well.  Thanks for your time.  Hopefully you didn't spend too much trying to help me.


You received this message because you are subscribed to a topic in the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/erpnext-developer-forum/AOz790DYP_4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CAAQzbF3hHiH3u4jDi10sw-ZhVuqKvzJAhqPWwGDryYmv9Shdzw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages