@@ -72,14 +72,16 @@ class AnnotationFactory {
72
72
static create ( xref , ref , pdfManager , idFactory , collectFields ) {
73
73
return Promise . all ( [
74
74
pdfManager . ensureCatalog ( "acroForm" ) ,
75
+ pdfManager . ensureDoc ( "xfaDatasets" ) ,
75
76
collectFields ? this . _getPageIndex ( xref , ref , pdfManager ) : - 1 ,
76
- ] ) . then ( ( [ acroForm , pageIndex ] ) =>
77
+ ] ) . then ( ( [ acroForm , xfaDatasets , pageIndex ] ) =>
77
78
pdfManager . ensure ( this , "_create" , [
78
79
xref ,
79
80
ref ,
80
81
pdfManager ,
81
82
idFactory ,
82
83
acroForm ,
84
+ xfaDatasets ,
83
85
collectFields ,
84
86
pageIndex ,
85
87
] )
@@ -95,6 +97,7 @@ class AnnotationFactory {
95
97
pdfManager ,
96
98
idFactory ,
97
99
acroForm ,
100
+ xfaDatasets ,
98
101
collectFields ,
99
102
pageIndex = - 1
100
103
) {
@@ -119,6 +122,7 @@ class AnnotationFactory {
119
122
id,
120
123
pdfManager,
121
124
acroForm : acroForm instanceof Dict ? acroForm : Dict . empty ,
125
+ xfaDatasets,
122
126
collectFields,
123
127
pageIndex,
124
128
} ;
@@ -1237,7 +1241,7 @@ class WidgetAnnotation extends Annotation {
1237
1241
) ;
1238
1242
}
1239
1243
1240
- const fieldValue = getInheritableProperty ( {
1244
+ let fieldValue = getInheritableProperty ( {
1241
1245
dict,
1242
1246
key : "V" ,
1243
1247
getArray : true ,
@@ -1251,6 +1255,15 @@ class WidgetAnnotation extends Annotation {
1251
1255
} ) ;
1252
1256
data . defaultFieldValue = this . _decodeFormValue ( defaultFieldValue ) ;
1253
1257
1258
+ if ( fieldValue === undefined && params . xfaDatasets ) {
1259
+ // Try to figure out if we have something in the xfa dataset.
1260
+ const path = stringToPDFString ( dict . get ( "T" ) || "" ) ;
1261
+ if ( path ) {
1262
+ data . hasValueFromXFA = true ;
1263
+ data . fieldValue = fieldValue = params . xfaDatasets . getValue ( path ) ;
1264
+ }
1265
+ }
1266
+
1254
1267
// When no "V" entry exists, let the fieldValue fallback to the "DV" entry
1255
1268
// (fixes issue13823.pdf).
1256
1269
if ( fieldValue === undefined && data . defaultFieldValue !== null ) {
@@ -1401,17 +1414,20 @@ class WidgetAnnotation extends Annotation {
1401
1414
}
1402
1415
1403
1416
async save ( evaluator , task , annotationStorage ) {
1404
- if ( ! annotationStorage ) {
1405
- return null ;
1406
- }
1407
- const storageEntry = annotationStorage . get ( this . data . id ) ;
1408
- const value = storageEntry && storageEntry . value ;
1417
+ const storageEntry = annotationStorage
1418
+ ? annotationStorage . get ( this . data . id )
1419
+ : undefined ;
1420
+ let value = storageEntry && storageEntry . value ;
1409
1421
if ( value === this . data . fieldValue || value === undefined ) {
1410
- return null ;
1422
+ if ( ! this . data . hasValueFromXFA ) {
1423
+ return null ;
1424
+ }
1425
+ value = value || this . data . fieldValue ;
1411
1426
}
1412
1427
1413
1428
// Value can be an array (with choice list and multiple selections)
1414
1429
if (
1430
+ ! this . data . hasValueFromXFA &&
1415
1431
Array . isArray ( value ) &&
1416
1432
Array . isArray ( this . data . fieldValue ) &&
1417
1433
value . length === this . data . fieldValue . length &&
@@ -1493,14 +1509,23 @@ class WidgetAnnotation extends Annotation {
1493
1509
1494
1510
async _getAppearance ( evaluator , task , annotationStorage ) {
1495
1511
const isPassword = this . hasFieldFlag ( AnnotationFieldFlag . PASSWORD ) ;
1496
- if ( ! annotationStorage || isPassword ) {
1512
+ if ( isPassword ) {
1497
1513
return null ;
1498
1514
}
1499
- const storageEntry = annotationStorage . get ( this . data . id ) ;
1515
+ const storageEntry = annotationStorage
1516
+ ? annotationStorage . get ( this . data . id )
1517
+ : undefined ;
1500
1518
let value = storageEntry && storageEntry . value ;
1501
1519
if ( value === undefined ) {
1502
- // The annotation hasn't been rendered so use the appearance
1503
- return null ;
1520
+ if ( ! this . data . hasValueFromXFA || this . appearance ) {
1521
+ // The annotation hasn't been rendered so use the appearance.
1522
+ return null ;
1523
+ }
1524
+ // The annotation has its value in XFA datasets but not in the V field.
1525
+ value = this . data . fieldValue ;
1526
+ if ( ! value ) {
1527
+ return "" ;
1528
+ }
1504
1529
}
1505
1530
1506
1531
value = value . trim ( ) ;
0 commit comments