standard.spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* @TODO Enable 'use strict', remove all these globals */
  2. /* global describe, xit, it, jsPDF, comparePdf, ComboBox, ListBox, PushButton, CheckBox, TextField, PasswordField, RadioButton, AcroForm */
  3. /**
  4. * Acroform testing
  5. */
  6. describe('Acroform', function () {
  7. // @TODO: Raise ticket with AcroForms developer about IE and other issues
  8. if (navigator.userAgent.indexOf('Trident') !== -1) {
  9. console.warn('Skipping IE for AcroForms')
  10. return
  11. }
  12. xit('should add a ComboBox', function () {
  13. var doc = jsPDF()
  14. doc.setFontSize(12)
  15. doc.text(10, 105, 'ComboBox:')
  16. var d = new ComboBox()
  17. d.T = 'ChoiceField1'
  18. d.TI = 1
  19. d.Rect = [50, 100, 30, 10]
  20. d.Opt = '[(a)(b)(c)]'
  21. d.V = '(b)'
  22. d.DV = '(b)'
  23. doc.addField(d)
  24. comparePdf(doc.output(), 'combobox.pdf', 'acroform')
  25. })
  26. xit('should add a CheckBox', function () {
  27. var doc = jsPDF()
  28. doc.text(10, 125, 'CheckBox:')
  29. var checkBox = new CheckBox()
  30. checkBox.T = 'CheckBox1'
  31. checkBox.Rect = [50, 120, 30, 10]
  32. doc.addField(checkBox)
  33. comparePdf(doc.output(), 'checkbox.pdf', 'acroform')
  34. })
  35. it('should add a ListBox', function () {
  36. var doc = jsPDF()
  37. doc.setFontSize(12)
  38. doc.text(10, 115, 'ListBox:')
  39. var d2 = new ListBox()
  40. d2.edit = false
  41. d2.T = 'ChoiceField2'
  42. d2.TI = 2
  43. d2.Rect = [50, 110, 30, 10]
  44. d2.Opt = '[(c)(a)(d)(f)(b)(s)]'
  45. d2.V = '(s)'
  46. d2.BG = [0, 1, 1]
  47. doc.addField(d2)
  48. comparePdf(doc.output(), 'listbox.pdf', 'acroform')
  49. })
  50. it('should add a PushButton', function () {
  51. var doc = jsPDF()
  52. doc.text(10, 135, 'PushButton:')
  53. var pushButton = new PushButton()
  54. pushButton.T = 'PushButton1'
  55. pushButton.Rect = [50, 130, 30, 10]
  56. pushButton.BG = [1, 0, 0]
  57. doc.addField(pushButton)
  58. comparePdf(doc.output(), 'pushbutton.pdf', 'acroform')
  59. })
  60. xit('should add a TextField', function () {
  61. var doc = jsPDF()
  62. doc.text(10, 145, 'TextField:')
  63. var textField = new TextField()
  64. textField.Rect = [50, 140, 30, 10]
  65. textField.multiline = true
  66. textField.V = 'The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse'//
  67. textField.T = 'TestTextBox'
  68. // textField.Q = 2; // Text-Alignment
  69. doc.addField(textField)
  70. comparePdf(doc.output(), 'textfield.pdf', 'acroform')
  71. })
  72. it('should add a Password', function () {
  73. var doc = jsPDF()
  74. doc.text(10, 155, 'Password:')
  75. var passwordField = new PasswordField()
  76. passwordField.Rect = [50, 150, 30, 10]
  77. doc.addField(passwordField)
  78. comparePdf(doc.output(), 'password.pdf', 'acroform')
  79. })
  80. it('should add a RadioGroup', function () {
  81. var doc = jsPDF()
  82. doc.text(50, 165, 'RadioGroup:')
  83. var radioGroup = new RadioButton()
  84. radioGroup.V = '/Test'
  85. radioGroup.Subtype = 'Form'
  86. doc.addField(radioGroup)
  87. var radioButton1 = radioGroup.createOption('Test')
  88. radioButton1.Rect = [50, 170, 30, 10]
  89. radioButton1.AS = '/Test'
  90. var radioButton2 = radioGroup.createOption('Test2')
  91. radioButton2.Rect = [50, 180, 30, 10]
  92. var radioButton3 = radioGroup.createOption('Test3')
  93. radioButton3.Rect = [50, 190, 20, 10]
  94. radioGroup.setAppearance(AcroForm.Appearance.RadioButton.Cross)
  95. comparePdf(doc.output(), 'radiogroup.pdf', 'acroform')
  96. })
  97. })