|
@@ -49,6 +49,7 @@ class ComPDFKitViewer {
|
|
this.scaleChangedCallback = null
|
|
this.scaleChangedCallback = null
|
|
this.annotationsNumChangedCallback = null
|
|
this.annotationsNumChangedCallback = null
|
|
this.distanceChangedCallback = null
|
|
this.distanceChangedCallback = null
|
|
|
|
+ this._pagesCount = 0
|
|
this._license = ''
|
|
this._license = ''
|
|
this._token = null
|
|
this._token = null
|
|
this._pdfId = null
|
|
this._pdfId = null
|
|
@@ -301,6 +302,7 @@ class ComPDFKitViewer {
|
|
tool,
|
|
tool,
|
|
color
|
|
color
|
|
}) {
|
|
}) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.activeTool = tool
|
|
this.activeTool = tool
|
|
this.color = color
|
|
this.color = color
|
|
this.eventBus.dispatch("toolChanged", { tool, color });
|
|
this.eventBus.dispatch("toolChanged", { tool, color });
|
|
@@ -495,7 +497,7 @@ class ComPDFKitViewer {
|
|
// }
|
|
// }
|
|
|
|
|
|
// 处理传入的PDF
|
|
// 处理传入的PDF
|
|
- return await loadingTask.promise.then(
|
|
|
|
|
|
+ return loadingTask.promise.then(
|
|
async pdfDocument => {
|
|
async pdfDocument => {
|
|
// 上传pdf
|
|
// 上传pdf
|
|
await pdfDocument.getData().then(async (binaryData) => {
|
|
await pdfDocument.getData().then(async (binaryData) => {
|
|
@@ -649,6 +651,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
getSelectedText(pageNumber) {
|
|
getSelectedText(pageNumber) {
|
|
|
|
+ if (!this.pdfDocument) return ''
|
|
if (pageNumber) {
|
|
if (pageNumber) {
|
|
const page = this.pdfViewer._pages[pageNumber - 1]
|
|
const page = this.pdfViewer._pages[pageNumber - 1]
|
|
if (page) {
|
|
if (page) {
|
|
@@ -953,6 +956,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
getOutlines() {
|
|
getOutlines() {
|
|
|
|
+ if (!this.pdfDocument) return []
|
|
if (this.outlines) {
|
|
if (this.outlines) {
|
|
return this.outlines
|
|
return this.outlines
|
|
}
|
|
}
|
|
@@ -965,6 +969,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
async search(value) {
|
|
async search(value) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
const result = await this.messageHandler.sendWithPromise('Search', {
|
|
const result = await this.messageHandler.sendWithPromise('Search', {
|
|
pagesPtr: this.pagesPtr,
|
|
pagesPtr: this.pagesPtr,
|
|
value
|
|
value
|
|
@@ -990,6 +995,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
setActiveSearchResult(result = null, activeSearchIndex = 0) {
|
|
setActiveSearchResult(result = null, activeSearchIndex = 0) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (!this.searchResults) return
|
|
if (!this.searchResults) return
|
|
const activeResult = result ? result : this.searchResults[0]
|
|
const activeResult = result ? result : this.searchResults[0]
|
|
const quad = activeResult.quads[0]
|
|
const quad = activeResult.quads[0]
|
|
@@ -1014,7 +1020,6 @@ class ComPDFKitViewer {
|
|
pageView.setActiveSearchResult(activeResult)
|
|
pageView.setActiveSearchResult(activeResult)
|
|
this.#activeSearchIndex = 0
|
|
this.#activeSearchIndex = 0
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
clearSearchResults() {
|
|
clearSearchResults() {
|
|
@@ -1153,12 +1158,14 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
removeAllAnnotations() {
|
|
removeAllAnnotations() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (this.pdfViewer.annotationStorage) {
|
|
if (this.pdfViewer.annotationStorage) {
|
|
this.pdfViewer.annotationStorage.cleanup()
|
|
this.pdfViewer.annotationStorage.cleanup()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
async importAnnotations(data) {
|
|
async importAnnotations(data) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
const source = await new Promise((resolve) => {
|
|
const source = await new Promise((resolve) => {
|
|
const reader = new FileReader();
|
|
const reader = new FileReader();
|
|
reader.onload = (event) => {
|
|
reader.onload = (event) => {
|
|
@@ -1264,6 +1271,7 @@ class ComPDFKitViewer {
|
|
return false
|
|
return false
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
// 设置密码标志
|
|
// 设置密码标志
|
|
this.saveAction = 'set'
|
|
this.saveAction = 'set'
|
|
this.#pwd = value
|
|
this.#pwd = value
|
|
@@ -1304,6 +1312,7 @@ class ComPDFKitViewer {
|
|
return false
|
|
return false
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (this.#pwd) {
|
|
if (this.#pwd) {
|
|
// 移除密码标志
|
|
// 移除密码标志
|
|
this.saveAction = 'remove'
|
|
this.saveAction = 'remove'
|
|
@@ -1337,6 +1346,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
toggleSidebar() {
|
|
toggleSidebar() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.pdfSidebar.toggle()
|
|
this.pdfSidebar.toggle()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1512,10 +1522,15 @@ class ComPDFKitViewer {
|
|
this.pdfOutlineViewer?.reset();
|
|
this.pdfOutlineViewer?.reset();
|
|
this.pdfAttachmentViewer?.reset();
|
|
this.pdfAttachmentViewer?.reset();
|
|
|
|
|
|
|
|
+ this.pagesPtr.length = 0
|
|
this.outlines = []
|
|
this.outlines = []
|
|
|
|
+ this.annotationHistory.length = 0
|
|
this.#pwd = ''
|
|
this.#pwd = ''
|
|
this._pdfId = null
|
|
this._pdfId = null
|
|
this.annotations = null
|
|
this.annotations = null
|
|
|
|
+ this._docName = ''
|
|
|
|
+ this._pagesCount = 0
|
|
|
|
+ annotationStore.annotationsAll = null
|
|
|
|
|
|
await Promise.all(promises);
|
|
await Promise.all(promises);
|
|
}
|
|
}
|
|
@@ -1928,6 +1943,7 @@ class ComPDFKitViewer {
|
|
return false
|
|
return false
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
let saveType = 2
|
|
let saveType = 2
|
|
if (!this.saveAction || this.saveAction === 'set') {
|
|
if (!this.saveAction || this.saveAction === 'set') {
|
|
saveType = 2
|
|
saveType = 2
|
|
@@ -1954,6 +1970,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
async flattenPdfDownload() {
|
|
async flattenPdfDownload() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
const blobData = await this.flattenPdf()
|
|
const blobData = await this.flattenPdf()
|
|
if (blobData) {
|
|
if (blobData) {
|
|
saveAs(blobData, this._docName)
|
|
saveAs(blobData, this._docName)
|
|
@@ -2046,6 +2063,7 @@ class ComPDFKitViewer {
|
|
return false
|
|
return false
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
const result = await this.messageHandler.sendWithPromise('XFDFExportAnnotations', {
|
|
const result = await this.messageHandler.sendWithPromise('XFDFExportAnnotations', {
|
|
doc: this.doc
|
|
doc: this.doc
|
|
})
|
|
})
|
|
@@ -2074,6 +2092,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
getSelectedPage(firstCoordinates, lastCoordinates) {
|
|
getSelectedPage(firstCoordinates, lastCoordinates) {
|
|
|
|
+ if (!this.pdfDocument) return null
|
|
let firstPageIndex = null, lastPageIndex = null
|
|
let firstPageIndex = null, lastPageIndex = null
|
|
for (let i = 0; i < this.pagesCount; i++) {
|
|
for (let i = 0; i < this.pagesCount; i++) {
|
|
const el = this.pdfViewer._pages[i].div
|
|
const el = this.pdfViewer._pages[i].div
|
|
@@ -2102,6 +2121,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
pageToWindow(coordinates, pageNumber) {
|
|
pageToWindow(coordinates, pageNumber) {
|
|
|
|
+ if (!this.pdfDocument) return null
|
|
if (pageNumber > this.page && pageNumber < 1) return null
|
|
if (pageNumber > this.page && pageNumber < 1) return null
|
|
const el = this.pdfViewer._pages[pageNumber - 1].div
|
|
const el = this.pdfViewer._pages[pageNumber - 1].div
|
|
const left = el.offsetLeft
|
|
const left = el.offsetLeft
|
|
@@ -2115,6 +2135,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
windowToPage(coordinates, pageNumber) {
|
|
windowToPage(coordinates, pageNumber) {
|
|
|
|
+ if (!this.pdfDocument) return null
|
|
if (pageNumber > this.page && pageNumber < 1) return null
|
|
if (pageNumber > this.page && pageNumber < 1) return null
|
|
const el = this.pdfViewer._pages[pageNumber - 1].div
|
|
const el = this.pdfViewer._pages[pageNumber - 1].div
|
|
const left = el.offsetLeft
|
|
const left = el.offsetLeft
|
|
@@ -2252,6 +2273,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
requestFullScreenMode() {
|
|
requestFullScreenMode() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.pdfPresentationMode?.request();
|
|
this.pdfPresentationMode?.request();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2274,7 +2296,8 @@ class ComPDFKitViewer {
|
|
this._cleanup()
|
|
this._cleanup()
|
|
}
|
|
}
|
|
|
|
|
|
- zoomIn(steps) {
|
|
|
|
|
|
+ zoomIn() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -2283,7 +2306,8 @@ class ComPDFKitViewer {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- zoomOut(steps) {
|
|
|
|
|
|
+ zoomOut() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -2293,14 +2317,17 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
nextPage() {
|
|
nextPage() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
return this.pdfViewer.nextPage()
|
|
return this.pdfViewer.nextPage()
|
|
}
|
|
}
|
|
|
|
|
|
previousPage() {
|
|
previousPage() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
return this.pdfViewer.previousPage()
|
|
return this.pdfViewer.previousPage()
|
|
}
|
|
}
|
|
|
|
|
|
pageNumberChanged(value) {
|
|
pageNumberChanged(value) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
// Note that for `<input type="number">` HTML elements, an empty string will
|
|
// Note that for `<input type="number">` HTML elements, an empty string will
|
|
// be returned for non-number inputs; hence we simply do nothing in that case.
|
|
// be returned for non-number inputs; hence we simply do nothing in that case.
|
|
if (value !== "") {
|
|
if (value !== "") {
|
|
@@ -2394,10 +2421,12 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
webViewerSwitchAnnotationEditorMode(evt) {
|
|
webViewerSwitchAnnotationEditorMode(evt) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.pdfViewer.annotationEditorMode = evt.mode;
|
|
this.pdfViewer.annotationEditorMode = evt.mode;
|
|
}
|
|
}
|
|
|
|
|
|
switchTool(mode) {
|
|
switchTool(mode) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.pdfCursorTools.switchTool(mode);
|
|
this.pdfCursorTools.switchTool(mode);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2470,6 +2499,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
webViewerPageMode({ mode }) {
|
|
webViewerPageMode({ mode }) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
// Handle the 'pagemode' hash parameter, see also `PDFLinkService_setHash`.
|
|
// Handle the 'pagemode' hash parameter, see also `PDFLinkService_setHash`.
|
|
let view;
|
|
let view;
|
|
switch (mode) {
|
|
switch (mode) {
|
|
@@ -2497,6 +2527,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
async webViewerNamedAction(evt) {
|
|
async webViewerNamedAction(evt) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
// Processing a couple of named actions that might be useful, see also
|
|
// Processing a couple of named actions that might be useful, see also
|
|
// `PDFLinkService.executeNamedAction`.
|
|
// `PDFLinkService.executeNamedAction`.
|
|
switch (evt.action) {
|
|
switch (evt.action) {
|
|
@@ -2516,6 +2547,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
triggerPrinting(data) {
|
|
triggerPrinting(data) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
let url = data instanceof Blob ? URL.createObjectURL(data) : data
|
|
let url = data instanceof Blob ? URL.createObjectURL(data) : data
|
|
url = decodeURIComponent(url)
|
|
url = decodeURIComponent(url)
|
|
printJS({
|
|
printJS({
|
|
@@ -2569,18 +2601,23 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
webViewerScaleChanged(value) {
|
|
webViewerScaleChanged(value) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.pdfViewer.currentScaleValue = value;
|
|
this.pdfViewer.currentScaleValue = value;
|
|
}
|
|
}
|
|
webViewerRotateCw() {
|
|
webViewerRotateCw() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.rotatePages(90);
|
|
this.rotatePages(90);
|
|
}
|
|
}
|
|
webViewerRotateCcw() {
|
|
webViewerRotateCcw() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.rotatePages(-90);
|
|
this.rotatePages(-90);
|
|
}
|
|
}
|
|
webViewerSwitchScrollMode(mode) {
|
|
webViewerSwitchScrollMode(mode) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.pdfViewer.scrollMode = mode;
|
|
this.pdfViewer.scrollMode = mode;
|
|
}
|
|
}
|
|
webViewerSwitchSpreadMode(mode) {
|
|
webViewerSwitchSpreadMode(mode) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.pdfViewer.spreadMode = mode;
|
|
this.pdfViewer.spreadMode = mode;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2662,6 +2699,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
async setToolMode(mode) {
|
|
async setToolMode(mode) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
const oldMode = this.toolMode;
|
|
const oldMode = this.toolMode;
|
|
this.toolMode = mode;
|
|
this.toolMode = mode;
|
|
if (mode === 'editor' && !this.fontFileInited) {
|
|
if (mode === 'editor' && !this.fontFileInited) {
|
|
@@ -2728,14 +2766,17 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
setPropertyPanel(props) {
|
|
setPropertyPanel(props) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.eventBus.dispatch("propertyPanelChanged", props);
|
|
this.eventBus.dispatch("propertyPanelChanged", props);
|
|
}
|
|
}
|
|
|
|
|
|
setFreetextProperty(data) {
|
|
setFreetextProperty(data) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
this.eventBus.dispatch('setFreetextProperty', data)
|
|
this.eventBus.dispatch('setFreetextProperty', data)
|
|
}
|
|
}
|
|
|
|
|
|
setContentEditorProperty(type, props) {
|
|
setContentEditorProperty(type, props) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (type === 'text') {
|
|
if (type === 'text') {
|
|
this.eventBus.dispatch("textPropertyChanged", props);
|
|
this.eventBus.dispatch("textPropertyChanged", props);
|
|
} else if (type === 'image') {
|
|
} else if (type === 'image') {
|
|
@@ -2744,6 +2785,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
setInitProperty() {
|
|
setInitProperty() {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (this.activeTool === 'textfield') {
|
|
if (this.activeTool === 'textfield') {
|
|
this.eventBus.dispatch("initTextfieldName");
|
|
this.eventBus.dispatch("initTextfieldName");
|
|
} else if (this.activeTool === 'checkbox') {
|
|
} else if (this.activeTool === 'checkbox') {
|
|
@@ -2756,6 +2798,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
handleField(prop) {
|
|
handleField(prop) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
const id = prop.id
|
|
const id = prop.id
|
|
const key = prop.key
|
|
const key = prop.key
|
|
const value = prop.value
|
|
const value = prop.value
|
|
@@ -2777,6 +2820,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
handleSign(flag, param) {
|
|
handleSign(flag, param) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (flag === 'create' && !this.InkSign) {
|
|
if (flag === 'create' && !this.InkSign) {
|
|
this.InkSign = new InkSign({
|
|
this.InkSign = new InkSign({
|
|
pdfViewer: this.pdfViewer,
|
|
pdfViewer: this.pdfViewer,
|
|
@@ -2800,6 +2844,7 @@ class ComPDFKitViewer {
|
|
}
|
|
}
|
|
|
|
|
|
handleStamp(data) {
|
|
handleStamp(data) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (!data) return
|
|
if (!data) return
|
|
let imgUi = data.stampContainer
|
|
let imgUi = data.stampContainer
|
|
let pageNum = data.page
|
|
let pageNum = data.page
|
|
@@ -3022,6 +3067,7 @@ class ComPDFKitViewer {
|
|
// 页面编辑 - 获取每个页面图片
|
|
// 页面编辑 - 获取每个页面图片
|
|
// 获取范围内的页面图片 index起始索引 num页面数量
|
|
// 获取范围内的页面图片 index起始索引 num页面数量
|
|
async getDocEditorPages(pageSize, index = 0, num = null) {
|
|
async getDocEditorPages(pageSize, index = 0, num = null) {
|
|
|
|
+ if (!this.pdfDocument) return
|
|
if (!this.docEditorCopy) {
|
|
if (!this.docEditorCopy) {
|
|
const doc = await this.messageHandler.sendWithPromise('createEditorDoc', {
|
|
const doc = await this.messageHandler.sendWithPromise('createEditorDoc', {
|
|
doc: this.doc,
|
|
doc: this.doc,
|
|
@@ -3392,6 +3438,7 @@ class ComPDFKitViewer {
|
|
// 页面编辑 - 保存
|
|
// 页面编辑 - 保存
|
|
async saveDocumentEdit(op) {
|
|
async saveDocumentEdit(op) {
|
|
const doc = this.docEditorCopy.doc
|
|
const doc = this.docEditorCopy.doc
|
|
|
|
+ if (!doc) return
|
|
const clearDocument = async () => {
|
|
const clearDocument = async () => {
|
|
await this.messageHandler.sendWithPromise('ClearDocument', doc)
|
|
await this.messageHandler.sendWithPromise('ClearDocument', doc)
|
|
this.docEditorCopy = null
|
|
this.docEditorCopy = null
|
|
@@ -3417,7 +3464,6 @@ class ComPDFKitViewer {
|
|
|
|
|
|
const newUrl = URL.createObjectURL(blobData)
|
|
const newUrl = URL.createObjectURL(blobData)
|
|
if (this.saveAction === 'set' && this.#oldPwd !== this.#pwd) this.#oldPwd = this.#pwd
|
|
if (this.saveAction === 'set' && this.#oldPwd !== this.#pwd) this.#oldPwd = this.#pwd
|
|
- await this.loadDocument(newUrl, { filename, notUpdatePwd: true })
|
|
|
|
await clearDocument()
|
|
await clearDocument()
|
|
return newUrl
|
|
return newUrl
|
|
}
|
|
}
|