[api-minor] Let getAnnotations fetch all annotations by default, unless an intent is specified

Currently `getAnnotations` will *only* fetch annotations that are either `viewable` or `printable`. This is "hidden" inside the `core.js` file, meaning that API consumers might be confused as to why they are not recieving *all* the annotations present for a page.

I thus think that the API should, by default, return *all* available annotations unless specifically told otherwise. In e.g. the default viewer, we obviously only want to display annotations that are `viewable`, hence this patch adds an `intent` parameter to `getAnnotations` that makes it possible to decide if only `viewable` or `printable` annotations should be fetched.
This commit is contained in:
Jonas Jenwald 2015-11-22 13:56:52 +01:00
parent aa75c4fe4e
commit b05652ca97
6 changed files with 55 additions and 17 deletions

View file

@ -649,6 +649,16 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* @property {string} fontFamily - possible font family
*/
/**
* Page annotation parameters.
*
* @typedef {Object} GetAnnotationsParameters
* @param {string} intent - Determines the annotations that will be fetched,
* can be either 'display' (viewable annotations) or 'print'
* (printable annotations).
* If the parameter is omitted, all annotations are fetched.
*/
/**
* Page render parameters.
*
@ -737,12 +747,17 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
},
/**
* @param {GetAnnotationsParameters} params - Annotation parameters.
* @return {Promise} A promise that is resolved with an {Array} of the
* annotation objects.
*/
getAnnotations: function PDFPageProxy_getAnnotations() {
if (!this.annotationsPromise) {
this.annotationsPromise = this.transport.getAnnotations(this.pageIndex);
getAnnotations: function PDFPageProxy_getAnnotations(params) {
var intent = (params && params.intent) || null;
if (!this.annotationsPromise || this.annotationsIntent !== intent) {
this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
intent);
this.annotationsIntent = intent;
}
return this.annotationsPromise;
},
@ -1470,9 +1485,11 @@ var WorkerTransport = (function WorkerTransportClosure() {
return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
},
getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
return this.messageHandler.sendWithPromise('GetAnnotations',
{ pageIndex: pageIndex });
getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
return this.messageHandler.sendWithPromise('GetAnnotations', {
pageIndex: pageIndex,
intent: intent,
});
},
getDestinations: function WorkerTransport_getDestinations() {
@ -1480,7 +1497,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
},
getDestination: function WorkerTransport_getDestination(id) {
return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
return this.messageHandler.sendWithPromise('GetDestination', { id: id });
},
getAttachments: function WorkerTransport_getAttachments() {