diff --git a/l10n/en-US/viewer.properties b/l10n/en-US/viewer.properties index f1c505478..7a795712b 100644 --- a/l10n/en-US/viewer.properties +++ b/l10n/en-US/viewer.properties @@ -89,6 +89,13 @@ document_properties_creator=Creator: document_properties_producer=PDF Producer: document_properties_version=PDF Version: document_properties_page_count=Page Count: +document_properties_page_size=Page Size: +# LOCALIZATION NOTE (document_properties_page_size_in): "{{width_in}}" and "{{height_in}}" +# will be replaced by the size of the first page of the PDF file in inches. +document_properties_page_size_in={{width_in}}in × {{height_in}}in +# LOCALIZATION NOTE (document_properties_page_size_mm): "{{width_mm}}" and "{{height_mm}}" +# will be replaced by the size of the first page of the PDF file in millimeters. +document_properties_page_size_mm={{width_mm}}mm × {{height_mm}}mm document_properties_close=Close print_progress_message=Preparing document for printing… diff --git a/src/display/api.js b/src/display/api.js index 163f257b2..0d2e316fe 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -692,6 +692,23 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() { getMetadata: function PDFDocumentProxy_getMetadata() { return this.transport.getMetadata(); }, + /** + * @param {number} pageNumber The page number to get the page size from. + * The first page is 1, which is also the default page used. + * @return {Promise} A promise that is resolved with an dict containing the + * width and height in inches. + */ + getPageSizeInches(pageNumber) { + pageNumber = pageNumber || 1; + return this.getPage(pageNumber).then((page) => { + const [x1, y1, x2, y2] = page.view; + // convert values from user units to inches + return { + width: (x2 - x1) / 72 * page.userUnit, + height: (y2 - y1) / 72 * page.userUnit, + }; + }); + }, /** * @return {Promise} A promise that is resolved with a TypedArray that has * the raw data from the PDF. diff --git a/web/pdf_document_properties.js b/web/pdf_document_properties.js index cb118920b..7f351592b 100644 --- a/web/pdf_document_properties.js +++ b/web/pdf_document_properties.js @@ -79,9 +79,14 @@ class PDFDocumentProperties { contentDispositionFilename || getPDFFileNameFromURL(this.url), this._parseFileSize(this.maybeFileSize), this._parseDate(info.CreationDate), - this._parseDate(info.ModDate) + this._parseDate(info.ModDate), + this.pdfDocument.getPageSizeInches().then((pageSizeInches) => { + return this._parsePageSize(pageSizeInches); + }), + ]); - }).then(([info, metadata, fileName, fileSize, creationDate, modDate]) => { + }).then(([info, metadata, fileName, fileSize, + creationDate, modDate, pageSize]) => { freezeFieldData({ 'fileName': fileName, 'fileSize': fileSize, @@ -95,6 +100,8 @@ class PDFDocumentProperties { 'producer': info.Producer, 'version': info.PDFFormatVersion, 'pageCount': this.pdfDocument.numPages, + 'pageSizeInch': pageSize.inch, + 'pageSizeMM': pageSize.mm, }); this._updateUI(); @@ -212,6 +219,33 @@ class PDFDocumentProperties { }, '{{size_mb}} MB ({{size_b}} bytes)'); } + /** + * @private + */ + _parsePageSize(pageSizeInches) { + if (!pageSizeInches) { + return Promise.resolve([undefined, undefined]); + } + const sizes_two_units = { + 'width_in': Math.round(pageSizeInches.width * 100) / 100, + 'height_in': Math.round(pageSizeInches.height * 100) / 100, + // 1in = 25.4mm; no need to round to 2 decimals for mm + 'width_mm': Math.round(pageSizeInches.width * 25.4 * 10) / 10, + 'height_mm': Math.round(pageSizeInches.height * 25.4 * 10) / 10, + }; + return Promise.all([ + this.l10n.get('document_properties_page_size_in', + sizes_two_units, '{{width_in}} in × {{height_in}} in'), + this.l10n.get('document_properties_page_size_mm', + sizes_two_units, '{{width_mm}} mm × {{height_mm}} mm'), + ]).then(([parsedPageSizeInches, parsedPageSizeMM]) => { + return Promise.resolve({ + inch: parsedPageSizeInches, + mm: parsedPageSizeMM, + }); + }); + } + /** * @private */ diff --git a/web/viewer.html b/web/viewer.html index 2faa0729c..7baec33e2 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -351,6 +351,13 @@ See https://github.com/adobe-type-tools/cmap-resources
Page Count:

-

+
+ Page Size: +

+ -
+ - +

+
diff --git a/web/viewer.js b/web/viewer.js index 1c3fbb240..242bf1df6 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -159,6 +159,8 @@ function getViewerConfiguration() { 'producer': document.getElementById('producerField'), 'version': document.getElementById('versionField'), 'pageCount': document.getElementById('pageCountField'), + 'pageSizeInch': document.getElementById('pageSizeFieldInch'), + 'pageSizeMM': document.getElementById('pageSizeFieldMM'), }, }, errorWrapper: {