|
@@ -2,20 +2,18 @@ import { getDocument, GlobalWorkerOptions, InvalidPDFException, MissingPDFExcept
|
|
|
import CryptoJS from 'crypto-js';
|
|
|
import printJS from 'print-js';
|
|
|
import { saveAs } from 'file-saver';
|
|
|
-import { LinkTarget, PDFLinkService } from "./pdf_link_service"
|
|
|
-import { PDFPrint, PDFPrintServiceFactory } from "./pdf_print_service"
|
|
|
+import { PDFLinkService } from "./pdf_link_service"
|
|
|
import { PasswordPrompt } from "./password_prompt.js";
|
|
|
import { PDFFindBar } from "./pdf_find_bar.js";
|
|
|
import { PDFFindController } from "./pdf_find_controller.js";
|
|
|
import { PDFViewer } from './pdf_viewer'
|
|
|
import { PDFOutlineViewer } from "./pdf_outline_viewer.js";
|
|
|
-import { PDFLayerViewer } from "./pdf_layer_viewer.js";
|
|
|
import { PDFThumbnailViewer } from './pdf_thumbnail_viewer'
|
|
|
import { PDFRenderingQueue } from "./pdf_rendering_queue";
|
|
|
import { PDFSidebar } from "./pdf_sidebar.js";
|
|
|
import { GenericExternalServices } from "./genericcom.js";
|
|
|
-import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools.js";
|
|
|
-import { EventBus, isValidRotation, isValidScrollMode, shadow, isValidSpreadMode, toDateObject, findIndex, scrollIntoView, getElementsByTagName, DEFAULT_SCALE_VALUE, SidebarView, parseAnnotationFromXml, PromiseExt } from './ui_utils'
|
|
|
+import { PDFCursorTools } from "./pdf_cursor_tools.js";
|
|
|
+import { EventBus, isValidRotation, isValidScrollMode, shadow, isValidSpreadMode, toDateObject, findIndex, scrollIntoView, DEFAULT_SCALE_VALUE, SidebarView, parseAnnotationFromXml, PromiseExt } from './ui_utils'
|
|
|
import { RenderingStates, AnnotationType, AnnotationTypeString } from "../constants";
|
|
|
import { PDFPresentationMode } from "./pdf_presentation_mode.js";
|
|
|
import annotationStore from "./annotation_store"
|
|
@@ -100,12 +98,12 @@ class ComPDFKitViewer {
|
|
|
this.pdfViewer.currentPageNumber = val;
|
|
|
}
|
|
|
|
|
|
- get scale() {
|
|
|
- return this.pdfViewer.currentScale;
|
|
|
+ get currentPageNumber() {
|
|
|
+ return this.pdfViewer.currentPageNumber
|
|
|
}
|
|
|
|
|
|
- get supportsPrinting() {
|
|
|
- return PDFPrintServiceFactory.instance.supportsPrinting;
|
|
|
+ get scale() {
|
|
|
+ return this.pdfViewer.currentScale;
|
|
|
}
|
|
|
|
|
|
initConfig(options) {
|
|
@@ -167,10 +165,8 @@ class ComPDFKitViewer {
|
|
|
thumbnailView,
|
|
|
annotationView,
|
|
|
outlineView,
|
|
|
- layerView,
|
|
|
findbarView,
|
|
|
toggleButton,
|
|
|
- annotationMode = 0
|
|
|
}) {
|
|
|
this._initializeViewerComponents({
|
|
|
container,
|
|
@@ -178,10 +174,8 @@ class ComPDFKitViewer {
|
|
|
thumbnailView,
|
|
|
annotationView,
|
|
|
outlineView,
|
|
|
- layerView,
|
|
|
findbarView,
|
|
|
toggleButton,
|
|
|
- annotationMode
|
|
|
})
|
|
|
this.initBindEvents()
|
|
|
if (thumbnailView && annotationView) {
|
|
@@ -437,6 +431,12 @@ class ComPDFKitViewer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ scrollPageIntoView({
|
|
|
+ pageNumber,
|
|
|
+ }) {
|
|
|
+ // if (this.currentPage)
|
|
|
+ }
|
|
|
+
|
|
|
async search(value) {
|
|
|
const searchResults = await this.messageHandler.sendWithPromise('Search', {
|
|
|
pagesPtr: this.pagesPtr,
|
|
@@ -782,7 +782,8 @@ class ComPDFKitViewer {
|
|
|
index,
|
|
|
doc,
|
|
|
messageHandler,
|
|
|
- parent
|
|
|
+ parent,
|
|
|
+ document: this
|
|
|
})
|
|
|
outline.children.forEach(function (outline, index) {
|
|
|
outlineItem.children.push(generateOutline(outline, index, outlineItem))
|
|
@@ -824,13 +825,6 @@ class ComPDFKitViewer {
|
|
|
}
|
|
|
this.pdfOutlineViewer?.render({ outline, pdfDocument });
|
|
|
});
|
|
|
-
|
|
|
- pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
|
|
|
- if (pdfDocument !== this.pdfDocument) {
|
|
|
- return; // The document was closed while the layers resolved.
|
|
|
- }
|
|
|
- this.pdfLayerViewer?.render({ optionalContentConfig, pdfDocument });
|
|
|
- });
|
|
|
});
|
|
|
|
|
|
this.eventBus.dispatch("documentinit", { source: this });
|
|
@@ -851,13 +845,8 @@ class ComPDFKitViewer {
|
|
|
bindEvents() {
|
|
|
const { eventBus, _boundEvents } = this;
|
|
|
|
|
|
- _boundEvents.beforePrint = this.beforePrint.bind(this);
|
|
|
- _boundEvents.afterPrint = this.afterPrint.bind(this);
|
|
|
-
|
|
|
eventBus._on("resize", this.webViewerResize.bind(this));
|
|
|
eventBus._on("pagerendered", this.webViewerPageRendered.bind(this));
|
|
|
- eventBus._on("beforeprint", _boundEvents.beforePrint);
|
|
|
- eventBus._on("afterprint", _boundEvents.afterPrint);
|
|
|
eventBus._on("updateviewarea", this.webViewerUpdateViewarea.bind(this));
|
|
|
eventBus._on("pagechanging", this.webViewerPageChanging.bind(this));
|
|
|
eventBus._on("rotationchanging", this.webViewerRotationChanging.bind(this));
|
|
@@ -874,12 +863,10 @@ class ComPDFKitViewer {
|
|
|
eventBus._on("scalechanged", this.webViewerScaleChanged.bind(this));
|
|
|
eventBus._on("rotatecw", this.webViewerRotateCw.bind(this));
|
|
|
eventBus._on("rotateccw", this.webViewerRotateCcw.bind(this));
|
|
|
- eventBus._on("optionalcontentconfig", this.webViewerOptionalContentConfig.bind(this));
|
|
|
eventBus._on("switchscrollmode", this.webViewerSwitchScrollMode.bind(this));
|
|
|
eventBus._on("scrollmodechanged", this.webViewerScrollModeChanged.bind(this));
|
|
|
eventBus._on("switchspreadmode", this.webViewerSwitchSpreadMode.bind(this));
|
|
|
eventBus._on("spreadmodechanged", this.webViewerSpreadModeChanged.bind(this));
|
|
|
- eventBus._on("documentproperties", this.webViewerDocumentProperties.bind(this));
|
|
|
eventBus._on("findfromurlhash", this.webViewerFindFromUrlHash.bind(this));
|
|
|
eventBus._on("updatefindmatchescount", this.webViewerUpdateFindMatchesCount.bind(this));
|
|
|
eventBus._on("updatefindcontrolstate", this.webViewerUpdateFindControlState.bind(this));
|
|
@@ -909,12 +896,6 @@ class ComPDFKitViewer {
|
|
|
hash: document.location.hash.substring(1),
|
|
|
});
|
|
|
};
|
|
|
- _boundEvents.windowBeforePrint = () => {
|
|
|
- eventBus.dispatch("beforeprint", { source: window });
|
|
|
- };
|
|
|
- _boundEvents.windowAfterPrint = () => {
|
|
|
- eventBus.dispatch("afterprint", { source: window });
|
|
|
- };
|
|
|
_boundEvents.windowUpdateFromSandbox = event => {
|
|
|
eventBus.dispatch("updatefromsandbox", {
|
|
|
source: window,
|
|
@@ -924,8 +905,6 @@ class ComPDFKitViewer {
|
|
|
|
|
|
window.addEventListener("resize", _boundEvents.windowResize);
|
|
|
window.addEventListener("hashchange", _boundEvents.windowHashChange);
|
|
|
- window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
|
|
- window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
|
|
|
window.addEventListener(
|
|
|
"updatefromsandbox",
|
|
|
_boundEvents.windowUpdateFromSandbox
|
|
@@ -958,14 +937,13 @@ class ComPDFKitViewer {
|
|
|
this._contentDispositionFilename = null;
|
|
|
this._contentLength = null;
|
|
|
this._saveInProgress = false;
|
|
|
- this._docStats = null;
|
|
|
this._hasAnnotationEditors = false;
|
|
|
|
|
|
this.pdfSidebar?.reset();
|
|
|
this.pdfOutlineViewer?.reset();
|
|
|
this.pdfAttachmentViewer?.reset();
|
|
|
- this.pdfLayerViewer?.reset();
|
|
|
|
|
|
+ this.outlines = []
|
|
|
this.#pwd = ''
|
|
|
this._pdfId = null
|
|
|
this.annotations = null
|
|
@@ -1264,10 +1242,8 @@ class ComPDFKitViewer {
|
|
|
thumbnailView,
|
|
|
annotationView,
|
|
|
outlineView,
|
|
|
- layerView,
|
|
|
findbarView,
|
|
|
toggleButton,
|
|
|
- annotationMode
|
|
|
}) {
|
|
|
this.viewerContainer = viewer
|
|
|
const pdfRenderingQueue = new PDFRenderingQueue();
|
|
@@ -1297,7 +1273,6 @@ class ComPDFKitViewer {
|
|
|
color: this.color
|
|
|
},
|
|
|
annotationView,
|
|
|
- annotationMode,
|
|
|
renderingQueue: pdfRenderingQueue,
|
|
|
linkService: pdfLinkService,
|
|
|
findController,
|
|
@@ -1375,14 +1350,6 @@ class ComPDFKitViewer {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if (layerView) {
|
|
|
- this.pdfLayerViewer = new PDFLayerViewer({
|
|
|
- container: layerView,
|
|
|
- eventBus: this.eventBus,
|
|
|
- $t: this.$t
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
if (toggleButton) {
|
|
|
this.pdfSidebar = new PDFSidebar({
|
|
|
elements: {
|
|
@@ -1530,7 +1497,6 @@ class ComPDFKitViewer {
|
|
|
// Work-around issue 15324 by ignoring "resize" events during printing.
|
|
|
return;
|
|
|
}
|
|
|
- pdfViewer._updateContainerHeightCss();
|
|
|
|
|
|
if (!pdfDocument) {
|
|
|
return;
|
|
@@ -1566,28 +1532,14 @@ class ComPDFKitViewer {
|
|
|
thumbnailView.setImage(pageView);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // if (error) {
|
|
|
- // this.l10n.get("rendering_error").then(msg => {
|
|
|
- // this._otherError(msg, error);
|
|
|
- // });
|
|
|
- // }
|
|
|
-
|
|
|
- // It is a good time to report stream and font types.
|
|
|
- this._reportDocumentStatsTelemetry();
|
|
|
}
|
|
|
|
|
|
get annotationMode() {
|
|
|
+ console.log(this._annotationMode)
|
|
|
return this._annotationMode
|
|
|
}
|
|
|
|
|
|
set annotationMode(mode) {
|
|
|
- if (this.annotationMode === mode) {
|
|
|
- return
|
|
|
- }
|
|
|
- if (!this.pdfDocument) {
|
|
|
- return;
|
|
|
- }
|
|
|
this._annotationMode = mode;
|
|
|
}
|
|
|
|
|
@@ -1599,18 +1551,6 @@ class ComPDFKitViewer {
|
|
|
this.pdfCursorTools.switchTool(mode);
|
|
|
}
|
|
|
|
|
|
- _reportDocumentStatsTelemetry() {
|
|
|
- const { stats } = this.pdfDocument;
|
|
|
- if (stats !== this._docStats) {
|
|
|
- this._docStats = stats;
|
|
|
-
|
|
|
- // this.externalServices.reportTelemetry({
|
|
|
- // type: "documentStats",
|
|
|
- // stats,
|
|
|
- // });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
webViewerUpdateViewarea({ location }) {
|
|
|
if (this.isInitialViewSet) {
|
|
|
// Only update the storage when the document has been loaded *and* rendered.
|
|
@@ -1788,10 +1728,6 @@ class ComPDFKitViewer {
|
|
|
this.zoomOut();
|
|
|
}
|
|
|
|
|
|
- webViewerPrint() {
|
|
|
- this.triggerPrinting();
|
|
|
- }
|
|
|
-
|
|
|
webViewerPageNumberChanged(evt) {
|
|
|
const pdfViewer = this.pdfViewer;
|
|
|
// Note that for `<input type="number">` HTML elements, an empty string will
|
|
@@ -1821,9 +1757,6 @@ class ComPDFKitViewer {
|
|
|
webViewerRotateCcw() {
|
|
|
this.rotatePages(-90);
|
|
|
}
|
|
|
- webViewerOptionalContentConfig(evt) {
|
|
|
- this.pdfViewer.optionalContentConfigPromise = evt.promise;
|
|
|
- }
|
|
|
webViewerSwitchScrollMode(mode) {
|
|
|
this.pdfViewer.scrollMode = mode;
|
|
|
}
|
|
@@ -1831,55 +1764,6 @@ class ComPDFKitViewer {
|
|
|
this.pdfViewer.spreadMode = mode;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- beforePrint() {
|
|
|
-
|
|
|
- if (this.printService) {
|
|
|
- // There is no way to suppress beforePrint/afterPrint events,
|
|
|
- // but PDFPrintService may generate double events -- this will ignore
|
|
|
- // the second event that will be coming from native window.print().
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // The beforePrint is a sync method and we need to know layout before
|
|
|
- // returning from this method. Ensure that we can get sizes of the pages.
|
|
|
- if (!this.pdfViewer.pageViewsReady) {
|
|
|
- // eslint-disable-next-line no-alert
|
|
|
- window.alert('Warning: The PDF is not fully loaded for printing.');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const pagesOverview = this.pdfViewer.getPagesOverview();
|
|
|
- const printContainer = document.getElementById("printContainer");
|
|
|
- const printResolution = 150;
|
|
|
- const optionalContentConfigPromise =
|
|
|
- this.pdfViewer.optionalContentConfigPromise;
|
|
|
- const printService = PDFPrintServiceFactory.instance.createPrintService(
|
|
|
- this.pdfDocument,
|
|
|
- pagesOverview,
|
|
|
- printContainer,
|
|
|
- printResolution,
|
|
|
- optionalContentConfigPromise
|
|
|
- );
|
|
|
- this.printService = printService;
|
|
|
- this.forceRendering();
|
|
|
- this.setTitle(this._docName);
|
|
|
-
|
|
|
- printService.layout();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- afterPrint() {
|
|
|
- if (this.printService) {
|
|
|
- this.printService.destroy();
|
|
|
- this.printService = null;
|
|
|
-
|
|
|
- this.pdfDocument?.annotationStorage.resetModified();
|
|
|
- }
|
|
|
- this.forceRendering();
|
|
|
- this.setTitle(this._title);
|
|
|
- }
|
|
|
-
|
|
|
rotatePages(delta) {
|
|
|
this.pdfViewer.pagesRotation += delta;
|
|
|
// Note that the thumbnail viewer is updated, and rendering is triggered,
|
|
@@ -1897,9 +1781,6 @@ class ComPDFKitViewer {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- webViewerDocumentProperties() {
|
|
|
- this.pdfDocumentProperties.open();
|
|
|
- }
|
|
|
|
|
|
webViewerFindFromUrlHash(evt) {
|
|
|
this.eventBus.dispatch("find", {
|
|
@@ -2227,32 +2108,6 @@ class ComPDFKitViewer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function webViewerTouchStart(evt) {
|
|
|
- if (
|
|
|
- PDFViewerApplication.pdfViewer.isInPresentationMode ||
|
|
|
- evt.touches.length < 2
|
|
|
- ) {
|
|
|
- return;
|
|
|
- }
|
|
|
- evt.preventDefault();
|
|
|
-
|
|
|
- if (evt.touches.length !== 2) {
|
|
|
- PDFViewerApplication._touchInfo = null;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- let [touch0, touch1] = evt.touches;
|
|
|
- if (touch0.identifier > touch1.identifier) {
|
|
|
- [touch0, touch1] = [touch1, touch0];
|
|
|
- }
|
|
|
- PDFViewerApplication._touchInfo = {
|
|
|
- touch0X: touch0.pageX,
|
|
|
- touch0Y: touch0.pageY,
|
|
|
- touch1X: touch1.pageX,
|
|
|
- touch1Y: touch1.pageY,
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
class PDFWorker {
|
|
|
destroyed = false
|
|
|
constructor() {
|