Advertisement
Guest User

Untitled

a guest
Mar 16th, 2021
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. % Simple pdfmark form example
  2. % by Jim DeLaHunt, jdlh.com, 3. March 2012
  3. %
  4. % This PostScript language code, when converted to PDF by
  5. % Adobe Acrobat Distiller or the like, creates a PDF file with form
  6. % fields, and a Submit button which sends the values of the fields
  7. % via an HTTP POST request.
  8. %
  9. % In reply to Stack Overflow question, "How can I create a PDF form
  10. % using PDFMARK and/or PERL cpan module PDF::API2?",
  11. % http://stackoverflow.com/questions/9440930/
  12. %
  13.  
  14. % AcroForm dictionary setup. From pdfmark Reference, Example 5.11, p.70
  15. %
  16. % Read also PDF specification PDF32000:2008
  17. % "Document management — Portable document format — Part 1: PDF 1.7",
  18. % Section 12.7 "Interactive Forms", p.430
  19. % To understand the syntax: [/_objdef {foo} /type /dict /OBJ pdfmark
  20. % read carefully pdfMark reference, "User-defined named objects", p.13.
  21.  
  22. % Define font objects for the widgets to use
  23. [ /_objdef {ZaDb} /type /dict /OBJ pdfmark
  24. [ {ZaDb} <<
  25.     /Type /Font
  26.     /Subtype /Type1
  27.     /Name /ZaDb
  28.     /BaseFont /ZapfDingbats
  29. >> /PUT pdfmark
  30. [ /_objdef {Helv} /type /dict /OBJ pdfmark
  31. [ {Helv} <<
  32.     /Type /Font
  33.     /Subtype /Type1
  34.     /Name /Helv
  35.     /BaseFont /Helvetica
  36.     % /Encoding {pdfDocEncoding} % for simplicity, use font's own encoding
  37.     % pdfmark Reference, Example 5.11, p.70, provides an Encoding
  38.     % array defining PDFDocEncoding
  39. >> /PUT pdfmark
  40.  
  41. [ /_objdef {aform} /type /dict /OBJ pdfmark
  42.  
  43. % Define Fields array of Acroform dictionary. It will contain entries for
  44. % each of the widgets defined below.
  45. % NOTE: It is not necessary to explicitly assign the widget annotations
  46. % to the Fields array; Acrobat does it automatically when the file is
  47. % opened.
  48.  
  49. [ /_objdef {afields} /type /array /OBJ pdfmark
  50. [ {aform} <<
  51.     /Fields {afields}
  52.     /DR << /Font << /ZaDb {ZaDb} /Helv {Helv} >> >>
  53.     /DA (/Helv 0 Tf 0 g)
  54.     /NeedAppearances true
  55.     % "/NeedAppearances true" tells reader 'to construct appearance
  56.     % streams and appearance dictionaries for all widget annotations
  57.     % in the document...' --PDF32000:2008 Table 218 p.431
  58. >> /PUT pdfmark
  59.  
  60. % Put Acroform entry in catalog dictionary
  61. [ {Catalog} << /AcroForm {aform} >> /PUT pdfmark
  62.  
  63.  
  64. % Example 5.12 Define the Widget annotations
  65. % pdfmark Reference pp. 72-75, with clarifications by Jim DeLaHunt
  66. %
  67. % These Widget annotations are also field dictionaries for this form.
  68. % This is the collection of all individual widget annotations.
  69. % It is possible to have multiple instances of these sections, such as
  70. % for defining a single widget on each instance.
  71. %
  72. % See PDF32000:2008 Section 12.5.6.19 "Widget Annotations", p.408
  73. % especially tables 188 and 189.
  74.  
  75. [ /Subtype /Widget
  76.     /Rect [100 223 245 260]
  77.     /F 4
  78.     /T (SL Text)
  79.     /FT /Tx
  80.     /DA (/Helv 14 Tf 0 0 1 rg)
  81.     /V (5)
  82.     /AA <<
  83.         /K <<
  84.             /S /JavaScript
  85.             /JS (AFNumber_Keystroke\(2, 0, 0, 0, "$", true\);)
  86.         >>
  87.         /V <<
  88.             /S /JavaScript
  89.             /JS (2;)
  90.         >>
  91.         /F <<
  92.             /S /JavaScript
  93.             /JS (AFNumber_Format\(2, 0, 0, 0, "$", true\);)
  94.             % pdfmark Reference p.72 seems to omit closing ")" above. Oops.
  95.         >>
  96.     >>
  97. /ANN pdfmark
  98.  
  99. showpage  % make sure a page gets produced
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement