src/reportlab/pdfbase/pdfform.py
author rptlab
Tue, 30 Apr 2013 14:28:14 +0100
branchpy33
changeset 3723 99aa837b6703
parent 3721 0c93dd8ff567
child 3843 ee97902ffa44
permissions -rw-r--r--
second stage of port to Python 3.3; working hello world
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
     1
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
     2
"""Support for Acrobat Forms in ReportLab documents
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
     3
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
     4
This module is somewhat experimental at this time.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
     5
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
     6
Includes basic support for
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
     7
    textfields,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
     8
    select fields (drop down lists), and
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
     9
    check buttons.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    10
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    11
The public interface consists of functions at the moment.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    12
At some later date these operations may be made into canvas
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    13
methods. (comments?)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    14
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    15
The ...Absolute(...) functions position the fields with respect
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    16
to the absolute canvas coordinate space -- that is, they do not
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    17
respect any coordinate transforms in effect for the canvas.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    18
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    19
The ...Relative(...) functions position the ONLY THE LOWER LEFT
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    20
CORNER of the field using the coordinate transform in effect for
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    21
the canvas.  THIS WILL ONLY WORK CORRECTLY FOR TRANSLATED COORDINATES
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    22
-- THE SHAPE, SIZE, FONTSIZE, AND ORIENTATION OF THE FIELD WILL NOT BE EFFECTED
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    23
BY SCALING, ROTATION, SKEWING OR OTHER NON-TRANSLATION COORDINATE
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    24
TRANSFORMS.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    25
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    26
Please note that all field names (titles) in a given document must be unique.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    27
Textfields and select fields only support the "base 14" canvas fonts
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    28
at this time.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    29
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    30
See individual function docstrings below for more information.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    31
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    32
The function test1(...) generates a simple test file.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    33
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    34
THIS CONTRIBUTION WAS COMMISSIONED BY REPORTLAB USERS
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    35
WHO WISH TO REMAIN ANONYMOUS.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    36
"""
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    37
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    38
### NOTE: MAKE THE STRING FORMATS DYNAMIC IN PATTERNS TO SUPPORT ENCRYPTION XXXX
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    39
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    40
import string
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    41
from reportlab.pdfbase.pdfdoc import LINEEND, PDFString, PDFStream, PDFDictionary, PDFName
3254
dd9042134279 canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents: 2964
diff changeset
    42
from reportlab.lib.colors import obj_R_G_B
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    43
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    44
#==========================public interfaces
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    45
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    46
def textFieldAbsolute(canvas, title, x, y, width, height, value="", maxlen=1000000, multiline=0):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    47
    """Place a text field on the current page
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    48
        with name title at ABSOLUTE position (x,y) with
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    49
        dimensions (width, height), using value as the default value and
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    50
        maxlen as the maximum permissible length.  If multiline is set make
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    51
        it a multiline field.
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    52
    """
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    53
    theform = getForm(canvas)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    54
    return theform.textField(canvas, title, x, y, x+width, y+height, value, maxlen, multiline)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    55
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    56
def textFieldRelative(canvas, title, xR, yR, width, height, value="", maxlen=1000000, multiline=0):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    57
    "same as textFieldAbsolute except the x and y are relative to the canvas coordinate transform"
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    58
    (xA, yA) = canvas.absolutePosition(xR,yR)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    59
    return textFieldAbsolute(canvas, title, xA, yA, width, height, value, maxlen, multiline)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    60
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    61
def buttonFieldAbsolute(canvas, title, value, x, y):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    62
    """Place a check button field on the current page
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    63
        with name title and default value value (one of "Yes" or "Off")
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    64
        at ABSOLUTE position (x,y).
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    65
    """
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    66
    theform = getForm(canvas)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    67
    return theform.buttonField(canvas, title, value, x, y)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    68
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    69
def buttonFieldRelative(canvas, title, value, xR, yR):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    70
    "same as buttonFieldAbsolute except the x and y are relative to the canvas coordinate transform"
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    71
    (xA, yA) = canvas.absolutePosition(xR,yR)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    72
    return buttonFieldAbsolute(canvas, title, value, xA, yA)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    73
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    74
def selectFieldAbsolute(canvas, title, value, options, x, y, width, height):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    75
    """Place a select field (drop down list) on the current page
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1660
diff changeset
    76
        with name title and
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    77
        with options listed in the sequence options
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    78
        default value value (must be one of options)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    79
        at ABSOLUTE position (x,y) with dimensions (width, height)."""
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    80
    theform = getForm(canvas)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    81
    theform.selectField(canvas, title, value, options, x, y, x+width, y+height)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1660
