def ButtonField(title, value, xmin, ymin, page, width=16.7704, height=14.907): if value not in ("Yes", "Off"): raise ValueError("button value must be 'Yes' or 'Off': " + repr(value)) fontSize = (11.3086 / 14.907) * height dx = (3.6017 / 16.7704) * width dy = (3.3881 / 14.907) * height return PDFPattern( ButtonFieldPattern, Name=PDFString(title), xmin=xmin, ymin=ymin, xmax=xmin + width, ymax=ymin + width, Hide=PDFPattern(['<< /S /Hide >>']), APDOff=ButtonStream('0.749 g 0 0 %(width)s %(height)s re f\r\n' % vars(), width=width, height=height), APDYes=ButtonStream( '0.749 g 0 0 %(width)s %(height)s re f q 1 1 %(width)s %(height)s re W n BT /ZaDb %(fontSize)s Tf 0 g 1 0 0 1 %(dx)s %(dy)s Tm (4) Tj ET\r\n' % vars(), width=width, height=height), APNYes=ButtonStream( 'q 1 1 %(width)s %(height)s re W n BT /ZaDb %(fontSize)s Tf 0 g 1 0 0 1 %(dx)s %(dy)s Tm (4) Tj ET Q\r\n' % vars(), width=width, height=height), Value=PDFName(value), Page=page)
def resetPdfForm(): global PDFDOCENC, ENCODING, GLOBALFONTSDICTIONARY, GLOBALRESOURCES, ZADB PDFDOCENC = PDFPattern(PDFDocEncodingPattern) ENCODING = PDFPattern(EncodingPattern, PDFDocEncoding=PDFDOCENC) ZADB = PDFPattern(ZaDbPattern) GLOBALFONTSDICTIONARY = FormFontsDictionary() GLOBALRESOURCES = FormResources()
def resetPdfForm(): global PDFDOCENC,ENCODING,GLOBALFONTSDICTIONARY,GLOBALRESOURCES,ZADB PDFDOCENC = PDFPattern(PDFDocEncodingPattern) ENCODING = PDFPattern(EncodingPattern, PDFDocEncoding=PDFDOCENC.clone()) ZADB = PDFPattern(ZaDbPattern) GLOBALFONTSDICTIONARY = FormFontsDictionary() GLOBALRESOURCES = FormResources()
def resetPdfForm(): pdfform.PDFDOCENC = PDFPattern(pdfform.PDFDocEncodingPattern) pdfform.ENCODING = PDFPattern( pdfform.EncodingPattern, PDFDocEncoding=pdfform.PDFDOCENC) pdfform.GLOBALFONTSDICTIONARY = pdfform.FormFontsDictionary() pdfform.GLOBALRESOURCES = pdfform.FormResources() pdfform.ZADB = PDFPattern(pdfform.ZaDbPattern)
def format(self, document): from reportlab.pdfbase.pdfdoc import PDFArray proxy = PDFPattern(FormPattern, Resources=getattr(self, 'resources', None) or FormResources(), NeedAppearances=getattr(self, 'needAppearances', 'false'), fields=PDFArray(self.fields), SigFlags=getattr(self, 'sigFlags', 0)) return proxy.format(document)
def format(self, document): from reportlab.pdfbase.pdfdoc import PDFArray proxy = PDFPattern( FormPattern, Resources=getattr(self, "resources", None) or FormResources(), NeedAppearances=getattr(self, "needAppearances", "false"), fields=PDFArray(self.fields), SigFlags=getattr(self, "sigFlags", 0), ) return proxy.format(document)
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 = list(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)
def FormFontsDictionary(): from reportlab.pdfbase.pdfdoc import PDFDictionary fontsdictionary = PDFDictionary() fontsdictionary.__RefOnly__ = 1 for fullname, shortname in FORMFONTNAMES.items(): fontsdictionary[shortname] = FormFont(fullname, shortname) fontsdictionary["ZaDb"] = PDFPattern(ZaDbPattern) return fontsdictionary
def buttonStreamDictionary(width=16.7704, height=14.907): "everything except the length for the button appearance streams" result = PDFDictionary() result["SubType"] = "/Form" result["BBox"] = "[0 0 %(width)s %(height)s]" % vars() font = PDFDictionary() font["ZaDb"] = PDFPattern(ZaDbPattern) resources = PDFDictionary() resources["ProcSet"] = "[ /PDF /Text ]" resources["Font"] = font result["Resources"] = resources return result
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)
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=PDFPattern(PDFDocEncodingPattern))
def FormResources(): return PDFPattern(FormResourcesDictionaryPattern, Encoding=PDFPattern( EncodingPattern, PDFDocEncoding=PDFPattern(PDFDocEncodingPattern)), Font=FormFontsDictionary())
def format(self, document): from reportlab.pdfbase.pdfdoc import PDFArray proxy = PDFPattern(FormPattern, Resources=getattr(self,'resources',GLOBALRESOURCES), NeedAppearances=getattr(self,'needAppearances','false'), fields=PDFArray(self.fields), SigFlags=getattr(self,'sigFlags',0)) return proxy.format(document)
' ] ', '\r\n', '/Subtype', ' /Widget ', '/T ', ["Name"], '\r\n', '/Type', ' /Annot ', '/V ', ["Value"], '\r\n', ' >>' ] 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
def FormResources(): return PDFPattern(FormResourcesDictionaryPattern, Encoding=ENCODING, Font=GLOBALFONTSDICTIONARY)