'Produces OCR Compatible PDF forms'

def OCRPDFManager(self):

    T = current.T
    s3ocr_root = self.__s3OCREtree()
    self.s3ocrxml = etree.tostring(s3ocr_root, pretty_print=DEBUG)
    self.content = []
    s3ocr_layout_etree = self.layoutEtree
    ITEXT = 'label'
    HINT = 'comment'
    TYPE = 'type'
    HASOPTIONS = 'has_options'
    LINES = 'lines'
    BOXES = 'boxes'
    REFERENCE = 'reference'
    RESOURCE = 'resource'
    dtformat = current.deployment_settings.get_L10n_datetime_format()
    if (str(dtformat)[:2] == '%m'):
        date_hint = T('fill    in    order:    month(2)    day(2)    year(4)')
        datetime_hint = T('fill    in    order:    hour(2)    min(2)    month(2)    day(2)    year(4)')
    else:
        date_hint = T('fill    in    order:    day(2)    month(2)    year(4)')
        datetime_hint = T('fill    in    order:    hour(2)    min(2)    day(2)    month(2)    year(4)')
    l10n = {'datetime_hint': {'date': date_hint, 'datetime': datetime_hint}, 'boolean': {'yes': T('Yes'), 'no': T('No')}, 'select': {'multiselect': T('Select    one    or    more    option(s)    that    apply'), 'singleselect': T('Select    the    option    that    applies')}}
    append = self.content.append
    SubElement = etree.SubElement
    for resource in s3ocr_root:
        name = resource.attrib.get('name')
        s3ocr_layout_resource_etree = SubElement(s3ocr_layout_etree, 'resource', name=name)
        styleSheet = getStyleSheet()
        for field in resource.iterchildren():
            get = field.attrib.get
            s3ocr_layout_field_etree = SubElement(s3ocr_layout_resource_etree, 'field', name=get('name'), type=get('type'))
            if (get(REFERENCE) == '1'):
                s3ocr_layout_field_etree.set(REFERENCE, '1')
                s3ocr_layout_field_etree.set(RESOURCE, get(RESOURCE))
            fieldlabel = get(ITEXT)
            spacing = ('    ' * 5)
            fieldhint = self.__trim(get(HINT))
            if fieldhint:
                append(Paragraph(html_unescape_and_strip(('%s%s(    %s    )' % (fieldlabel, spacing, fieldhint))), styleSheet['Question']))
            else:
                append(Paragraph(html_unescape_and_strip(fieldlabel), styleSheet['Question']))
            if ((get('readable', 'False') == 'True') and (get('writable', 'False') == 'False')):
                append(Paragraph(html_unescape_and_strip(get('default', 'No    default    Value')), styleSheet['DefaultAnswer']))
                s3ocr_layout_resource_etree.remove(s3ocr_layout_field_etree)
            elif (get(HASOPTIONS) == 'True'):
                fieldtype = get(TYPE)
                if (fieldtype == 'boolean'):
                    bool_text = l10n.get('boolean')
                    append(DrawOptionBoxes(s3ocr_layout_field_etree, [bool_text.get('yes').decode('utf-8'), bool_text.get('no').decode('utf-8')], ['yes', 'no']))
                else:
                    if (fieldtype == 'multiselect'):
                        option_hint = l10n.get('select').get('multiselect')
                    else:
                        option_hint = None
                    s3ocrselect = field.getchildren()[0]
                    numoptions = len(s3ocrselect.getchildren())
                    if (numoptions <= MAX_FORM_OPTIONS_LIMIT):
                        s3ocr_layout_field_etree.attrib['limitcrossed'] = '1'
                        if option_hint:
                            append(DrawHintBox(option_hint.decode('utf-8')))
                        options = s3ocrselect.iterchildren()
                        opts = []
                        oppend = opts.append
                        range = int(math.ceil((numoptions / 4.0)))
                        for row in xrange(range):
                            labels = []
                            lappend = labels.append
                            values = []
                            vappend = values.append
                            i = 1
                            for option in options:
                                label = option.text
                                if (label in opts):
                                    continue
                                oppend(label)
                                lappend(label)
                                vappend(option.attrib.get('value'))
                                if (i == 4):
                                    break
                                i += 1
                            append(DrawOptionBoxes(s3ocr_layout_field_etree, labels, values))
                    else:
                        append(DrawHintBox(T('Enter    a    value    carefully    without    spelling    mistakes,    this    field    needs    to    match    existing    data.').decode('utf-8')))
                        for line in xrange(2):
                            append(StringInputBoxes(numBoxes=None, etreeElem=s3ocr_layout_field_etree))
            else:
                fieldtype = get(TYPE)
                BOXES_TYPES = ['string', 'textbox', 'integer', 'double', 'date', 'datetime']
                if (fieldtype in BOXES_TYPES):
                    if (fieldtype in ['string', 'textbox']):
                        num_lines = int(get('lines', 1))
                        for line in xrange(num_lines):
                            append(StringInputBoxes(numBoxes=None, etreeElem=s3ocr_layout_field_etree))
                    elif (fieldtype in ['integer', 'double']):
                        num_boxes = int(get('boxes', 9))
                        append(StringInputBoxes(numBoxes=num_boxes, etreeElem=s3ocr_layout_field_etree))
                    elif (fieldtype in ['date', 'datetime']):
                        if (fieldtype == 'datetime'):
                            append(DateTimeBoxes(s3ocr_layout_field_etree))
                        elif (fieldtype == 'date'):
                            append(DateBoxes(s3ocr_layout_field_etree))
                else:
                    self.r.error(501, current.ERROR.PARSE_ERROR)
                    print sys.stderr(('%s    :invalid    field    type:    %s' % (get('name'), fieldtype)))
    return
