mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 23:28:06 +02:00
Add page size to the document properties dialog
This commit is contained in:
parent
5f98f9b8f1
commit
8558c5b1d9
5 changed files with 69 additions and 2 deletions
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue