Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Simple pdfmark form example
- % by Jim DeLaHunt, jdlh.com, 3. March 2012
- %
- % This PostScript language code, when converted to PDF by
- % Adobe Acrobat Distiller or the like, creates a PDF file with form
- % fields, and a Submit button which sends the values of the fields
- % via an HTTP POST request.
- %
- % In reply to Stack Overflow question, "How can I create a PDF form
- % using PDFMARK and/or PERL cpan module PDF::API2?",
- % http://stackoverflow.com/questions/9440930/
- %
- % AcroForm dictionary setup. From pdfmark Reference, Example 5.11, p.70
- %
- % Read also PDF specification PDF32000:2008
- % "Document management — Portable document format — Part 1: PDF 1.7",
- % Section 12.7 "Interactive Forms", p.430
- % To understand the syntax: [/_objdef {foo} /type /dict /OBJ pdfmark
- % read carefully pdfMark reference, "User-defined named objects", p.13.
- % Define font objects for the widgets to use
- [ /_objdef {ZaDb} /type /dict /OBJ pdfmark
- [ {ZaDb} <<
- /Type /Font
- /Subtype /Type1
- /Name /ZaDb
- /BaseFont /ZapfDingbats
- >> /PUT pdfmark
- [ /_objdef {Helv} /type /dict /OBJ pdfmark
- [ {Helv} <<
- /Type /Font
- /Subtype /Type1
- /Name /Helv
- /BaseFont /Helvetica
- % /Encoding {pdfDocEncoding} % for simplicity, use font's own encoding
- % pdfmark Reference, Example 5.11, p.70, provides an Encoding
- % array defining PDFDocEncoding
- >> /PUT pdfmark
- [ /_objdef {aform} /type /dict /OBJ pdfmark
- % Define Fields array of Acroform dictionary. It will contain entries for
- % each of the widgets defined below.
- % NOTE: It is not necessary to explicitly assign the widget annotations
- % to the Fields array; Acrobat does it automatically when the file is
- % opened.
- [ /_objdef {afields} /type /array /OBJ pdfmark
- [ {aform} <<
- /Fields {afields}
- /DR << /Font << /ZaDb {ZaDb} /Helv {Helv} >> >>
- /DA (/Helv 0 Tf 0 g)
- /NeedAppearances true
- % "/NeedAppearances true" tells reader 'to construct appearance
- % streams and appearance dictionaries for all widget annotations
- % in the document...' --PDF32000:2008 Table 218 p.431
- >> /PUT pdfmark
- % Put Acroform entry in catalog dictionary
- [ {Catalog} << /AcroForm {aform} >> /PUT pdfmark
- % Example 5.12 Define the Widget annotations
- % pdfmark Reference pp. 72-75, with clarifications by Jim DeLaHunt
- %
- % These Widget annotations are also field dictionaries for this form.
- % This is the collection of all individual widget annotations.
- % It is possible to have multiple instances of these sections, such as
- % for defining a single widget on each instance.
- %
- % See PDF32000:2008 Section 12.5.6.19 "Widget Annotations", p.408
- % especially tables 188 and 189.
- [ /Subtype /Widget
- /Rect [100 223 245 260]
- /F 4
- /T (SL Text)
- /FT /Tx
- /DA (/Helv 14 Tf 0 0 1 rg)
- /V (5)
- /AA <<
- /K <<
- /S /JavaScript
- /JS (AFNumber_Keystroke\(2, 0, 0, 0, "$", true\);)
- >>
- /V <<
- /S /JavaScript
- /JS (2;)
- >>
- /F <<
- /S /JavaScript
- /JS (AFNumber_Format\(2, 0, 0, 0, "$", true\);)
- % pdfmark Reference p.72 seems to omit closing ")" above. Oops.
- >>
- >>
- /ANN pdfmark
- showpage % make sure a page gets produced
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement