[api-minor] Implement API to get MarkInfo from the catalog.
This commit is contained in:
parent
8cf27494b3
commit
f5c821e9c3
@ -152,6 +152,47 @@ class Catalog {
|
|||||||
return shadow(this, "metadata", metadata);
|
return shadow(this, "metadata", metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get markInfo() {
|
||||||
|
let markInfo = null;
|
||||||
|
try {
|
||||||
|
markInfo = this._readMarkInfo();
|
||||||
|
} catch (ex) {
|
||||||
|
if (ex instanceof MissingDataException) {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
warn("Unable to read mark info.");
|
||||||
|
}
|
||||||
|
return shadow(this, "markInfo", markInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_readMarkInfo() {
|
||||||
|
const obj = this._catDict.get("MarkInfo");
|
||||||
|
if (!isDict(obj)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const markInfo = Object.assign(Object.create(null), {
|
||||||
|
Marked: false,
|
||||||
|
UserProperties: false,
|
||||||
|
Suspects: false,
|
||||||
|
});
|
||||||
|
for (const key in markInfo) {
|
||||||
|
if (!obj.has(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const value = obj.get(key);
|
||||||
|
if (!isBool(value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
markInfo[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return markInfo;
|
||||||
|
}
|
||||||
|
|
||||||
get toplevelPagesDict() {
|
get toplevelPagesDict() {
|
||||||
const pagesObj = this._catDict.get("Pages");
|
const pagesObj = this._catDict.get("Pages");
|
||||||
if (!isDict(pagesObj)) {
|
if (!isDict(pagesObj)) {
|
||||||
|
@ -499,6 +499,10 @@ class WorkerMessageHandler {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handler.on("GetMarkInfo", function wphSetupGetMarkInfo(data) {
|
||||||
|
return pdfManager.ensureCatalog("markInfo");
|
||||||
|
});
|
||||||
|
|
||||||
handler.on("GetData", function wphSetupGetData(data) {
|
handler.on("GetData", function wphSetupGetData(data) {
|
||||||
pdfManager.requestLoadedStream();
|
pdfManager.requestLoadedStream();
|
||||||
return pdfManager.onLoadedStream().then(function (stream) {
|
return pdfManager.onLoadedStream().then(function (stream) {
|
||||||
|
@ -805,6 +805,23 @@ class PDFDocumentProxy {
|
|||||||
return this._transport.getMetadata();
|
return this._transport.getMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} MarkInfo
|
||||||
|
* Properties correspond to Table 321 of the PDF 32000-1:2008 spec.
|
||||||
|
* @property {boolean} Marked
|
||||||
|
* @property {boolean} UserProperties
|
||||||
|
* @property {boolean} Suspects
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Promise<MarkInfo | null>} A promise that is resolved with
|
||||||
|
* a {MarkInfo} object that contains the MarkInfo flags for the PDF
|
||||||
|
* document, or `null` when no MarkInfo values are present in the PDF file.
|
||||||
|
*/
|
||||||
|
getMarkInfo() {
|
||||||
|
return this._transport.getMarkInfo();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Promise<TypedArray>} A promise that is resolved with a
|
* @returns {Promise<TypedArray>} A promise that is resolved with a
|
||||||
* {TypedArray} that has the raw data from the PDF.
|
* {TypedArray} that has the raw data from the PDF.
|
||||||
@ -2646,6 +2663,10 @@ class WorkerTransport {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMarkInfo() {
|
||||||
|
return this.messageHandler.sendWithPromise("GetMarkInfo", null);
|
||||||
|
}
|
||||||
|
|
||||||
getStats() {
|
getStats() {
|
||||||
return this.messageHandler.sendWithPromise("GetStats", null);
|
return this.messageHandler.sendWithPromise("GetStats", null);
|
||||||
}
|
}
|
||||||
|
@ -1192,6 +1192,24 @@ describe("api", function () {
|
|||||||
.catch(done.fail);
|
.catch(done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("gets markInfo", function (done) {
|
||||||
|
const loadingTask = getDocument(
|
||||||
|
buildGetDocumentParams("annotation-line.pdf")
|
||||||
|
);
|
||||||
|
|
||||||
|
loadingTask.promise
|
||||||
|
.then(function (pdfDoc) {
|
||||||
|
return pdfDoc.getMarkInfo();
|
||||||
|
})
|
||||||
|
.then(function (info) {
|
||||||
|
expect(info.Marked).toEqual(true);
|
||||||
|
expect(info.UserProperties).toEqual(false);
|
||||||
|
expect(info.Suspects).toEqual(false);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
it("gets data", function (done) {
|
it("gets data", function (done) {
|
||||||
var promise = pdfDocument.getData();
|
var promise = pdfDocument.getData();
|
||||||
promise
|
promise
|
||||||
|
Loading…
Reference in New Issue
Block a user