'Method to create a table object
@param document: A S3PDF object
@param raw_data: A list of rows
@param rfields: A list of field selectors
@param groupby: A field name that is to be used as a sub-group
All the records that share the same pdf_groupby value
will be clustered together
@param hide_comments: Any comment field will be hidden'

def __init__(self, document, rfields, raw_data, groupby=None, hide_comments=False, autogrow=False, body_height=0):

    if (current.deployment_settings.get_paper_size() == 'Letter'):
        self.paper_size = LETTER
    else:
        self.paper_size = A4
    set_fonts(self)
    rtl = current.response.s3.rtl
    self.pdf = document
    self.rfields = rfields
    rdata = []
    rappend = rdata.append
    for row in raw_data:
        data = []
        dappend = data.append
        for selector in rfields:
            value = row[selector.colname]
            dvalue = None
            while True:
                if isinstance(value, (basestring, lazyT)):
                    dvalue = biDiText(value)
                elif isinstance(value, IMG):
                    dvalue = S3html2pdf.parse_img(value, selector.field.uploadfolder)
                    if dvalue:
                        dvalue = dvalue[0]
                elif isinstance(value, DIV):
                    if (len(value.components) > 0):
                        value = value.components[0]
                        continue
                    else:
                        dvalue = biDiText(value)
                else:
                    dvalue = biDiText(value)
                break
            dappend(dvalue)
        if rtl:
            data.reverse()
        rappend(data)
    self.raw_data = rdata
    labels = [biDiText(selector.label) for selector in self.rfields]
    if rtl:
        labels.reverse()
    self.labels = labels
    list_fields = [selector.fname for selector in self.rfields]
    if rtl:
        list_fields.reverse()
    self.list_fields = list_fields
    self.pdf_groupby = groupby
    self.hideComments = hide_comments
    self.autogrow = autogrow
    self.body_height = body_height
    self.data = []
    self.subheadingList = []
    self.subheadingLevel = {}
    self.pages = []
    self.colWidths = []
    self.newColWidth = []
    self.rowHeights = []
    self.style = None
    self.tempDoc = EdenDocTemplate()
    self.headerColour = Color(0.73, 0.76, 1)
    self.oddColour = Color(0.92, 0.92, 1)
    self.evenColour = Color(0.83, 0.84, 1)
    self.MIN_COMMENT_COL_WIDTH = 200
    self.fontsize = 12
