mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Fixes to get field heirarchy working
This commit is contained in:
parent
e135aad920
commit
1553ca8498
4
.gitignore
vendored
4
.gitignore
vendored
@ -13,3 +13,7 @@ demo/bundle.js
|
||||
coverage
|
||||
tests/integration/__pdfs__
|
||||
tests/integration/pdfmake/__pdfs__
|
||||
tests/integration/**/__snapshots__/*
|
||||
tests/integration/__snapshots__/*
|
||||
*.snap
|
||||
/*.pdf
|
||||
|
||||
@ -17,10 +17,10 @@ doc.font('Helvetica') // establishes the default font
|
||||
doc.initAcroForm();
|
||||
|
||||
let rootField = doc.field('rootField');
|
||||
let child1Field = doc.field('child1Field', { parent: rootField });
|
||||
let child2Field = doc.field('child2Field', { parent: rootField });
|
||||
doc.formText('leaf1', 10, 10, 200, 40, { parent: child1Field })
|
||||
doc.formText('leaf2', 10, 60, 200, 40, { parent: child1Field })
|
||||
doc.formText('leaf3', 10, 110, 200, 40, { parent: child2Field })
|
||||
let child1Field = doc.field('child1Field', { Parent: rootField });
|
||||
let child2Field = doc.field('child2Field', { Parent: rootField });
|
||||
doc.formText('leaf1', 10, 10, 200, 40, { Parent: child1Field })
|
||||
doc.formText('leaf2', 10, 60, 200, 40, { Parent: child1Field })
|
||||
doc.formText('leaf3', 10, 110, 200, 40, { Parent: child2Field })
|
||||
|
||||
doc.end();
|
||||
|
||||
@ -74,32 +74,29 @@ export default {
|
||||
field (name, options = {}) {
|
||||
let fieldDict = this._fieldDict(name, options);
|
||||
let fieldRef = this.ref(fieldDict);
|
||||
this._addToParent(fieldRef, options.parent);
|
||||
delete options.parent;
|
||||
this._addToParent(fieldRef);
|
||||
return fieldRef;
|
||||
},
|
||||
|
||||
widgetAnnot (name, x, y, w, h, options = {}) {
|
||||
let fieldDict = this._fieldDict(name, null, options);
|
||||
let fieldDict = this._fieldDict(name, options);
|
||||
fieldDict.Subtype = 'Widget';
|
||||
fieldDict.F = 4;
|
||||
let parent = options.parent;
|
||||
delete options.parent;
|
||||
|
||||
// Add Field annot to page, and get it's ref
|
||||
this.annotate(x, y, w, h, fieldDict);
|
||||
let annotRef = this.page.annotations[this.page.annotations.length - 1];
|
||||
|
||||
return this._addToParent(annotRef, parent);
|
||||
return this._addToParent(annotRef);
|
||||
},
|
||||
|
||||
_addToParent (fieldRef, parentRef) {
|
||||
if (parentRef) {
|
||||
if (!parentRef.data.Kids) {
|
||||
parentRef.data.Kids = [];
|
||||
_addToParent (fieldRef) {
|
||||
let parent = fieldRef.data.Parent;
|
||||
if (parent) {
|
||||
if (!parent.data.Kids) {
|
||||
parent.data.Kids = [];
|
||||
}
|
||||
parentRef.data.Kids.push(fieldRef);
|
||||
fieldRef.data.Parent = parentRef;
|
||||
parent.data.Kids.push(fieldRef);
|
||||
} else {
|
||||
this._root.data.AcroForm.data.Fields.push(fieldRef);
|
||||
}
|
||||
|
||||
@ -66,11 +66,11 @@ describe('AcroForm', () => {
|
||||
doc.initAcroForm()
|
||||
|
||||
let rootField = doc.field('rootField');
|
||||
let child1Field = doc.field('child1Field', { parent: rootField });
|
||||
let child2Field = doc.field('child2Field', { parent: rootField });
|
||||
doc.formText('leaf1', 10, 10, 200, 40, { parent: child1Field })
|
||||
doc.formText('leaf2', 10, 60, 200, 40, { parent: child1Field })
|
||||
doc.formText('leaf3', 10, 110, 200, 40, { parent: child2Field })
|
||||
let child1Field = doc.field('child1Field', { Parent: rootField });
|
||||
let child2Field = doc.field('child2Field', { Parent: rootField });
|
||||
doc.formText('leaf1', 10, 10, 200, 40, { Parent: child1Field })
|
||||
doc.formText('leaf2', 10, 60, 200, 40, { Parent: child1Field })
|
||||
doc.formText('leaf3', 10, 110, 200, 40, { Parent: child2Field })
|
||||
|
||||
doc.end();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user