[api-minor] Implement securityHandler in the scripting API (bug 1731578)

This commit is contained in:
Jane-Kotovich 2021-10-26 00:09:26 +10:00
parent 1ab9a6e36e
commit 91fc643ff9
7 changed files with 32 additions and 1 deletions

View File

@ -1689,6 +1689,7 @@ const CipherTransformFactory = (function CipherTransformFactoryClosure() {
if (!isName(filter, "Standard")) { if (!isName(filter, "Standard")) {
throw new FormatError("unknown encryption method"); throw new FormatError("unknown encryption method");
} }
this.filterName = filter.name;
this.dict = dict; this.dict = dict;
const algorithm = dict.get("V"); const algorithm = dict.get("V");
if ( if (

View File

@ -1161,6 +1161,9 @@ class PDFDocument {
const docInfo = { const docInfo = {
PDFFormatVersion: version, PDFFormatVersion: version,
Language: this.catalog.lang, Language: this.catalog.lang,
EncryptFilterName: this.xref.encrypt
? this.xref.encrypt.filterName
: null,
IsLinearized: !!this.linearization, IsLinearized: !!this.linearization,
IsAcroFormPresent: this.formInfo.hasAcroForm, IsAcroFormPresent: this.formInfo.hasAcroForm,
IsXFAPresent: this.formInfo.hasXfa, IsXFAPresent: this.formInfo.hasXfa,

View File

@ -66,6 +66,7 @@ class Doc extends PDFObject {
this._numPages = data.numPages || 1; this._numPages = data.numPages || 1;
this._pageNum = data.pageNum || 0; this._pageNum = data.pageNum || 0;
this._producer = data.Producer || ""; this._producer = data.Producer || "";
this._securityHandler = data.EncryptFilterName || null;
this._subject = data.Subject || ""; this._subject = data.Subject || "";
this._title = data.Title || ""; this._title = data.Title || "";
this._URL = data.URL || ""; this._URL = data.URL || "";
@ -522,7 +523,7 @@ class Doc extends PDFObject {
} }
get securityHandler() { get securityHandler() {
return null; return this._securityHandler;
} }
set securityHandler(_) { set securityHandler(_) {

View File

@ -896,4 +896,26 @@ describe("Interaction", () => {
); );
}); });
}); });
describe("in secHandler.pdf", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("secHandler.pdf", "#\\32 5R");
});
afterAll(async () => {
await closePages(pages);
});
it("must print securityHandler value in a text field", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const text = await actAndWaitForInput(page, "#\\32 5R", async () => {
await page.click("[data-annotation-id='26R']");
});
expect(text).withContext(`In ${browserName}`).toEqual("Standard");
})
);
});
});
}); });

View File

@ -477,3 +477,4 @@
!issue12337.pdf !issue12337.pdf
!pr12564.pdf !pr12564.pdf
!pr12828.pdf !pr12828.pdf
!secHandler.pdf

BIN
test/pdfs/secHandler.pdf Normal file

Binary file not shown.

View File

@ -1166,6 +1166,7 @@ describe("api", function () {
// The following are PDF.js specific, non-standard, properties. // The following are PDF.js specific, non-standard, properties.
expect(info.PDFFormatVersion).toEqual("1.7"); expect(info.PDFFormatVersion).toEqual("1.7");
expect(info.Language).toEqual("en"); expect(info.Language).toEqual("en");
expect(info.EncryptFilterName).toEqual(null);
expect(info.IsLinearized).toEqual(false); expect(info.IsLinearized).toEqual(false);
expect(info.IsAcroFormPresent).toEqual(false); expect(info.IsAcroFormPresent).toEqual(false);
expect(info.IsXFAPresent).toEqual(false); expect(info.IsXFAPresent).toEqual(false);
@ -1201,6 +1202,7 @@ describe("api", function () {
// The following are PDF.js specific, non-standard, properties. // The following are PDF.js specific, non-standard, properties.
expect(info.PDFFormatVersion).toEqual("1.4"); expect(info.PDFFormatVersion).toEqual("1.4");
expect(info.Language).toEqual(null); expect(info.Language).toEqual(null);
expect(info.EncryptFilterName).toEqual(null);
expect(info.IsLinearized).toEqual(false); expect(info.IsLinearized).toEqual(false);
expect(info.IsAcroFormPresent).toEqual(false); expect(info.IsAcroFormPresent).toEqual(false);
expect(info.IsXFAPresent).toEqual(false); expect(info.IsXFAPresent).toEqual(false);
@ -1223,6 +1225,7 @@ describe("api", function () {
// The following are PDF.js specific, non-standard, properties. // The following are PDF.js specific, non-standard, properties.
expect(info.PDFFormatVersion).toEqual(null); expect(info.PDFFormatVersion).toEqual(null);
expect(info.Language).toEqual(null); expect(info.Language).toEqual(null);
expect(info.EncryptFilterName).toEqual(null);
expect(info.IsLinearized).toEqual(false); expect(info.IsLinearized).toEqual(false);
expect(info.IsAcroFormPresent).toEqual(false); expect(info.IsAcroFormPresent).toEqual(false);
expect(info.IsXFAPresent).toEqual(false); expect(info.IsXFAPresent).toEqual(false);