Ejemplo n.º 1
0
def resetPdfForm():
    global PDFDOCENC,ENCODING,GLOBALFONTSDICTIONARY,GLOBALRESOURCES,ZADB
    PDFDOCENC = PDFPattern(PDFDocEncodingPattern)
    ENCODING = PDFPattern(EncodingPattern, PDFDocEncoding=PDFDOCENC)
    ZADB = PDFPattern(ZaDbPattern)
    GLOBALFONTSDICTIONARY = FormFontsDictionary()
    GLOBALRESOURCES = FormResources()
def SelectField(title,
                value,
                options,
                xmin,
                ymin,
                xmax,
                ymax,
                page,
                font="Helvetica-Bold",
                fontsize=9,
                R=0,
                G=0,
                B=0.627):
    #print "ARGS", (title, value, options, xmin, ymin, xmax, ymax, page, font, fontsize, R, G, B)
    from reportlab.pdfbase.pdfdoc import PDFString, PDFName, PDFArray
    if value not in options:
        raise ValueError, "value %s must be one of options %s" % (
            repr(value), repr(options))
    fontname = FORMFONTNAMES[font]
    optionstrings = map(PDFString, options)
    optionarray = PDFArray(optionstrings)
    return PDFPattern(SelectFieldPattern,
                      Options=optionarray,
                      Selected=PDFString(value),
                      Page=page,
                      Name=PDFString(title),
                      xmin=xmin,
                      ymin=ymin,
                      xmax=xmax,
                      ymax=ymax,
                      fontname=PDFName(fontname),
                      fontsize=fontsize,
                      R=R,
                      G=G,
                      B=B)
def TextField(title,
              value,
              xmin,
              ymin,
              xmax,
              ymax,
              page,
              maxlen=1000000,
              font="Helvetica-Bold",
              fontsize=9,
              R=0,
              G=0,
              B=0.627,
              multiline=0):
    from reportlab.pdfbase.pdfdoc import PDFString, PDFName
    Flags = 0
    if multiline:
        Flags = Flags | (1 << 12)  # bit 13 is at position 12 :)
    fontname = FORMFONTNAMES[font]
    return PDFPattern(TextFieldPattern,
                      value=PDFString(value),
                      maxlen=maxlen,
                      page=page,
                      title=PDFString(title),
                      xmin=xmin,
                      ymin=ymin,
                      xmax=xmax,
                      ymax=ymax,
                      fontname=PDFName(fontname),
                      fontsize=fontsize,
                      R=R,
                      G=G,
                      B=B,
                      Flags=Flags)
Ejemplo n.º 4
0
def ButtonField(title, value, xmin, ymin, page):
    if value not in ("Yes", "Off"):
        raise ValueError, "button value must be 'Yes' or 'Off': "+repr(value)
    (dx, dy) = (16.77036, 14.90698)
    return PDFPattern(ButtonFieldPattern,
                      Name=PDFString(title),
                      xmin=xmin, ymin=ymin, xmax=xmin+dx, ymax=ymin+dy,
                      Hide=HIDE,
                      APDOff=APDOFF,
                      APDYes=APDYES,
                      APNYes=APNYES,
                      Value=PDFName(value),
                      Page=page)
Ejemplo n.º 5
0
 def format(self, document):
     from reportlab.pdfbase.pdfdoc import PDFArray
     proxy = PDFPattern(FormPattern, Resources=GLOBALRESOURCES, fields=PDFArray(self.fields))
     return proxy.format(document)
def FormFont(BaseFont, Name):
    from reportlab.pdfbase.pdfdoc import PDFName
    return PDFPattern(FormFontPattern,
                      BaseFont=PDFName(BaseFont),
                      Name=PDFName(Name),
                      Encoding=PDFDOCENC)
def FormResources():
    return PDFPattern(FormResourcesDictionaryPattern,
                      Encoding=ENCODING,
                      Font=GLOBALFONTSDICTIONARY)
 def format(self, document):
     from reportlab.pdfbase.pdfdoc import PDFArray
     proxy = PDFPattern(FormPattern,
                        Resources=GLOBALRESOURCES,
                        fields=PDFArray(self.fields))
     return proxy.format(document)

ZaDbPattern = [
    ' <<'
    ' /BaseFont'
    '    /ZapfDingbats'
    ' /Name'
    '    /ZaDb'
    ' /Subtype'
    '    /Type1'
    ' /Type'
    '    /Font'
    '>>'
]

ZADB = PDFPattern(ZaDbPattern)

FormResourcesDictionaryPattern = [
    '<<', ' /Encoding ', ["Encoding"], LINEEND, ' /Font ', ["Font"], LINEEND,
    '>>'
]

FORMFONTNAMES = {
    "Helvetica": "Helv",
    "Helvetica-Bold": "HeBo",
    'Courier': "Cour",
    'Courier-Bold': "CoBo",
    'Courier-Oblique': "CoOb",
    'Courier-BoldOblique': "CoBO",
    'Helvetica-Oblique': "HeOb",
    'Helvetica-BoldOblique': "HeBO",
Ejemplo n.º 10
0
'/Rect',
'    [',["xmin"], " ", ["ymin"], " ", ["xmax"], " ", ["ymax"],
'    ] ',LINEEND,
'/Subtype',
'    /Widget ',
'/T ',
["Name"], LINEEND,
'/Type',
'    /Annot ',
'/V ',
["Value"], LINEEND,
' >>']

HIDE = PDFPattern([
'<< '
'/S '
' /Hide '
'>>'])

def buttonStreamDictionary():
    "everything except the length for the button appearance streams"
    result = PDFDictionary()
    result["SubType"] = "/Form"
    result["BBox"] = "[0 0 16.77036 14.90698]"
    font = PDFDictionary()
    font["ZaDb"] = ZADB
    resources = PDFDictionary()
    resources["ProcSet"] = "[ /PDF /Text ]"
    resources["Font"] = font
    result["Resources"] = resources
    return result