Merge pull request #9508 from pal03377/file-info-page-size

Add paper size to document information/properties
This commit is contained in:
Yury Delendik 2018-03-08 11:57:38 -06:00 committed by GitHub
commit e0fb18a339
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 2 deletions

View File

@ -89,6 +89,13 @@ document_properties_creator=Creator:
document_properties_producer=PDF Producer: document_properties_producer=PDF Producer:
document_properties_version=PDF Version: document_properties_version=PDF Version:
document_properties_page_count=Page Count: 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 document_properties_close=Close
print_progress_message=Preparing document for printing… print_progress_message=Preparing document for printing…

View File

@ -692,6 +692,23 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
getMetadata: function PDFDocumentProxy_getMetadata() { getMetadata: function PDFDocumentProxy_getMetadata() {
return this.transport.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 * @return {Promise} A promise that is resolved with a TypedArray that has
* the raw data from the PDF. * the raw data from the PDF.

View File

@ -79,9 +79,14 @@ class PDFDocumentProperties {
contentDispositionFilename || getPDFFileNameFromURL(this.url), contentDispositionFilename || getPDFFileNameFromURL(this.url),
this._parseFileSize(this.maybeFileSize), this._parseFileSize(this.maybeFileSize),
this._parseDate(info.CreationDate), 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({ freezeFieldData({
'fileName': fileName, 'fileName': fileName,
'fileSize': fileSize, 'fileSize': fileSize,
@ -95,6 +100,8 @@ class PDFDocumentProperties {
'producer': info.Producer, 'producer': info.Producer,
'version': info.PDFFormatVersion, 'version': info.PDFFormatVersion,
'pageCount': this.pdfDocument.numPages, 'pageCount': this.pdfDocument.numPages,
'pageSizeInch': pageSize.inch,
'pageSizeMM': pageSize.mm,
}); });
this._updateUI(); this._updateUI();
@ -212,6 +219,33 @@ class PDFDocumentProperties {
}, '{{size_mb}} MB ({{size_b}} bytes)'); }, '{{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 * @private
*/ */

View File

@ -351,6 +351,13 @@ See https://github.com/adobe-type-tools/cmap-resources
<div class="row"> <div class="row">
<span data-l10n-id="document_properties_page_count">Page Count:</span> <p id="pageCountField">-</p> <span data-l10n-id="document_properties_page_count">Page Count:</span> <p id="pageCountField">-</p>
</div> </div>
<div class="row">
<span data-l10n-id="document_properties_page_size">Page Size:</span>
<p>
<span id="pageSizeFieldMM">-</span><br>
<span id="pageSizeFieldInch">-</span>
</p>
</div>
<div class="buttonRow"> <div class="buttonRow">
<button id="documentPropertiesClose" class="overlayButton"><span data-l10n-id="document_properties_close">Close</span></button> <button id="documentPropertiesClose" class="overlayButton"><span data-l10n-id="document_properties_close">Close</span></button>
</div> </div>

View File

@ -159,6 +159,8 @@ function getViewerConfiguration() {
'producer': document.getElementById('producerField'), 'producer': document.getElementById('producerField'),
'version': document.getElementById('versionField'), 'version': document.getElementById('versionField'),
'pageCount': document.getElementById('pageCountField'), 'pageCount': document.getElementById('pageCountField'),
'pageSizeInch': document.getElementById('pageSizeFieldInch'),
'pageSizeMM': document.getElementById('pageSizeFieldMM'),
}, },
}, },
errorWrapper: { errorWrapper: {