diff changeset
    82
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    83
def selectFieldRelative(canvas, title, value, options, xR, yR, width, height):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    84
    "same as textFieldAbsolute except the x and y are relative to the canvas coordinate transform"
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    85
    (xA, yA) = canvas.absolutePosition(xR,yR)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    86
    return selectFieldAbsolute(canvas, title, value, options, xA, yA, width, height)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    87
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    88
def test1():
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    89
    from reportlab.pdfgen import canvas
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    90
    fn = "formtest1.pdf"
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    91
    c = canvas.Canvas(fn)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    92
    # first page
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    93
    c.setFont("Courier", 10)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    94
    c.drawString(100, 500, "hello world")
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    95
    textFieldAbsolute(c, "fieldA", 100, 600, 100, 20, "default value")
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    96
    textFieldAbsolute(c, "fieldB", 100, 300, 100, 50, "another default value", multiline=1)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    97
    selectFieldAbsolute(c, "fieldC", "France", ["Canada", "France", "China"], 100, 200, 100, 20)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    98
    c.rect(100, 600, 100, 20)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
    99
    buttonFieldAbsolute(c, "field2", "Yes", 100, 700)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   100
    c.rect(100, 700, 20, 20)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   101
    buttonFieldAbsolute(c, "field3", "Off", 100, 800)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   102
    c.rect(100, 800, 20, 20)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   103
    # second page
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   104
    c.showPage()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   105
    c.setFont("Helvetica", 7)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   106
    c.translate(50, 20)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   107
    c.drawString(100, 500, "hello world")
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   108
    textFieldRelative(c, "fieldA_1", 100, 600, 100, 20, "default value 2")
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   109
    c.setStrokeColorRGB(1,0,0)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   110
    c.setFillColorRGB(0,1,0.5)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   111
    textFieldRelative(c, "fieldB_1", 100, 300, 100, 50, "another default value 2", multiline=1)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   112
    selectFieldRelative(c, "fieldC_1", "France 1", ["Canada 0", "France 1", "China 2"], 100, 200, 100, 20)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   113
    c.rect(100, 600, 100, 20)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   114
    buttonFieldRelative(c, "field2_1", "Yes", 100, 700)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   115
    c.rect(100, 700, 20, 20)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   116
    buttonFieldRelative(c, "field3_1", "Off", 100, 800)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   117
    c.rect(100, 800, 20, 20)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   118
    c.save()
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3637
diff changeset
   119
    print("wrote", fn)
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   120
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   121
#==========================end of public interfaces
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   122
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3637
diff changeset
   123
