diff --git a/lib/mixins/acroform.js b/lib/mixins/acroform.js index 3ea5271..0b608cc 100644 --- a/lib/mixins/acroform.js +++ b/lib/mixins/acroform.js @@ -13,6 +13,11 @@ const FIELD_FLAGS = { edit: 0x40000, sort: 0x80000 }; +const FIELD_JUSTIFY = { + left: 0, + center: 1, + right: 2 +}; export default { @@ -63,7 +68,9 @@ export default { } let opts = Object.assign({}, options); opts = this._resolveFlags(opts); + opts = this._resolveJustify(opts); opts = this._resolveFont(opts); + opts = this._resolveStrings(opts); opts = Object.assign(opts, { Subtype: 'Widget', F: 4, @@ -92,6 +99,14 @@ export default { return options; }, + _resolveJustify (options) { + if (options.align && FIELD_JUSTIFY[options.align]) { + options.Q = FIELD_JUSTIFY[options.align]; + delete options.align; + } + return options; + }, + _resolveFont (options) { // add current font to document-level AcroForm dict if necessary if (this._acroform.fonts[this._font.id] == null) { @@ -106,6 +121,27 @@ export default { return options; }, + _resolveStrings (options) { + if (Array.isArray(options.Opt)) { + let arr = []; + for (let idx = 0; idx < options.Opt.length; idx++) { + if (typeof options.Opt[idx] === 'string') { + arr.push(new String(options.Opt[idx])) + } else { + arr.push(options.Opt[idx]) + } + arr.push(new String(options.Opt[idx])); + } + options.Opt = arr; + } + ['V', 'DV'].forEach(key => { + if (typeof options[key] === 'string') { + options[key] = new String(options[key]); + } + }); + return options; + }, + formButton (name, x, y, w, h, options = {}) { options.FT = 'Btn'; return this.formAnnot(name, x, y, w, h, options) diff --git a/tests/unit/acroform.spec.js b/tests/unit/acroform.spec.js index 44cdac0..9350b98 100644 --- a/tests/unit/acroform.spec.js +++ b/tests/unit/acroform.spec.js @@ -36,7 +36,7 @@ describe('AcroForm', () => { test('standard fonts', () => { - // const docData = logData(doc); + const docData = logData(doc); doc.registerFont('myfont1', 'tests/fonts/Roboto-Regular.ttf')