Skip to content

Commit dbea302

Browse files
committed
Text widget annotations: do not render on canvas as well
If interactive forms are enabled, then the display layer takes care of rendering the form elements. There is no need to draw them on the canvas as well. This also leads to issues when values are prefilled, because the text fields are transparent, so the contents that have been rendered onto the canvas will be visible too. We address this issue by passing the `renderInteractiveForms` parameter to the render task and handling it when the page is rendered (i.e., when the canvas is rendered).
1 parent adf0972 commit dbea302

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

src/core/annotation.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
6868
* @param {Object} ref
6969
* @param {string} uniquePrefix
7070
* @param {Object} idCounters
71+
* @param {boolean} renderInteractiveForms
7172
* @returns {Annotation}
7273
*/
7374
create: function AnnotationFactory_create(xref, ref,
74-
uniquePrefix, idCounters) {
75+
uniquePrefix, idCounters,
76+
renderInteractiveForms) {
7577
var dict = xref.fetchIfRef(ref);
7678
if (!isDict(dict)) {
7779
return;
@@ -90,6 +92,7 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
9092
ref: isRef(ref) ? ref : null,
9193
subtype: subtype,
9294
id: id,
95+
renderInteractiveForms: renderInteractiveForms,
9396
};
9497

9598
switch (subtype) {
@@ -693,6 +696,8 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
693696
function TextWidgetAnnotation(params) {
694697
WidgetAnnotation.call(this, params);
695698

699+
this.renderInteractiveForms = params.renderInteractiveForms;
700+
696701
// Determine the alignment of text in the field.
697702
var alignment = Util.getInheritableProperty(params.dict, 'Q');
698703
if (!isInt(alignment) || alignment < 0 || alignment > 2) {
@@ -715,12 +720,18 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
715720
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
716721
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
717722
task) {
723+
var operatorList = new OperatorList();
724+
725+
// Do not render form elements on the canvas when interactive forms are
726+
// enabled. The display layer is responsible for rendering them instead.
727+
if (this.renderInteractiveForms) {
728+
return Promise.resolve(operatorList);
729+
}
730+
718731
if (this.appearance) {
719732
return Annotation.prototype.getOperatorList.call(this, evaluator, task);
720733
}
721734

722-
var operatorList = new OperatorList();
723-
724735
// Even if there is an appearance stream, ignore it. This is the
725736
// behaviour used by Adobe Reader.
726737
if (!this.data.defaultAppearance) {

src/core/document.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ var Page = (function PageClosure() {
205205
}.bind(this));
206206
},
207207

208-
getOperatorList: function Page_getOperatorList(handler, task, intent) {
208+
getOperatorList: function Page_getOperatorList(handler, task, intent,
209+
renderInteractiveForms) {
209210
var self = this;
210211

211212
var pdfManager = this.pdfManager;
@@ -245,6 +246,8 @@ var Page = (function PageClosure() {
245246
});
246247
});
247248

249+
this.renderInteractiveForms = renderInteractiveForms;
250+
248251
var annotationsPromise = pdfManager.ensure(this, 'annotations');
249252
return Promise.all([pageListPromise, annotationsPromise]).then(
250253
function(datas) {
@@ -328,7 +331,8 @@ var Page = (function PageClosure() {
328331
var annotationRef = annotationRefs[i];
329332
var annotation = annotationFactory.create(this.xref, annotationRef,
330333
this.uniquePrefix,
331-
this.idCounters);
334+
this.idCounters,
335+
this.renderInteractiveForms);
332336
if (annotation) {
333337
annotations.push(annotation);
334338
}

src/core/worker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,8 @@ var WorkerMessageHandler = {
839839
var pageNum = pageIndex + 1;
840840
var start = Date.now();
841841
// Pre compile the pdf page and fetch the fonts/images.
842-
page.getOperatorList(handler, task, data.intent).then(
842+
page.getOperatorList(handler, task, data.intent,
843+
data.renderInteractiveForms).then(
843844
function(operatorList) {
844845
finishWorkerTask(task);
845846

src/display/api.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
656656
* calling of PDFPage.getViewport method.
657657
* @property {string} intent - Rendering intent, can be 'display' or 'print'
658658
* (default value is 'display').
659+
* @property {boolean} renderInteractiveForms - (optional) Whether or not
660+
* interactive form elements are rendered in the display
661+
* layer. If so, we do not render them on canvas as well.
659662
* @property {Array} transform - (optional) Additional transform, applied
660663
* just before viewport transform.
661664
* @property {Object} imageLayer - (optional) An object that has beginLayout,
@@ -764,6 +767,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
764767
this.pendingCleanup = false;
765768

766769
var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
770+
var renderInteractiveForms = (params.renderInteractiveForms === true ?
771+
true : /* Default */ false);
767772

768773
if (!this.intentStates[renderingIntent]) {
769774
this.intentStates[renderingIntent] = Object.create(null);
@@ -784,7 +789,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
784789
this.stats.time('Page Request');
785790
this.transport.messageHandler.send('RenderPageRequest', {
786791
pageIndex: this.pageNumber - 1,
787-
intent: renderingIntent
792+
intent: renderingIntent,
793+
renderInteractiveForms: renderInteractiveForms,
788794
});
789795
}
790796

web/pdf_page_view.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ var PDFPageView = (function PDFPageViewClosure() {
498498
canvasContext: ctx,
499499
transform: transform,
500500
viewport: this.viewport,
501+
renderInteractiveForms: pdfjsLib.PDFJS.renderInteractiveForms,
501502
// intent: 'default', // === 'display'
502503
};
503504
var renderTask = this.renderTask = this.pdfPage.render(renderContext);

0 commit comments

Comments
 (0)