Ejemplo n.º 1
0
    def test_pdf_borders(self):
        html = """
			<style>
            .print-format {
             margin-top: 0mm;
             margin-left: 10mm;
             margin-right: 0mm;
            }
            </style>
            <p>This is a test html snippet</p>
			<div class="more-info">
				<a href="http://test.com">Test link 1</a>
				<a href="/about">Test link 2</a>
				<a href="login">Test link 3</a>
				<img src="/assets/frappe/test.jpg">
			</div>
			<div style="background-image: url('/assets/frappe/bg.jpg')">
				Please mail us at <a href="mailto:[email protected]">email</a>
			</div>
		"""

        html, html_options = read_options_from_html(html)
        self.assertTrue(html_options['margin-top'] == '0')
        self.assertTrue(html_options['margin-left'] == '10')
        self.assertTrue(html_options['margin-right'] == '0')
Ejemplo n.º 2
0
def prepare_options(html, options):
    if not options:
        options = {}

    options.update({
        'print-media-type': None,
        'background': None,
        'images': None,
        'quiet': None,
        # 'no-outline': None,
        'encoding': "UTF-8",
        #'load-error-handling': 'ignore',

        # defaults
        'margin-right': '2mm',
        'margin-left': '2mm'
    })

    html, html_options = read_options_from_html(html)
    options.update(html_options or {})

    # cookies
    if frappe.session and frappe.session.sid:
        options['cookie'] = [('sid', '{0}'.format(frappe.session.sid))]

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

    return html, options
Ejemplo n.º 3
0
	def test_read_options_from_html(self):
		_, html_options = pdfgen.read_options_from_html(self.html)
		self.assertTrue(html_options['margin-top'] == '0')
		self.assertTrue(html_options['margin-left'] == '10')
		self.assertTrue(html_options['margin-right'] == '0')
Ejemplo n.º 4
0
 def test_read_options_from_html(self):
     _, html_options = pdfgen.read_options_from_html(self.html)
     self.assertTrue(html_options["margin-top"] == "0")
     self.assertTrue(html_options["margin-left"] == "10")
     self.assertTrue(html_options["margin-right"] == "0")