Merge pull request #13942 from Snuffleupagus/viewer-components-export-layers
Export the XFA/StructTree-layers in the viewer components
This commit is contained in:
commit
a270baeb67
@ -54,11 +54,13 @@ loadingTask.promise.then(function (pdfDocument) {
|
|||||||
scale: SCALE,
|
scale: SCALE,
|
||||||
defaultViewport: pdfPage.getViewport({ scale: SCALE }),
|
defaultViewport: pdfPage.getViewport({ scale: SCALE }),
|
||||||
eventBus,
|
eventBus,
|
||||||
// We can enable text/annotations layers, if needed
|
// We can enable text/annotation/xfa/struct-layers, as needed.
|
||||||
textLayerFactory: new pdfjsViewer.DefaultTextLayerFactory(),
|
textLayerFactory: new pdfjsViewer.DefaultTextLayerFactory(),
|
||||||
annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
|
annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
|
||||||
|
xfaLayerFactory: new pdfjsViewer.DefaultXfaLayerFactory(),
|
||||||
|
structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(),
|
||||||
});
|
});
|
||||||
// Associates the actual page with the view, and drawing it
|
// Associate the actual page with the view, and draw it.
|
||||||
pdfPageView.setPdfPage(pdfPage);
|
pdfPageView.setPdfPage(pdfPage);
|
||||||
return pdfPageView.draw();
|
return pdfPageView.draw();
|
||||||
});
|
});
|
||||||
|
@ -80,10 +80,7 @@ class AnnotationLayerBuilder {
|
|||||||
this.pdfPage.getAnnotations({ intent }),
|
this.pdfPage.getAnnotations({ intent }),
|
||||||
this._hasJSActionsPromise,
|
this._hasJSActionsPromise,
|
||||||
]).then(([annotations, hasJSActions = false]) => {
|
]).then(([annotations, hasJSActions = false]) => {
|
||||||
if (this._cancelled) {
|
if (this._cancelled || annotations.length === 0) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (annotations.length === 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ import { RenderingStates } from "./pdf_rendering_queue.js";
|
|||||||
* @property {IPDFAnnotationLayerFactory} annotationLayerFactory
|
* @property {IPDFAnnotationLayerFactory} annotationLayerFactory
|
||||||
* @property {IPDFXfaLayerFactory} xfaLayerFactory
|
* @property {IPDFXfaLayerFactory} xfaLayerFactory
|
||||||
* @property {IPDFStructTreeLayerFactory} structTreeLayerFactory
|
* @property {IPDFStructTreeLayerFactory} structTreeLayerFactory
|
||||||
|
* @property {Object} [textHighlighterFactory]
|
||||||
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
||||||
* for annotation icons. Include trailing slash.
|
* for annotation icons. Include trailing slash.
|
||||||
* @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'.
|
* @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'.
|
||||||
|
@ -17,10 +17,18 @@ import {
|
|||||||
AnnotationLayerBuilder,
|
AnnotationLayerBuilder,
|
||||||
DefaultAnnotationLayerFactory,
|
DefaultAnnotationLayerFactory,
|
||||||
} from "./annotation_layer_builder.js";
|
} from "./annotation_layer_builder.js";
|
||||||
|
import {
|
||||||
|
DefaultStructTreeLayerFactory,
|
||||||
|
StructTreeLayerBuilder,
|
||||||
|
} from "./struct_tree_layer_builder.js";
|
||||||
import {
|
import {
|
||||||
DefaultTextLayerFactory,
|
DefaultTextLayerFactory,
|
||||||
TextLayerBuilder,
|
TextLayerBuilder,
|
||||||
} from "./text_layer_builder.js";
|
} from "./text_layer_builder.js";
|
||||||
|
import {
|
||||||
|
DefaultXfaLayerFactory,
|
||||||
|
XfaLayerBuilder,
|
||||||
|
} from "./xfa_layer_builder.js";
|
||||||
import { EventBus, ProgressBar } from "./ui_utils.js";
|
import { EventBus, ProgressBar } from "./ui_utils.js";
|
||||||
import { PDFLinkService, SimpleLinkService } from "./pdf_link_service.js";
|
import { PDFLinkService, SimpleLinkService } from "./pdf_link_service.js";
|
||||||
import { DownloadManager } from "./download_manager.js";
|
import { DownloadManager } from "./download_manager.js";
|
||||||
@ -41,7 +49,9 @@ const pdfjsBuild = PDFJSDev.eval("BUNDLE_BUILD");
|
|||||||
export {
|
export {
|
||||||
AnnotationLayerBuilder,
|
AnnotationLayerBuilder,
|
||||||
DefaultAnnotationLayerFactory,
|
DefaultAnnotationLayerFactory,
|
||||||
|
DefaultStructTreeLayerFactory,
|
||||||
DefaultTextLayerFactory,
|
DefaultTextLayerFactory,
|
||||||
|
DefaultXfaLayerFactory,
|
||||||
DownloadManager,
|
DownloadManager,
|
||||||
EventBus,
|
EventBus,
|
||||||
GenericL10n,
|
GenericL10n,
|
||||||
@ -55,5 +65,7 @@ export {
|
|||||||
PDFViewer,
|
PDFViewer,
|
||||||
ProgressBar,
|
ProgressBar,
|
||||||
SimpleLinkService,
|
SimpleLinkService,
|
||||||
|
StructTreeLayerBuilder,
|
||||||
TextLayerBuilder,
|
TextLayerBuilder,
|
||||||
|
XfaLayerBuilder,
|
||||||
};
|
};
|
||||||
|
@ -93,10 +93,9 @@ class TextLayerBuilder {
|
|||||||
}
|
}
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
|
||||||
this.textDivs = [];
|
this.textDivs.length = 0;
|
||||||
if (this.highlighter) {
|
this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
|
||||||
this.highlighter.setTextMapping(this.textDivs, this.textContentItemsStr);
|
|
||||||
}
|
|
||||||
const textLayerFrag = document.createDocumentFragment();
|
const textLayerFrag = document.createDocumentFragment();
|
||||||
this.textLayerRenderTask = renderTextLayer({
|
this.textLayerRenderTask = renderTextLayer({
|
||||||
textContent: this.textContent,
|
textContent: this.textContent,
|
||||||
|
@ -21,19 +21,19 @@ import { XfaLayer } from "pdfjs-lib";
|
|||||||
* @typedef {Object} XfaLayerBuilderOptions
|
* @typedef {Object} XfaLayerBuilderOptions
|
||||||
* @property {HTMLDivElement} pageDiv
|
* @property {HTMLDivElement} pageDiv
|
||||||
* @property {PDFPage} pdfPage
|
* @property {PDFPage} pdfPage
|
||||||
* @property {Object} [xfaHtml]
|
|
||||||
* @property {AnnotationStorage} [annotationStorage]
|
* @property {AnnotationStorage} [annotationStorage]
|
||||||
|
* @property {Object} [xfaHtml]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class XfaLayerBuilder {
|
class XfaLayerBuilder {
|
||||||
/**
|
/**
|
||||||
* @param {XfaLayerBuilderOptions} options
|
* @param {XfaLayerBuilderOptions} options
|
||||||
*/
|
*/
|
||||||
constructor({ pageDiv, pdfPage, xfaHtml, annotationStorage }) {
|
constructor({ pageDiv, pdfPage, annotationStorage, xfaHtml }) {
|
||||||
this.pageDiv = pageDiv;
|
this.pageDiv = pageDiv;
|
||||||
this.pdfPage = pdfPage;
|
this.pdfPage = pdfPage;
|
||||||
this.xfaHtml = xfaHtml;
|
|
||||||
this.annotationStorage = annotationStorage;
|
this.annotationStorage = annotationStorage;
|
||||||
|
this.xfaHtml = xfaHtml;
|
||||||
|
|
||||||
this.div = null;
|
this.div = null;
|
||||||
this._cancelled = false;
|
this._cancelled = false;
|
||||||
@ -62,17 +62,18 @@ class XfaLayerBuilder {
|
|||||||
this.pageDiv.appendChild(div);
|
this.pageDiv.appendChild(div);
|
||||||
parameters.div = div;
|
parameters.div = div;
|
||||||
|
|
||||||
XfaLayer.render(parameters);
|
const result = XfaLayer.render(parameters);
|
||||||
return Promise.resolve();
|
return Promise.resolve(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// intent === "display"
|
// intent === "display"
|
||||||
return this.pdfPage
|
return this.pdfPage
|
||||||
.getXfa()
|
.getXfa()
|
||||||
.then(xfa => {
|
.then(xfa => {
|
||||||
if (this._cancelled) {
|
if (this._cancelled || !xfa) {
|
||||||
return Promise.resolve();
|
return { textDivs: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const parameters = {
|
const parameters = {
|
||||||
viewport: viewport.clone({ dontFlip: true }),
|
viewport: viewport.clone({ dontFlip: true }),
|
||||||
div: this.div,
|
div: this.div,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user