19
19
20
20
import {
21
21
AbortException ,
22
+ AnnotationMode ,
22
23
assert ,
23
24
createPromiseCapability ,
24
25
getVerbosityLevel ,
@@ -1135,9 +1136,18 @@ class PDFDocumentProxy {
1135
1136
* the `PDFPageProxy.getViewport` method.
1136
1137
* @property {string } [intent] - Rendering intent, can be 'display', 'print',
1137
1138
* or 'any'. The default value is 'display'.
1138
- * @property {boolean } [renderInteractiveForms] - Whether or not interactive
1139
- * form elements are rendered in the display layer. If so, we do not render
1140
- * them on the canvas as well. The default value is `false`.
1139
+ * @property {number } [annotationMode] Controls which annotations are rendered
1140
+ * onto the canvas, for annotations with appearance-data; the values from
1141
+ * {@link AnnotationMode} should be used. The following values are supported:
1142
+ * - `AnnotationMode.DISABLE`, which disables all annotations.
1143
+ * - `AnnotationMode.ENABLE`, which includes all possible annotations (thus
1144
+ * it also depends on the `intent`-option, see above).
1145
+ * - `AnnotationMode.ENABLE_FORMS`, which excludes annotations that contain
1146
+ * interactive form elements (those will be rendered in the display layer).
1147
+ * - `AnnotationMode.ENABLE_STORAGE`, which includes all possible annotations
1148
+ * (as above) but where interactive form elements are updated with data
1149
+ * from the {@link AnnotationStorage}-instance; useful e.g. for printing.
1150
+ * The default value is `AnnotationMode.ENABLE`.
1141
1151
* @property {Array<any> } [transform] - Additional transform, applied just
1142
1152
* before viewport transform.
1143
1153
* @property {Object } [imageLayer] - An object that has `beginLayout`,
@@ -1149,9 +1159,6 @@ class PDFDocumentProxy {
1149
1159
* <color> value, a `CanvasGradient` object (a linear or radial gradient) or
1150
1160
* a `CanvasPattern` object (a repetitive image). The default value is
1151
1161
* 'rgb(255,255,255)'.
1152
- * @property {boolean } [includeAnnotationStorage] - Render stored interactive
1153
- * form element data, from the {@link AnnotationStorage}-instance, onto the
1154
- * canvas itself; useful e.g. for printing. The default value is `false`.
1155
1162
* @property {Promise<OptionalContentConfig> } [optionalContentConfigPromise] -
1156
1163
* A promise that should resolve with an {@link OptionalContentConfig}
1157
1164
* created from `PDFDocumentProxy.getOptionalContentConfig`. If `null`,
@@ -1165,6 +1172,18 @@ class PDFDocumentProxy {
1165
1172
* @typedef {Object } GetOperatorListParameters
1166
1173
* @property {string } [intent] - Rendering intent, can be 'display', 'print',
1167
1174
* or 'any'. The default value is 'display'.
1175
+ * @property {number } [annotationMode] Controls which annotations are included
1176
+ * in the operatorList, for annotations with appearance-data; the values from
1177
+ * {@link AnnotationMode} should be used. The following values are supported:
1178
+ * - `AnnotationMode.DISABLE`, which disables all annotations.
1179
+ * - `AnnotationMode.ENABLE`, which includes all possible annotations (thus
1180
+ * it also depends on the `intent`-option, see above).
1181
+ * - `AnnotationMode.ENABLE_FORMS`, which excludes annotations that contain
1182
+ * interactive form elements (those will be rendered in the display layer).
1183
+ * - `AnnotationMode.ENABLE_STORAGE`, which includes all possible annotations
1184
+ * (as above) but where interactive form elements are updated with data
1185
+ * from the {@link AnnotationStorage}-instance; useful e.g. for printing.
1186
+ * The default value is `AnnotationMode.ENABLE`.
1168
1187
*/
1169
1188
1170
1189
/**
@@ -1280,7 +1299,7 @@ class PDFPageProxy {
1280
1299
* {Array} of the annotation objects.
1281
1300
*/
1282
1301
getAnnotations ( { intent = "display" } = { } ) {
1283
- const intentArgs = this . _transport . getRenderingIntent ( intent , { } ) ;
1302
+ const intentArgs = this . _transport . getRenderingIntent ( intent ) ;
1284
1303
1285
1304
let promise = this . _annotationPromises . get ( intentArgs . cacheKey ) ;
1286
1305
if ( ! promise ) {
@@ -1324,22 +1343,48 @@ class PDFPageProxy {
1324
1343
canvasContext,
1325
1344
viewport,
1326
1345
intent = "display" ,
1327
- renderInteractiveForms = false ,
1346
+ annotationMode = AnnotationMode . ENABLE ,
1328
1347
transform = null ,
1329
1348
imageLayer = null ,
1330
1349
canvasFactory = null ,
1331
1350
background = null ,
1332
- includeAnnotationStorage = false ,
1333
1351
optionalContentConfigPromise = null ,
1334
1352
} ) {
1353
+ if ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "GENERIC" ) ) {
1354
+ if ( arguments [ 0 ] ?. renderInteractiveForms !== undefined ) {
1355
+ deprecated (
1356
+ "render no longer accepts the `renderInteractiveForms`-option, " +
1357
+ "please use the `annotationMode`-option instead."
1358
+ ) ;
1359
+ if (
1360
+ arguments [ 0 ] . renderInteractiveForms === true &&
1361
+ annotationMode === AnnotationMode . ENABLE
1362
+ ) {
1363
+ annotationMode = AnnotationMode . ENABLE_FORMS ;
1364
+ }
1365
+ }
1366
+ if ( arguments [ 0 ] ?. includeAnnotationStorage !== undefined ) {
1367
+ deprecated (
1368
+ "render no longer accepts the `includeAnnotationStorage`-option, " +
1369
+ "please use the `annotationMode`-option instead."
1370
+ ) ;
1371
+ if (
1372
+ arguments [ 0 ] . includeAnnotationStorage === true &&
1373
+ annotationMode === AnnotationMode . ENABLE
1374
+ ) {
1375
+ annotationMode = AnnotationMode . ENABLE_STORAGE ;
1376
+ }
1377
+ }
1378
+ }
1379
+
1335
1380
if ( this . _stats ) {
1336
1381
this . _stats . time ( "Overall" ) ;
1337
1382
}
1338
1383
1339
- const intentArgs = this . _transport . getRenderingIntent ( intent , {
1340
- renderForms : renderInteractiveForms === true ,
1341
- includeAnnotationStorage : includeAnnotationStorage === true ,
1342
- } ) ;
1384
+ const intentArgs = this . _transport . getRenderingIntent (
1385
+ intent ,
1386
+ annotationMode
1387
+ ) ;
1343
1388
// If there was a pending destroy, cancel it so no cleanup happens during
1344
1389
// this call to render.
1345
1390
this . pendingCleanup = false ;
@@ -1460,7 +1505,10 @@ class PDFPageProxy {
1460
1505
* @returns {Promise<PDFOperatorList> } A promise resolved with an
1461
1506
* {@link PDFOperatorList} object that represents the page's operator list.
1462
1507
*/
1463
- getOperatorList ( { intent = "display" } = { } ) {
1508
+ getOperatorList ( {
1509
+ intent = "display" ,
1510
+ annotationMode = AnnotationMode . ENABLE ,
1511
+ } = { } ) {
1464
1512
function operatorListChanged ( ) {
1465
1513
if ( intentState . operatorList . lastChunk ) {
1466
1514
intentState . opListReadCapability . resolve ( intentState . operatorList ) ;
@@ -1469,9 +1517,11 @@ class PDFPageProxy {
1469
1517
}
1470
1518
}
1471
1519
1472
- const intentArgs = this . _transport . getRenderingIntent ( intent , {
1473
- isOpList : true ,
1474
- } ) ;
1520
+ const intentArgs = this . _transport . getRenderingIntent (
1521
+ intent ,
1522
+ annotationMode ,
1523
+ /* isOpList = */ true
1524
+ ) ;
1475
1525
let intentState = this . _intentStates . get ( intentArgs . cacheKey ) ;
1476
1526
if ( ! intentState ) {
1477
1527
intentState = Object . create ( null ) ;
@@ -1792,7 +1842,7 @@ class PDFPageProxy {
1792
1842
}
1793
1843
}
1794
1844
intentState . streamReader
1795
- . cancel ( new AbortException ( reason ? .message ) )
1845
+ . cancel ( new AbortException ( reason . message ) )
1796
1846
. catch ( ( ) => {
1797
1847
// Avoid "Uncaught promise" messages in the console.
1798
1848
} ) ;
@@ -2351,7 +2401,8 @@ class WorkerTransport {
2351
2401
2352
2402
getRenderingIntent (
2353
2403
intent ,
2354
- { renderForms = false , includeAnnotationStorage = false , isOpList = false }
2404
+ annotationMode = AnnotationMode . ENABLE ,
2405
+ isOpList = false
2355
2406
) {
2356
2407
let renderingIntent = RenderingIntentFlag . DISPLAY ; // Default value.
2357
2408
let lastModified = "" ;
@@ -2369,13 +2420,22 @@ class WorkerTransport {
2369
2420
warn ( `getRenderingIntent - invalid intent: ${ intent } ` ) ;
2370
2421
}
2371
2422
2372
- if ( renderForms ) {
2373
- renderingIntent += RenderingIntentFlag . ANNOTATIONS_FORMS ;
2374
- }
2375
- if ( includeAnnotationStorage ) {
2376
- renderingIntent += RenderingIntentFlag . ANNOTATIONS_STORAGE ;
2423
+ switch ( annotationMode ) {
2424
+ case AnnotationMode . DISABLE :
2425
+ renderingIntent += RenderingIntentFlag . ANNOTATIONS_DISABLE ;
2426
+ break ;
2427
+ case AnnotationMode . ENABLE :
2428
+ break ;
2429
+ case AnnotationMode . ENABLE_FORMS :
2430
+ renderingIntent += RenderingIntentFlag . ANNOTATIONS_FORMS ;
2431
+ break ;
2432
+ case AnnotationMode . ENABLE_STORAGE :
2433
+ renderingIntent += RenderingIntentFlag . ANNOTATIONS_STORAGE ;
2377
2434
2378
- lastModified = this . annotationStorage . lastModified ;
2435
+ lastModified = this . annotationStorage . lastModified ;
2436
+ break ;
2437
+ default :
2438
+ warn ( `getRenderingIntent - invalid annotationMode: ${ annotationMode } ` ) ;
2379
2439
}
2380
2440
2381
2441
if ( isOpList ) {
0 commit comments