from .pdfpattern import PDFPattern
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   124
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   125
def getForm(canvas):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   126
    "get form from canvas, create the form if needed"
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   127
    try:
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   128
        return canvas.AcroForm
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   129
    except AttributeError:
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   130
        theform = canvas.AcroForm = AcroForm()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   131
        # install the form in the document
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   132
        d = canvas._doc
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   133
        cat = d._catalog
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   134
        cat.AcroForm = theform
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   135
        return theform
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1660
diff changeset
   136
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   137
class AcroForm:
3317
7cc62d990f32 pdfform/pdfpattern.py: add __PDFObject__ to classes (patch from Arnaud Fontaine <arnaud@andesi.org>
rgbecker
parents: 3254
diff changeset
   138
    __PDFObject__ = True
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   139
    def __init__(self):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   140
        self.fields = []
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   141
    def textField(self, canvas, title, xmin, ymin, xmax, ymax, value="", maxlen=1000000, multiline=0):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   142
        # determine the page ref
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   143
        doc = canvas._doc
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   144
        page = doc.thisPageRef()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   145
        # determine text info
3254
dd9042134279 canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents: 2964
diff changeset
   146
        R, G, B = obj_R_G_B(canvas._fillColorObj)
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   147
        #print "rgb", (R,G,B)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   148
        font = canvas. _fontname
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   149
        fontsize = canvas. _fontsize
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   150
        field = TextField(title, value, xmin, ymin, xmax, ymax, page, maxlen,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   151
                          font, fontsize, R, G, B, multiline)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   152
        self.fields.append(field)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   153
        canvas._addAnnotation(field)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   154
    def selectField(self, canvas, title, value, options, xmin, ymin, xmax, ymax):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   155
        # determine the page ref
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   156
        doc = canvas._doc
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   157
        page = doc.thisPageRef()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   158
        # determine text info
3254
dd9042134279 canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents: 2964
diff changeset
   159
        R, G, B = obj_R_G_B(canvas._fillColorObj)
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   160
        #print "rgb", (R,G,B)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   161
        font = canvas. _fontname
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   162
        fontsize = canvas. _fontsize
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   163
        field = SelectField(title, value, options, xmin, ymin, xmax, ymax, page,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   164
              font=font, fontsize=fontsize, R=R, G=G, B=B)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   165
        self.fields.append(field)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   166
        canvas._addAnnotation(field)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   167
    def buttonField(self, canvas, title, value, xmin, ymin):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   168
        # determine the page ref
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   169
        doc = canvas._doc
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   170
        page = doc.thisPageRef()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   171
        field = ButtonField(title, value, xmin, ymin, page)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   172
        self.fields.append(field)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   173
        canvas._addAnnotation(field)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   174
    def format(self, document):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   175
        from reportlab.pdfbase.pdfdoc import PDFArray
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   176
        proxy = PDFPattern(FormPattern, Resources=GLOBALRESOURCES, fields=PDFArray(self.fields))
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   177
        return proxy.format(document)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   178
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   179
FormPattern = [
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   180
'<<', LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   181
' /NeedAppearances true ', LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   182
' /DA ', PDFString('/Helv 0 Tf 0 g '), LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   183
' /DR ', LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   184
["Resources"],
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   185
' /Fields ', LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   186
["fields"],
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   187
'>>'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   188
]
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   189
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   190
def FormFontsDictionary():
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   191
    from reportlab.pdfbase.pdfdoc import PDFDictionary
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   192
    fontsdictionary = PDFDictionary()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   193
    fontsdictionary.__RefOnly__ = 1
3723
99aa837b6703 second stage of port to Python 3.3; working hello world
rptlab
parents: 3721
diff changeset
   194
    for fullname, shortname in FORMFONTNAMES.items():
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   195
        fontsdictionary[shortname] = FormFont(fullname, shortname)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   196
    fontsdictionary["ZaDb"] = ZADB
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   197
    return fontsdictionary
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   198
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   199
def FormResources():
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   200
    return PDFPattern(FormResourcesDictionaryPattern,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   201
                      Encoding=ENCODING, Font=GLOBALFONTSDICTIONARY)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   202
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   203
ZaDbPattern = [
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   204
' <<'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   205
' /BaseFont'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   206
'    /ZapfDingbats'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   207
' /Name'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   208
'    /ZaDb'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   209
' /Subtype'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   210
'    /Type1'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   211
' /Type'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   212
'    /Font'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   213
'>>']
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   214
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   215
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   216
FormResourcesDictionaryPattern = [
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   217
'<<',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   218
' /Encoding ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   219
["Encoding"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   220
' /Font ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   221
["Font"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   222
'>>'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   223
]
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   224
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   225
FORMFONTNAMES = {
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   226
    "Helvetica": "Helv",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   227
    "Helvetica-Bold": "HeBo",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   228
    'Courier': "Cour",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   229
    'Courier-Bold': "CoBo",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   230
    'Courier-Oblique': "CoOb",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   231
    'Courier-BoldOblique': "CoBO",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   232
    'Helvetica-Oblique': "HeOb",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   233
    'Helvetica-BoldOblique': "HeBO",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   234
    'Times-Roman': "Time",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   235
    'Times-Bold': "TiBo",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   236
    'Times-Italic': "TiIt",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   237
    'Times-BoldItalic': "TiBI",
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   238
    }
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   239
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   240
EncodingPattern = [
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   241
'<<',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   242
' /PDFDocEncoding ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   243
["PDFDocEncoding"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   244
'>>',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   245
]
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   246
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   247
PDFDocEncodingPattern = [
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   248
'<<'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   249
' /Differences'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   250
'    ['
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   251
' 24'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   252
' /breve'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   253
' /caron'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   254
' /circumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   255
' /dotaccent'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   256
' /hungarumlaut'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   257
' /ogonek'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   258
' /ring'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   259
' /tilde'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   260
' 39'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   261
' /quotesingle'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   262
' 96'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   263
' /grave'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   264
' 128'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   265
' /bullet'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   266
' /dagger'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   267
' /daggerdbl'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   268
' /ellipsis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   269
' /emdash'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   270
' /endash'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   271
' /florin'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   272
' /fraction'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   273
' /guilsinglleft'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   274
' /guilsinglright'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   275
' /minus'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   276
' /perthousand'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   277
' /quotedblbase'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   278
' /quotedblleft'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   279
' /quotedblright'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   280
' /quoteleft'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   281
' /quoteright'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   282
' /quotesinglbase'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   283
' /trademark'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   284
' /fi'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   285
' /fl'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   286
' /Lslash'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   287
' /OE'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   288
' /Scaron'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   289
' /Ydieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   290
' /Zcaron'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   291
' /dotlessi'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   292
' /lslash'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   293
' /oe'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   294
' /scaron'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   295
' /zcaron'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   296
' 160'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   297
' /Euro'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   298
' 164'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   299
' /currency'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   300
' 166'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   301
' /brokenbar'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   302
' 168'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   303
' /dieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   304
' /copyright'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   305
' /ordfeminine'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   306
' 172'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   307
' /logicalnot'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   308
' /.notdef'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   309
' /registered'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   310
' /macron'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   311
' /degree'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   312
' /plusminus'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   313
' /twosuperior'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   314
' /threesuperior'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   315
' /acute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   316
' /mu'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   317
' 183'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   318
' /periodcentered'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   319
' /cedilla'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   320
' /onesuperior'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   321
' /ordmasculine'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   322
' 188'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   323
' /onequarter'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   324
' /onehalf'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   325
' /threequarters'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   326
' 192'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   327
' /Agrave'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   328
' /Aacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   329
' /Acircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   330
' /Atilde'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   331
' /Adieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   332
' /Aring'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   333
' /AE'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   334
' /Ccedilla'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   335
' /Egrave'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   336
' /Eacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   337
' /Ecircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   338
' /Edieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   339
' /Igrave'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   340
' /Iacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   341
' /Icircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   342
' /Idieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   343
' /Eth'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   344
' /Ntilde'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   345
' /Ograve'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   346
' /Oacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   347
' /Ocircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   348
' /Otilde'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   349
' /Odieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   350
' /multiply'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   351
' /Oslash'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   352
' /Ugrave'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   353
' /Uacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   354
' /Ucircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   355
' /Udieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   356
' /Yacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   357
' /Thorn'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   358
' /germandbls'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   359
' /agrave'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   360
' /aacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   361
' /acircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   362
' /atilde'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   363
' /adieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   364
' /aring'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   365
' /ae'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   366
' /ccedilla'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   367
' /egrave'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   368
' /eacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   369
' /ecircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   370
' /edieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   371
' /igrave'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   372
' /iacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   373
' /icircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   374
' /idieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   375
' /eth'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   376
' /ntilde'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   377
' /ograve'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   378
' /oacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   379
' /ocircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   380
' /otilde'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   381
' /odieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   382
' /divide'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   383
' /oslash'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   384
' /ugrave'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   385
' /uacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   386
' /ucircumflex'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   387
' /udieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   388
' /yacute'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   389
' /thorn'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   390
' /ydieresis'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   391
'    ]'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   392
' /Type'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   393
' /Encoding'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   394
'>>']
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   395
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   396
def FormFont(BaseFont, Name):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   397
    from reportlab.pdfbase.pdfdoc import PDFName
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   398
    return PDFPattern(FormFontPattern, BaseFont=PDFName(BaseFont), Name=PDFName(Name), Encoding=PDFDOCENC)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   399
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   400
FormFontPattern = [
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   401
'<<',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   402
' /BaseFont ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   403
["BaseFont"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   404
' /Encoding ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   405
["Encoding"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   406
' /Name ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   407
["Name"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   408
' /Subtype '
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   409
' /Type1 '
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   410
' /Type '
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   411
' /Font '
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   412
'>>' ]
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   413
3637
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   414
def resetPdfForm():
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   415
    global PDFDOCENC,ENCODING,GLOBALFONTSDICTIONARY,GLOBALRESOURCES,ZADB
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   416
    PDFDOCENC = PDFPattern(PDFDocEncodingPattern)
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   417
    ENCODING = PDFPattern(EncodingPattern, PDFDocEncoding=PDFDOCENC)
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   418
    ZADB = PDFPattern(ZaDbPattern)
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   419
    GLOBALFONTSDICTIONARY = FormFontsDictionary()
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   420
    GLOBALRESOURCES = FormResources()
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   421
from reportlab.rl_config import register_reset
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   422
register_reset(resetPdfForm)
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   423
resetPdfForm()
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   424
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   425
def TextField(title, value, xmin, ymin, xmax, ymax, page,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   426
              maxlen=1000000, font="Helvetica-Bold", fontsize=9, R=0, G=0, B=0.627, multiline=0):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   427
    from reportlab.pdfbase.pdfdoc import PDFString, PDFName
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   428
    Flags = 0
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   429
    if multiline:
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   430
        Flags = Flags | (1<<12) # bit 13 is at position 12 :)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   431
    fontname = FORMFONTNAMES[font]
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   432
    return PDFPattern(TextFieldPattern,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   433
                      value=PDFString(value), maxlen=maxlen, page=page,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   434
                      title=PDFString(title),
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   435
                      xmin=xmin, ymin=ymin, xmax=xmax, ymax=ymax,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   436
                      fontname=PDFName(fontname), fontsize=fontsize, R=R, G=G, B=B, Flags=Flags)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   437
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   438
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   439
TextFieldPattern = [
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   440
'<<'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   441
' /DA'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   442
' (', ["fontname"],' ',["fontsize"],' Tf ',["R"],' ',["G"],' ',["B"],' rg)'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   443
' /DV ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   444
["value"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   445
' /F 4 /FT /Tx'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   446
'/MK << /BC [ 0 0 0 ] >>'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   447
' /MaxLen ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   448
["maxlen"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   449
' /P ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   450
["page"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   451
' /Rect '
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   452
'    [', ["xmin"], " ", ["ymin"], " ", ["xmax"], " ", ["ymax"], ' ]'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   453
'/Subtype /Widget'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   454
' /T ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   455
["title"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   456
' /Type'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   457
'    /Annot'
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   458
' /V ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   459
["value"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   460
' /Ff ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   461
["Flags"],LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   462
'>>']
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   463
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   464
def SelectField(title, value, options, xmin, ymin, xmax, ymax, page,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   465
              font="Helvetica-Bold", fontsize=9, R=0, G=0, B=0.627):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   466
    #print "ARGS", (title, value, options, xmin, ymin, xmax, ymax, page, font, fontsize, R, G, B)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   467
    from reportlab.pdfbase.pdfdoc import PDFString, PDFName, PDFArray
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   468
    if value not in options:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3637
diff changeset
   469
        raise ValueError("value %s must be one of options %s" % (repr(value), repr(options)))
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   470
    fontname = FORMFONTNAMES[font]
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3637
diff changeset
   471
    optionstrings = list(map(PDFString, options))
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   472
    optionarray = PDFArray(optionstrings)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   473
    return PDFPattern(SelectFieldPattern,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   474
                      Options=optionarray,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   475
                      Selected=PDFString(value), Page=page,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   476
                      Name=PDFString(title),
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   477
                      xmin=xmin, ymin=ymin, xmax=xmax, ymax=ymax,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   478
                      fontname=PDFName(fontname), fontsize=fontsize, R=R, G=G, B=B)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   479
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   480
SelectFieldPattern = [
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   481
'<< % a select list',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   482
' /DA ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   483
' (', ["fontname"],' ',["fontsize"],' Tf ',["R"],' ',["G"],' ',["B"],' rg)',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   484
#'    (/Helv 12 Tf 0 g)',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   485
' /DV ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   486
["Selected"],LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   487
' /F ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   488
'    4',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   489
' /FT ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   490
'    /Ch',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   491
' /MK ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   492
'    <<',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   493
'    /BC',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   494
'        [',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   495
'            0',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   496
'            0',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   497
'            0',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   498
'        ]',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   499
'    /BG',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   500
'        [',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   501
'            1',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   502
'            1',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   503
'            1',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   504
'        ]',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   505
'    >>',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   506
' /Opt ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   507
["Options"],LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   508
' /P ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   509
["Page"],LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   510
'/Rect',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   511
'    [',["xmin"], " ", ["ymin"], " ", ["xmax"], " ", ["ymax"],
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   512
'    ] ',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   513
'/Subtype',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   514
'    /Widget',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   515
' /T ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   516
["Name"],LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   517
' /Type ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   518
'    /Annot',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   519
' /V ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   520
["Selected"],LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   521
'>>']
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   522
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   523
def ButtonField(title, value, xmin, ymin, page):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   524
    if value not in ("Yes", "Off"):
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3637
diff changeset
   525
        raise ValueError("button value must be 'Yes' or 'Off': "+repr(value))
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   526
    (dx, dy) = (16.77036, 14.90698)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   527
    return PDFPattern(ButtonFieldPattern,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   528
                      Name=PDFString(title),
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   529
                      xmin=xmin, ymin=ymin, xmax=xmin+dx, ymax=ymin+dy,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   530
                      Hide=HIDE,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   531
                      APDOff=APDOFF,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   532
                      APDYes=APDYES,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   533
                      APNYes=APNYES,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   534
                      Value=PDFName(value),
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   535
                      Page=page)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   536
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   537
ButtonFieldPattern = ['<< ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   538
'/AA',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   539
'    <<',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   540
'    /D ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   541
["Hide"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   542
#'        %(imported.18.0)s',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   543
'    >> ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   544
'/AP ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   545
'    <<',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   546
'    /D',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   547
'        <<',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   548
'        /Off ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   549
#'            %(imported.40.0)s',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   550
["APDOff"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   551
'        /Yes ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   552
#'            %(imported.39.0)s',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   553
["APDYes"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   554
'        >>', LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   555
'    /N',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   556
'        << ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   557
'        /Yes ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   558
#'            %(imported.38.0)s',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   559
["APNYes"],  LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   560
'        >>',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   561
'    >>', LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   562
' /AS ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   563
["Value"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   564
' /DA ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   565
PDFString('/ZaDb 0 Tf 0 g'), LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   566
'/DV ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   567
["Value"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   568
'/F ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   569
'    4 ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   570
'/FT ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   571
'    /Btn ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   572
'/H ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   573
'    /T ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   574
'/MK ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   575
'    <<',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   576
'    /AC (\\376\\377)',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   577
#PDFString('\376\377'),
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   578
'    /CA ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   579
PDFString('4'),
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   580
'    /RC ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   581
PDFString('\376\377'),
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   582
'    >> ',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   583
'/P ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   584
["Page"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   585
'/Rect',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   586
'    [',["xmin"], " ", ["ymin"], " ", ["xmax"], " ", ["ymax"],
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   587
'    ] ',LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   588
'/Subtype',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   589
'    /Widget ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   590
'/T ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   591
["Name"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   592
'/Type',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   593
'    /Annot ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   594
'/V ',
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   595
["Value"], LINEEND,
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   596
' >>']
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   597
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   598
HIDE = PDFPattern([
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   599
'<< '
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   600
'/S '
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   601
' /Hide '
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   602
'>>'])
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   603
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   604
def buttonStreamDictionary():
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   605
    "everything except the length for the button appearance streams"
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   606
    result = PDFDictionary()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   607
    result["SubType"] = "/Form"
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   608
    result["BBox"] = "[0 0 16.77036 14.90698]"
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   609
    font = PDFDictionary()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   610
    font["ZaDb"] = ZADB
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   611
    resources = PDFDictionary()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   612
    resources["ProcSet"] = "[ /PDF /Text ]"
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   613
    resources["Font"] = font
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   614
    result["Resources"] = resources
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   615
    return result
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   616
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   617
def ButtonStream(content):
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   618
    dict = buttonStreamDictionary()
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   619
    result = PDFStream(dict, content)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   620
    result.filters = []
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   621
    return result
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   622
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   623
APDOFF = ButtonStream('0.749 g 0 0 16.7704 14.907 re f'+LINEEND)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1660
diff changeset
   624
APDYES = ButtonStream(
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   625
'0.749 g 0 0 16.7704 14.907 re f q 1 1 14.7704 12.907 re W '+
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   626
'n BT /ZaDb 11.3086 Tf 0 g  1 0 0 1 3.6017 3.3881 Tm (4) Tj ET'+LINEEND)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   627
APNYES = ButtonStream(
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   628
'q 1 1 14.7704 12.907 re W n BT /ZaDb 11.3086 Tf 0 g  1 0 0 1 3.6017 3.3881 Tm (4) Tj ET Q'+LINEEND)
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   629
3637
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3317
diff changeset
   630
1660
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   631
#==== script interpretation
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   632
c93476060b9d simple support for acrobat forms in reportlab documents. Minor optimizations to metrics
aaron_watters
parents:
diff changeset
   633
if __name__=="__main__":
3254
dd9042134279 canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents: 2964
diff changeset
   634
    test1()