選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

37 行
886 B

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import pdfkit, os, frappe
  5. from frappe.utils import scrub_urls
  6. def get_pdf(html, options=None):
  7. if not options:
  8. options = {}
  9. options.update({
  10. "print-media-type": None,
  11. "background": None,
  12. "images": None,
  13. 'margin-top': '15mm',
  14. 'margin-right': '15mm',
  15. 'margin-bottom': '15mm',
  16. 'margin-left': '15mm',
  17. 'encoding': "UTF-8",
  18. 'no-outline': None
  19. })
  20. if not options.get("page-size"):
  21. options['page-size'] = frappe.db.get_single_value("Print Settings", "pdf_page_size") or "A4"
  22. html = scrub_urls(html)
  23. fname = os.path.join("/tmp", frappe.generate_hash() + ".pdf")
  24. pdfkit.from_string(html, fname, options=options or {})
  25. with open(fname, "rb") as fileobj:
  26. filedata = fileobj.read()
  27. os.remove(fname)
  28. return filedata