Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the XfaLayerBuilder.render method to be asynchronous #15805

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 24 additions & 30 deletions web/xfa_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class XfaLayerBuilder {
* @param {string} intent (default value is 'display')
* @returns {Promise<Object | void>} A promise that is resolved when rendering
* of the XFA layer is complete. The first rendering will return an object
* with a `textDivs` property that can be used with the TextHighlighter.
* with a `textDivs` property that can be used with the TextHighlighter.
*/
render(viewport, intent = "display") {
async render(viewport, intent = "display") {
if (intent === "print") {
const parameters = {
viewport: viewport.clone({ dontFlip: true }),
Expand All @@ -73,39 +73,33 @@ class XfaLayerBuilder {
this.pageDiv.append(div);
parameters.div = div;

const result = XfaLayer.render(parameters);
return Promise.resolve(result);
return XfaLayer.render(parameters);
}

// intent === "display"
return this.pdfPage
.getXfa()
.then(xfaHtml => {
if (this._cancelled || !xfaHtml) {
return { textDivs: [] };
}
const xfaHtml = await this.pdfPage.getXfa();
if (this._cancelled || !xfaHtml) {
return { textDivs: [] };
}

const parameters = {
viewport: viewport.clone({ dontFlip: true }),
div: this.div,
xfaHtml,
annotationStorage: this.annotationStorage,
linkService: this.linkService,
intent,
};

const parameters = {
viewport: viewport.clone({ dontFlip: true }),
div: this.div,
xfaHtml,
annotationStorage: this.annotationStorage,
linkService: this.linkService,
intent,
};
if (this.div) {
return XfaLayer.update(parameters);
}
// Create an xfa layer div and render the form
this.div = document.createElement("div");
this.pageDiv.append(this.div);
parameters.div = this.div;

if (this.div) {
return XfaLayer.update(parameters);
}
// Create an xfa layer div and render the form
this.div = document.createElement("div");
this.pageDiv.append(this.div);
parameters.div = this.div;
return XfaLayer.render(parameters);
})
.catch(error => {
console.error(error);
});
return XfaLayer.render(parameters);
}

cancel() {
Expand Down