Add page size to the document properties dialog

This commit is contained in:
palsch 2018-03-08 18:23:47 +01:00
parent 5f98f9b8f1
commit 8558c5b1d9
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_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…

View File

@ -626,6 +626,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.

View File

@ -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
*/

View File

@ -351,6 +351,13 @@ See https://github.com/adobe-type-tools/cmap-resources
<div class="row">
<span data-l10n-id="document_properties_page_count">Page Count:</span> <p id="pageCountField">-</p>
</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">
<button id="documentPropertiesClose" class="overlayButton"><span data-l10n-id="document_properties_close">Close</span></button>
</div>

View File

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