def test_ul(self):
     html = "<html><body><ul><li>foo</li><li>bar</li></html>"
     tree = etree.XML(cook_body(html, DEFAULT_BODY_STYLESHEET))
     self.assertEquals(tree.xpath("child::*")[0].tag, 
                       "{%s}list-block" % self.ns)
     self.assertEquals(len(tree.findall(".//{%s}list-item" % self.ns)), 2)
     self.assertEquals(len(tree.findall(".//{%s}list-item-label" % self.ns)), 2)
     self.assertEquals(len(tree.findall(".//{%s}list-item-body" % self.ns)), 2)
示例#2
0
    def __call__(self):
        """Returns the PDF printout.
        """
        context = aq_inner(self.context)
        body = context.getRawText()

        # Check there is a template
        if self.default_template == "":
            IStatusMessage(self.request).addStatusMessage(
                _("Template is empty. Check your Printout control panel."), type="info"
            )
            return self.request.response.redirect(context.absolute_url())

        # Render Chameleon Template
        plone_portal_state = getMultiAdapter((context, self.request), name="plone_portal_state")
        plone_tools = getMultiAdapter((context, self.request), name="plone_tools")
        plone_context_state = getMultiAdapter((context, self.request), name="plone_portal_state")
        try:
            pt = PageTemplate(self.default_template, format="xml", encoding="utf-8", debug=True)
            cooked_body = cook_body(body, self.default_body_stylesheet)
            output = pt.render(
                context=context,
                plone_portal_state=plone_portal_state,
                plone_tools=plone_tools,
                plone_context_state=plone_context_state,
                body=cooked_body,
            )
        except ExpatError, e:
            error = {
                "title": "Error rendering the default (chameleon/zpt) template",
                "message": str(e),
                "fo_output": "",
                "template": escape(self.default_template),
                "stylesheet": escape(self.default_body_stylesheet),
                "body": "",
                "cooked_body": "",
            }
            return self.error(error)
示例#3
0
file.close()

# input.html
file = open("input.html", "r")
body = file.read()
file.close()

class Context:
    pass

context = Context()
context.Title = "This is a title"
context.Description = "Description"


pt = PageTemplate(default_template)

output = pt.render(context=context, 
                   body=cook_body(body, 
                   default_body_stylesheet))

fo_filename = "tmp.fo"
file = open(fo_filename, "w")
file.write(output)
file.close()

fop = Fop()
output_filename = fop.convert(fo_filename, output_filename="out.pdf")
print output_filename

 def test_full(self):
     html = "<h2>headline</h2><p>paragraph</p><ul><li>one</li><li>two</li></ul><p>paragraph</p><ol><li>foo</li><li>bar</li></ol>"
     tree = etree.XML(cook_body(html, DEFAULT_BODY_STYLESHEET))
     result = etree.tostring(tree)
     self.assertEquals(len(tree.findall(".//*")), 16)
 def test_combination(self):
     html = "<html><body><h2>headline</h2><p>paragraph</p></body></html>"
     tree = etree.XML(cook_body(html, DEFAULT_BODY_STYLESHEET))
     result = etree.tostring(tree)
     self.assertEquals(len(tree.findall(".//*")), 2)
 def test_h1(self):
     html = "<html><body><h1>headline</h1></body></html>"
     tree = etree.XML(cook_body(html, DEFAULT_BODY_STYLESHEET))
     self.assertEquals(tree.xpath("child::*")[0].text, 'headline')
     self.assertEquals(len(tree.xpath("/*")), 1)
 def test_paragraph(self):
     html = "<html><body><p>a simple paragraph</p></body></html>"
     tree = etree.XML(cook_body(html, DEFAULT_BODY_STYLESHEET))
     self.assertEquals(tree.xpath("child::*")[0].text, 'a simple paragraph')
     self.assertEquals(len(tree.xpath("child::*")), 1)