How to use the xhtml2pdf.tags.pisaTag function in xhtml2pdf

To help you get started, we’ve selected a few xhtml2pdf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xhtml2pdf / xhtml2pdf / tests / test_tags.py View on Github external
def test_pisa_tag_will_set_attrs_on_init(self):
        dom = minidom.parseString("test")
        element = dom.getElementsByTagName("unit")[0]
        attrs = AttrContainer({})
        instance = tags.pisaTag(element, attrs)
        self.assertEqual(instance.node, element)
        self.assertEqual(instance.tag, "unit")
        self.assertEqual(instance.attr, {})
github xhtml2pdf / xhtml2pdf / xhtml2pdf / tags.py View on Github external
class pisaTagPDFPAGECOUNT(pisaTag):
    """
    
    """

    def start(self, c):
        c.frag.pageCount = True
        c.addFrag()
        c.frag.pageCount = False

    def end(self, c):
        c.addPageCount()


class pisaTagPDFTOC(pisaTag):
    """
    
    """

    def end(self, c):
        c.multiBuild = True
        c.addTOC()


class pisaTagPDFFRAME(pisaTag):
    """
    
    """

    def start(self, c):
        deprecation("pdf:frame")
github xhtml2pdf / xhtml2pdf / xhtml2pdf / tags.py View on Github external
pass


class pisaTagBODY(pisaTag):
    """
    We can also asume that there is a BODY tag because html5lib
    adds it for us. Here we take the base font size for later calculations
    in the FONT tag.
    """

    def start(self, c):
        c.baseFontSize = c.frag.fontSize
        # print("base font size", c.baseFontSize)


class pisaTagTITLE(pisaTag):
    def end(self, c):
        c.meta["title"] = c.text
        c.clearFrag()


class pisaTagSTYLE(pisaTag):
    def start(self, c):
        c.addPara()


    def end(self, c):
        c.clearFrag()


class pisaTagMETA(pisaTag):
    def start(self, c):
github xhtml2pdf / xhtml2pdf / xhtml2pdf / tags.py View on Github external
else:
            if type(lst) == type(u""):
                frag.text = lst
            else:
                # XXX This should be the recent font, but it throws errors in Reportlab!
                frag.text = lst(c)

        # XXX This should usually be done in the context!!!
        frag.fontName = frag.bulletFontName = tt2ps(frag.fontName, frag.bold, frag.italic)
        c.frag.bulletText = [frag]

    def end(self, c):
        c.fragBlock.spaceBefore += self.offset


class pisaTagBR(pisaTag):
    def start(self, c):
        c.frag.lineBreak = 1
        c.addFrag()
        c.fragStrip = True
        del c.frag.lineBreak
        c.force = True


class pisaTagIMG(pisaTag):
    def start(self, c):
        attr = self.attr
        if attr.src and (not attr.src.notFound()):

            try:
                align = attr.align or c.frag.vAlign or "baseline"
                width = c.frag.width
github xhtml2pdf / xhtml2pdf / xhtml2pdf / tables.py View on Github external
tdata = c.tableData
        row = tdata.row
        begin = (0, row)
        end = (-1, row)

        tdata.add_cell_styles(c, begin, end, "tr")
        c.frag.vAlign = self.attr.valign or c.frag.vAlign

        tdata.col = 0
        tdata.data.append([])

    def end(self, c):
        c.tableData.row += 1


class pisaTagTD(pisaTag):

    def start(self, c):

        if self.attr.align is not None:
            c.frag.alignment = getAlign(self.attr.align)

        c.clearFrag()
        self.story = c.swapStory()

        attrs = self.attr

        tdata = c.tableData

        cspan = attrs.colspan
        rspan = attrs.rowspan
