[api-minor] Include the /Lang-property in the documentInfo, and use it in the viewer (issue 14110)

*Please note:* This is a tentative patch, since I don't have the necessary a11y-software to actually test it.

To avoid having to add a new API-method just for a single string, I figured that adding the new property to the existing `documentInfo`-data (accessed via `PDFDocumentProxy.getMetadata` in the API) will hopefully be deemed acceptable.
This commit is contained in:
Jonas Jenwald 2021-10-11 15:55:16 +02:00
parent 52fce0d17b
commit 00720d059a
4 changed files with 17 additions and 0 deletions

View File

@ -89,6 +89,15 @@ class Catalog {
); );
} }
get lang() {
const lang = this._catDict.get("Lang");
return shadow(
this,
"lang",
typeof lang === "string" ? stringToPDFString(lang) : null
);
}
/** /**
* @type {boolean} `true` for pure XFA documents, * @type {boolean} `true` for pure XFA documents,
* `false` for XFA Foreground documents. * `false` for XFA Foreground documents.

View File

@ -1160,6 +1160,7 @@ class PDFDocument {
const docInfo = { const docInfo = {
PDFFormatVersion: version, PDFFormatVersion: version,
Language: this.catalog.lang,
IsLinearized: !!this.linearization, IsLinearized: !!this.linearization,
IsAcroFormPresent: this.formInfo.hasAcroForm, IsAcroFormPresent: this.formInfo.hasAcroForm,
IsXFAPresent: this.formInfo.hasXfa, IsXFAPresent: this.formInfo.hasXfa,

View File

@ -1161,6 +1161,7 @@ describe("api", function () {
expect(info.Custom).toEqual(undefined); expect(info.Custom).toEqual(undefined);
// 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.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);
@ -1195,6 +1196,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.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);
@ -1216,6 +1218,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.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);

View File

@ -812,6 +812,7 @@ const PDFViewerApplication = {
const { container } = this.appConfig.errorWrapper; const { container } = this.appConfig.errorWrapper;
container.hidden = true; container.hidden = true;
} }
this.appConfig.viewerContainer.removeAttribute("lang");
if (!this.pdfLoadingTask) { if (!this.pdfLoadingTask) {
return; return;
@ -1536,6 +1537,9 @@ const PDFViewerApplication = {
`(PDF.js: ${version || "-"})` `(PDF.js: ${version || "-"})`
); );
if (info.Language) {
this.appConfig.viewerContainer.lang = info.Language;
}
let pdfTitle = info?.Title; let pdfTitle = info?.Title;
const metadataTitle = metadata?.get("dc:title"); const metadataTitle = metadata?.get("dc:title");