'Function to convert the rules passed in to a flowable.
The rules (for example) could be an rHeader callback
@param rules: the HTML (web2py helper class) or a callback
to produce it. The callback receives the
S3Request as parameter.
@param printable_width: the printable width
@param styles: styles for HTML=>PDF conversion'

def get_html_flowable(self, rules, printable_width, styles=None):

    if callable(rules):
        r = self.r
        if (r is not None):
            representation = r.representation
            r.representation = 'html'
        try:
            html = rules(r)
        except:
            if current.response.s3.debug:
                raise
            else:
                import sys
                current.log.error(sys.exc_info()[1])
                html = ''
        if (r is not None):
            r.representation = representation
    else:
        html = rules
    parser = S3html2pdf(pageWidth=printable_width, exclude_class_list=['tabs'], styles=styles)
    result = parser.parse(html)
    return result
