|
|
@ -24,17 +24,14 @@ import { parseQueryString } from './ui_utils'; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Performs navigation functions inside PDF, such as opening specified page, |
|
|
|
* Performs navigation functions inside PDF, such as opening specified page, |
|
|
|
* or destination. |
|
|
|
* or destination. |
|
|
|
* @class |
|
|
|
|
|
|
|
* @implements {IPDFLinkService} |
|
|
|
* @implements {IPDFLinkService} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
class PDFLinkService { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @constructs PDFLinkService |
|
|
|
|
|
|
|
* @param {PDFLinkServiceOptions} options |
|
|
|
* @param {PDFLinkServiceOptions} options |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function PDFLinkService(options) { |
|
|
|
constructor({ eventBus, } = {}) { |
|
|
|
options = options || {}; |
|
|
|
this.eventBus = eventBus || getGlobalEventBus(); |
|
|
|
this.eventBus = options.eventBus || getGlobalEventBus(); |
|
|
|
|
|
|
|
this.baseUrl = null; |
|
|
|
this.baseUrl = null; |
|
|
|
this.pdfDocument = null; |
|
|
|
this.pdfDocument = null; |
|
|
|
this.pdfViewer = null; |
|
|
|
this.pdfViewer = null; |
|
|
@ -43,41 +40,40 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
this._pagesRefCache = null; |
|
|
|
this._pagesRefCache = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PDFLinkService.prototype = { |
|
|
|
setDocument(pdfDocument, baseUrl) { |
|
|
|
setDocument: function PDFLinkService_setDocument(pdfDocument, baseUrl) { |
|
|
|
|
|
|
|
this.baseUrl = baseUrl; |
|
|
|
this.baseUrl = baseUrl; |
|
|
|
this.pdfDocument = pdfDocument; |
|
|
|
this.pdfDocument = pdfDocument; |
|
|
|
this._pagesRefCache = Object.create(null); |
|
|
|
this._pagesRefCache = Object.create(null); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setViewer: function PDFLinkService_setViewer(pdfViewer) { |
|
|
|
setViewer(pdfViewer) { |
|
|
|
this.pdfViewer = pdfViewer; |
|
|
|
this.pdfViewer = pdfViewer; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setHistory: function PDFLinkService_setHistory(pdfHistory) { |
|
|
|
setHistory(pdfHistory) { |
|
|
|
this.pdfHistory = pdfHistory; |
|
|
|
this.pdfHistory = pdfHistory; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @returns {number} |
|
|
|
* @returns {number} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
get pagesCount() { |
|
|
|
get pagesCount() { |
|
|
|
return this.pdfDocument ? this.pdfDocument.numPages : 0; |
|
|
|
return this.pdfDocument ? this.pdfDocument.numPages : 0; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @returns {number} |
|
|
|
* @returns {number} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
get page() { |
|
|
|
get page() { |
|
|
|
return this.pdfViewer.currentPageNumber; |
|
|
|
return this.pdfViewer.currentPageNumber; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {number} value |
|
|
|
* @param {number} value |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
set page(value) { |
|
|
|
set page(value) { |
|
|
|
this.pdfViewer.currentPageNumber = value; |
|
|
|
this.pdfViewer.currentPageNumber = value; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {string|Array} dest - The named, or explicit, PDF destination. |
|
|
|
* @param {string|Array} dest - The named, or explicit, PDF destination. |
|
|
@ -151,7 +147,7 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
goToDestination(data); |
|
|
|
goToDestination(data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {string|Array} dest - The PDF destination object. |
|
|
|
* @param {string|Array} dest - The PDF destination object. |
|
|
@ -166,7 +162,7 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
return this.getAnchorUrl('#' + escape(str)); |
|
|
|
return this.getAnchorUrl('#' + escape(str)); |
|
|
|
} |
|
|
|
} |
|
|
|
return this.getAnchorUrl(''); |
|
|
|
return this.getAnchorUrl(''); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prefix the full url on anchor links to make sure that links are resolved |
|
|
|
* Prefix the full url on anchor links to make sure that links are resolved |
|
|
@ -174,17 +170,17 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
* @param {String} anchor The anchor hash, including the #. |
|
|
|
* @param {String} anchor The anchor hash, including the #. |
|
|
|
* @returns {string} The hyperlink to the PDF object. |
|
|
|
* @returns {string} The hyperlink to the PDF object. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
getAnchorUrl: function PDFLinkService_getAnchorUrl(anchor) { |
|
|
|
getAnchorUrl(anchor) { |
|
|
|
return (this.baseUrl || '') + anchor; |
|
|
|
return (this.baseUrl || '') + anchor; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {string} hash |
|
|
|
* @param {string} hash |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setHash: function PDFLinkService_setHash(hash) { |
|
|
|
setHash(hash) { |
|
|
|
var pageNumber, dest; |
|
|
|
let pageNumber, dest; |
|
|
|
if (hash.indexOf('=') >= 0) { |
|
|
|
if (hash.indexOf('=') >= 0) { |
|
|
|
var params = parseQueryString(hash); |
|
|
|
let params = parseQueryString(hash); |
|
|
|
if ('search' in params) { |
|
|
|
if ('search' in params) { |
|
|
|
this.eventBus.dispatch('findfromurlhash', { |
|
|
|
this.eventBus.dispatch('findfromurlhash', { |
|
|
|
source: this, |
|
|
|
source: this, |
|
|
@ -205,9 +201,9 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
if ('zoom' in params) { |
|
|
|
if ('zoom' in params) { |
|
|
|
// Build the destination array.
|
|
|
|
// Build the destination array.
|
|
|
|
var zoomArgs = params.zoom.split(','); // scale,left,top
|
|
|
|
let zoomArgs = params.zoom.split(','); // scale,left,top
|
|
|
|
var zoomArg = zoomArgs[0]; |
|
|
|
let zoomArg = zoomArgs[0]; |
|
|
|
var zoomArgNumber = parseFloat(zoomArg); |
|
|
|
let zoomArgNumber = parseFloat(zoomArg); |
|
|
|
|
|
|
|
|
|
|
|
if (zoomArg.indexOf('Fit') === -1) { |
|
|
|
if (zoomArg.indexOf('Fit') === -1) { |
|
|
|
// If the zoomArg is a number, it has to get divided by 100. If it's
|
|
|
|
// If the zoomArg is a number, it has to get divided by 100. If it's
|
|
|
@ -225,16 +221,16 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
zoomArgs.length > 1 ? (zoomArgs[1] | 0) : null]; |
|
|
|
zoomArgs.length > 1 ? (zoomArgs[1] | 0) : null]; |
|
|
|
} else if (zoomArg === 'FitR') { |
|
|
|
} else if (zoomArg === 'FitR') { |
|
|
|
if (zoomArgs.length !== 5) { |
|
|
|
if (zoomArgs.length !== 5) { |
|
|
|
console.error('PDFLinkService_setHash: ' + |
|
|
|
console.error( |
|
|
|
'Not enough parameters for \'FitR\'.'); |
|
|
|
'PDFLinkService.setHash: Not enough parameters for "FitR".'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dest = [null, { name: zoomArg, }, |
|
|
|
dest = [null, { name: zoomArg, }, |
|
|
|
(zoomArgs[1] | 0), (zoomArgs[2] | 0), |
|
|
|
(zoomArgs[1] | 0), (zoomArgs[2] | 0), |
|
|
|
(zoomArgs[3] | 0), (zoomArgs[4] | 0)]; |
|
|
|
(zoomArgs[3] | 0), (zoomArgs[4] | 0)]; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.error('PDFLinkService_setHash: \'' + zoomArg + |
|
|
|
console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + |
|
|
|
'\' is not a valid zoom value.'); |
|
|
|
'a valid zoom value.'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -258,7 +254,7 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
/^\d+$/.test(hash) && hash <= this.pagesCount) { |
|
|
|
/^\d+$/.test(hash) && hash <= this.pagesCount) { |
|
|
|
console.warn('PDFLinkService_setHash: specifying a page number ' + |
|
|
|
console.warn('PDFLinkService_setHash: specifying a page number ' + |
|
|
|
'directly after the hash symbol (#) is deprecated, ' + |
|
|
|
'directly after the hash symbol (#) is deprecated, ' + |
|
|
|
'please use the "#page=' + hash + '" form instead.'); |
|
|
|
`please use the "#page=${hash}" form instead.`); |
|
|
|
this.page = hash | 0; |
|
|
|
this.page = hash | 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -280,15 +276,15 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
this.navigateTo(dest); |
|
|
|
this.navigateTo(dest); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
console.error('PDFLinkService_setHash: \'' + unescape(hash) + |
|
|
|
console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + |
|
|
|
'\' is not a valid destination.'); |
|
|
|
'a valid destination.'); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {string} action |
|
|
|
* @param {string} action |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
executeNamedAction: function PDFLinkService_executeNamedAction(action) { |
|
|
|
executeNamedAction(action) { |
|
|
|
// See PDF reference, table 8.45 - Named action
|
|
|
|
// See PDF reference, table 8.45 - Named action
|
|
|
|
switch (action) { |
|
|
|
switch (action) { |
|
|
|
case 'GoBack': |
|
|
|
case 'GoBack': |
|
|
@ -331,51 +327,51 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
source: this, |
|
|
|
source: this, |
|
|
|
action, |
|
|
|
action, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {Object} params |
|
|
|
* @param {Object} params |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
onFileAttachmentAnnotation(params = {}) { |
|
|
|
onFileAttachmentAnnotation({ id, filename, content, }) { |
|
|
|
this.eventBus.dispatch('fileattachmentannotation', { |
|
|
|
this.eventBus.dispatch('fileattachmentannotation', { |
|
|
|
source: this, |
|
|
|
source: this, |
|
|
|
id: params.id, |
|
|
|
id, |
|
|
|
filename: params.filename, |
|
|
|
filename, |
|
|
|
content: params.content, |
|
|
|
content, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {number} pageNum - page number. |
|
|
|
* @param {number} pageNum - page number. |
|
|
|
* @param {Object} pageRef - reference to the page. |
|
|
|
* @param {Object} pageRef - reference to the page. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
cachePageRef: function PDFLinkService_cachePageRef(pageNum, pageRef) { |
|
|
|
cachePageRef(pageNum, pageRef) { |
|
|
|
var refStr = pageRef.num + ' ' + pageRef.gen + ' R'; |
|
|
|
let refStr = pageRef.num + ' ' + pageRef.gen + ' R'; |
|
|
|
this._pagesRefCache[refStr] = pageNum; |
|
|
|
this._pagesRefCache[refStr] = pageNum; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_cachedPageNumber: function PDFLinkService_cachedPageNumber(pageRef) { |
|
|
|
_cachedPageNumber(pageRef) { |
|
|
|
var refStr = pageRef.num + ' ' + pageRef.gen + ' R'; |
|
|
|
let refStr = pageRef.num + ' ' + pageRef.gen + ' R'; |
|
|
|
return (this._pagesRefCache && this._pagesRefCache[refStr]) || null; |
|
|
|
return (this._pagesRefCache && this._pagesRefCache[refStr]) || null; |
|
|
|
}, |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function isValidExplicitDestination(dest) { |
|
|
|
function isValidExplicitDestination(dest) { |
|
|
|
if (!(dest instanceof Array)) { |
|
|
|
if (!(dest instanceof Array)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
var destLength = dest.length, allowNull = true; |
|
|
|
let destLength = dest.length, allowNull = true; |
|
|
|
if (destLength < 2) { |
|
|
|
if (destLength < 2) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
var page = dest[0]; |
|
|
|
let page = dest[0]; |
|
|
|
if (!(typeof page === 'object' && |
|
|
|
if (!(typeof page === 'object' && |
|
|
|
typeof page.num === 'number' && (page.num | 0) === page.num && |
|
|
|
typeof page.num === 'number' && (page.num | 0) === page.num && |
|
|
|
typeof page.gen === 'number' && (page.gen | 0) === page.gen) && |
|
|
|
typeof page.gen === 'number' && (page.gen | 0) === page.gen) && |
|
|
|
!(typeof page === 'number' && (page | 0) === page && page >= 0)) { |
|
|
|
!(typeof page === 'number' && (page | 0) === page && page >= 0)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
var zoom = dest[1]; |
|
|
|
let zoom = dest[1]; |
|
|
|
if (!(typeof zoom === 'object' && typeof zoom.name === 'string')) { |
|
|
|
if (!(typeof zoom === 'object' && typeof zoom.name === 'string')) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -405,8 +401,8 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
default: |
|
|
|
default: |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
for (var i = 2; i < destLength; i++) { |
|
|
|
for (let i = 2; i < destLength; i++) { |
|
|
|
var param = dest[i]; |
|
|
|
let param = dest[i]; |
|
|
|
if (!(typeof param === 'number' || (allowNull && param === null))) { |
|
|
|
if (!(typeof param === 'number' || (allowNull && param === null))) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -414,61 +410,53 @@ var PDFLinkService = (function PDFLinkServiceClosure() { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return PDFLinkService; |
|
|
|
class SimpleLinkService { |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var SimpleLinkService = (function SimpleLinkServiceClosure() { |
|
|
|
|
|
|
|
function SimpleLinkService() {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SimpleLinkService.prototype = { |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @returns {number} |
|
|
|
* @returns {number} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
get page() { |
|
|
|
get page() { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}, |
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {number} value |
|
|
|
* @param {number} value |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
set page(value) {}, |
|
|
|
set page(value) {} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param dest - The PDF destination object. |
|
|
|
* @param dest - The PDF destination object. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
navigateTo(dest) {}, |
|
|
|
navigateTo(dest) {} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param dest - The PDF destination object. |
|
|
|
* @param dest - The PDF destination object. |
|
|
|
* @returns {string} The hyperlink to the PDF object. |
|
|
|
* @returns {string} The hyperlink to the PDF object. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
getDestinationHash(dest) { |
|
|
|
getDestinationHash(dest) { |
|
|
|
return '#'; |
|
|
|
return '#'; |
|
|
|
}, |
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param hash - The PDF parameters/hash. |
|
|
|
* @param hash - The PDF parameters/hash. |
|
|
|
* @returns {string} The hyperlink to the PDF object. |
|
|
|
* @returns {string} The hyperlink to the PDF object. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
getAnchorUrl(hash) { |
|
|
|
getAnchorUrl(hash) { |
|
|
|
return '#'; |
|
|
|
return '#'; |
|
|
|
}, |
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {string} hash |
|
|
|
* @param {string} hash |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
setHash(hash) {}, |
|
|
|
setHash(hash) {} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {string} action |
|
|
|
* @param {string} action |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
executeNamedAction(action) {}, |
|
|
|
executeNamedAction(action) {} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {Object} params |
|
|
|
* @param {Object} params |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
onFileAttachmentAnnotation(params) {}, |
|
|
|
onFileAttachmentAnnotation({ id, filename, content, }) {} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param {number} pageNum - page number. |
|
|
|
* @param {number} pageNum - page number. |
|
|
|
* @param {Object} pageRef - reference to the page. |
|
|
|
* @param {Object} pageRef - reference to the page. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
cachePageRef(pageNum, pageRef) {}, |
|
|
|
cachePageRef(pageNum, pageRef) {} |
|
|
|
}; |
|
|
|
} |
|
|
|
return SimpleLinkService; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export { |
|
|
|
export { |
|
|
|
PDFLinkService, |
|
|
|
PDFLinkService, |
|
|
|