github xhtml2pdf / xhtml2pdf / xhtml2pdf / tags.py View on Github external
The default class for a tag definition
    """

    def __init__(self, node, attr):
        self.node = node
        self.tag = node.tagName
        self.attr = attr

    def start(self, c):
        pass

    def end(self, c):
        pass


class pisaTagBODY(pisaTag):
    """
    We can also asume that there is a BODY tag because html5lib
    adds it for us. Here we take the base font size for later calculations
    in the FONT tag.
    """

    def start(self, c):
        c.baseFontSize = c.frag.fontSize
        # print("base font size", c.baseFontSize)


class pisaTagTITLE(pisaTag):
    def end(self, c):
        c.meta["title"] = c.text
        c.clearFrag()
github xhtml2pdf / xhtml2pdf / xhtml2pdf / tags.py View on Github external
class pisaTagPDFNEXTPAGE(pisaTag):
    """
    
    """

    def start(self, c):
        # deprecation("pdf:nextpage")
        c.addPara()
        if self.attr.name:
            c.addStory(NextPageTemplate(self.attr.name))
        c.addStory(PageBreak())


class pisaTagPDFNEXTTEMPLATE(pisaTag):
    """
    
    """

    def start(self, c):
        # deprecation("pdf:frame")
        c.addStory(NextPageTemplate(self.attr["name"]))


class pisaTagPDFNEXTFRAME(pisaTag):
    """
    
    """

    def start(self, c):
        c.addPara()
github xhtml2pdf / xhtml2pdf / xhtml2pdf / tags.py View on Github external
afrag.bold = 0
            afrag.italic = 0
            afrag.cbDefn = ABag(
                kind="anchor",
                name=attr.name,
                label="anchor")
            c.fragAnchor.append(afrag)
            c.anchorName.append(attr.name)
        if attr.href and self.rxLink.match(attr.href):
            c.frag.link = attr.href

    def end(self, c):
        pass


class pisaTagFONT(pisaTag):
    # Source: http://www.w3.org/TR/CSS21/fonts.html#propdef-font-size

    def start(self, c):
        if self.attr["color"] is not None:
            c.frag.textColor = getColor(self.attr["color"])
        if self.attr["face"] is not None:
            c.frag.fontName = c.getFontName(self.attr["face"])
        if self.attr["size"] is not None:
            size = getSize(self.attr["size"], c.frag.fontSize, c.baseFontSize)
            c.frag.fontSize = max(size, 1.0)

    def end(self, c):
        pass


class pisaTagP(pisaTag):
github xhtml2pdf / xhtml2pdf / xhtml2pdf / tags.py View on Github external
class pisaTagSELECT(pisaTagINPUT):

        def start(self, c):
            c.select_options = ["One", "Two", "Three"]

        def _render(self, c, attr):
            c.addStory(xhtml2pdf_reportlab.PmlInput(attr.name,
                                                    type="select",
                                                    default=c.select_options[0],
                                                    options=c.select_options,
                                                    width=100,
                                                    height=40))
            c.select_options = None

    class pisaTagOPTION(pisaTag):

        pass


class pisaTagPDFNEXTPAGE(pisaTag):
    """
    
    """

    def start(self, c):
        # deprecation("pdf:nextpage")
        c.addPara()
        if self.attr.name:
            c.addStory(NextPageTemplate(self.attr.name))
        c.addStory(PageBreak())
github xhtml2pdf / xhtml2pdf / xhtml2pdf / tags.py View on Github external
def start(self, c):
        c.addPara()


    def end(self, c):
        c.clearFrag()


class pisaTagMETA(pisaTag):
    def start(self, c):
        name = self.attr.name.lower()
        if name in ("author", "subject", "keywords"):
            c.meta[name] = self.attr.content


class pisaTagSUP(pisaTag):
    def start(self, c):
        c.frag.super = 1


class pisaTagSUB(pisaTag):
    def start(self, c):
        c.frag.sub = 1


class pisaTagA(pisaTag):
    rxLink = re.compile("^(#|[a-z]+\:).*")


    def start(self, c):
        attr = self.attr
        # XXX Also support attr.id ?