from __future__ import unicode_literals

import pdfkit, os, frappe
from frappe.utils import scrub_urls

def get_pdf(html, options=None):
	if not options:
		options = {}

	options.update({
		"print-media-type": None,
		"background": None,
		"images": None,
		'margin-top': '15mm',
		'margin-right': '15mm',
		'margin-bottom': '15mm',
		'margin-left': '15mm',
		'encoding': "UTF-8",
		'no-outline': None
	})

	if not options.get("page-size"):
		options['page-size'] = frappe.db.get_single_value("Print Settings", "pdf_page_size") or "A4"

	html = scrub_urls(html)
	fname = os.path.join("/tmp", frappe.generate_hash() + ".pdf")
	pdfkit.from_string(html, fname, options=options or {})

	with open(fname, "rb") as fileobj:
		filedata = fileobj.read()

	os.remove(fname)

	return filedata

from __future__ import unicode_literals

import pdfkit, os, frappe
from frappe.utils import scrub_urls

def get_pdf(html, options=None):
	if not options:
		options = {}

	options.update({
		"print-media-type": None,
		"background": None,
		"images": None,
		# 'margin-top': '10mm',
		# 'margin-right': '1mm',
		# 'margin-bottom': '10mm',
		# 'margin-left': '1mm',
		'encoding': "UTF-8",
		'no-outline': None
	})

	if not options.get("page-size"):
		options['page-size'] = frappe.db.get_single_value("Print Settings", "pdf_page_size") or "A4"

	html = scrub_urls(html)
	fname = os.path.join("/tmp", frappe.generate_hash() + ".pdf")
	pdfkit.from_string(html, fname, options=options or {})

	with open(fname, "rb") as fileobj:
		filedata = fileobj.read()

	os.remove(fname)

	return filedata

Remove margin constrains from PDF printing
Remove margin constrains from PDF printing

  from __future__ import unicode_literals
  
  import pdfkit, os, frappe
  from frappe.utils import scrub_urls
  
  def get_pdf(html, options=None):
  	if not options:
  		options = {}
  
  	options.update({
  		"print-media-type": None,
  		"background": None,
  		"images": None,
- 		'margin-top': '15mm',
+ 		# 'margin-top': '10mm',
- 		'margin-right': '15mm',
+ 		# 'margin-right': '1mm',
- 		'margin-bottom': '15mm',
+ 		# 'margin-bottom': '10mm',
- 		'margin-left': '15mm',
+ 		# 'margin-left': '1mm',
  		'encoding': "UTF-8",
  		'no-outline': None
  	})
  
  	if not options.get("page-size"):
  		options['page-size'] = frappe.db.get_single_value("Print Settings", "pdf_page_size") or "A4"
  
  	html = scrub_urls(html)
  	fname = os.path.join("/tmp", frappe.generate_hash() + ".pdf")
  	pdfkit.from_string(html, fname, options=options or {})
  
  	with open(fname, "rb") as fileobj:
  		filedata = fileobj.read()
  
  	os.remove(fname)
  
  	return filedata
  
Remove margin constrains from PDF printing
## Code Before:
from __future__ import unicode_literals

import pdfkit, os, frappe
from frappe.utils import scrub_urls

def get_pdf(html, options=None):
	if not options:
		options = {}

	options.update({
		"print-media-type": None,
		"background": None,
		"images": None,
		'margin-top': '15mm',
		'margin-right': '15mm',
		'margin-bottom': '15mm',
		'margin-left': '15mm',
		'encoding': "UTF-8",
		'no-outline': None
	})

	if not options.get("page-size"):
		options['page-size'] = frappe.db.get_single_value("Print Settings", "pdf_page_size") or "A4"

	html = scrub_urls(html)
	fname = os.path.join("/tmp", frappe.generate_hash() + ".pdf")
	pdfkit.from_string(html, fname, options=options or {})

	with open(fname, "rb") as fileobj:
		filedata = fileobj.read()

	os.remove(fname)

	return filedata

## Instruction:
Remove margin constrains from PDF printing
## Code After:
from __future__ import unicode_literals

import pdfkit, os, frappe
from frappe.utils import scrub_urls

def get_pdf(html, options=None):
	if not options:
		options = {}

	options.update({
		"print-media-type": None,
		"background": None,
		"images": None,
		# 'margin-top': '10mm',
		# 'margin-right': '1mm',
		# 'margin-bottom': '10mm',
		# 'margin-left': '1mm',
		'encoding': "UTF-8",
		'no-outline': None
	})

	if not options.get("page-size"):
		options['page-size'] = frappe.db.get_single_value("Print Settings", "pdf_page_size") or "A4"

	html = scrub_urls(html)
	fname = os.path.join("/tmp", frappe.generate_hash() + ".pdf")
	pdfkit.from_string(html, fname, options=options or {})

	with open(fname, "rb") as fileobj:
		filedata = fileobj.read()

	os.remove(fname)

	return filedata
