|
|
@ -37,6 +37,20 @@ var _pdf = require('../pdf'); |
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
|
|
|
|
|
|
|
|
|
|
var DEFAULT_FIELD_CONTENT = '-'; |
|
|
|
var DEFAULT_FIELD_CONTENT = '-'; |
|
|
|
|
|
|
|
var NON_METRIC_LOCALES = ['en-us', 'en-lr', 'my']; |
|
|
|
|
|
|
|
var US_PAGE_NAMES = { |
|
|
|
|
|
|
|
'8.5x11': 'Letter', |
|
|
|
|
|
|
|
'8.5x14': 'Legal' |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
var METRIC_PAGE_NAMES = { |
|
|
|
|
|
|
|
'297x420': 'A3', |
|
|
|
|
|
|
|
'210x297': 'A4' |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
function getPageName(size, isPortrait, pageNames) { |
|
|
|
|
|
|
|
var width = isPortrait ? size.width : size.height; |
|
|
|
|
|
|
|
var height = isPortrait ? size.height : size.width; |
|
|
|
|
|
|
|
return pageNames[width + 'x' + height]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var PDFDocumentProperties = function () { |
|
|
|
var PDFDocumentProperties = function () { |
|
|
|
function PDFDocumentProperties(_ref, overlayManager, eventBus) { |
|
|
|
function PDFDocumentProperties(_ref, overlayManager, eventBus) { |
|
|
@ -65,7 +79,14 @@ var PDFDocumentProperties = function () { |
|
|
|
eventBus.on('pagechanging', function (evt) { |
|
|
|
eventBus.on('pagechanging', function (evt) { |
|
|
|
_this._currentPageNumber = evt.pageNumber; |
|
|
|
_this._currentPageNumber = evt.pageNumber; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
eventBus.on('rotationchanging', function (evt) { |
|
|
|
|
|
|
|
_this._pagesRotation = evt.pagesRotation; |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this._isNonMetricLocale = true; |
|
|
|
|
|
|
|
l10n.getLanguage().then(function (locale) { |
|
|
|
|
|
|
|
_this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_createClass(PDFDocumentProperties, [{ |
|
|
|
_createClass(PDFDocumentProperties, [{ |
|
|
@ -83,7 +104,8 @@ var PDFDocumentProperties = function () { |
|
|
|
}; |
|
|
|
}; |
|
|
|
Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(function () { |
|
|
|
Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(function () { |
|
|
|
var currentPageNumber = _this2._currentPageNumber; |
|
|
|
var currentPageNumber = _this2._currentPageNumber; |
|
|
|
if (_this2.fieldData && currentPageNumber === _this2.fieldData['_currentPageNumber']) { |
|
|
|
var pagesRotation = _this2._pagesRotation; |
|
|
|
|
|
|
|
if (_this2.fieldData && currentPageNumber === _this2.fieldData['_currentPageNumber'] && pagesRotation === _this2.fieldData['_pagesRotation']) { |
|
|
|
_this2._updateUI(); |
|
|
|
_this2._updateUI(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -93,7 +115,7 @@ var PDFDocumentProperties = function () { |
|
|
|
contentDispositionFilename = _ref2.contentDispositionFilename; |
|
|
|
contentDispositionFilename = _ref2.contentDispositionFilename; |
|
|
|
|
|
|
|
|
|
|
|
return Promise.all([info, metadata, contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(_this2.url), _this2._parseFileSize(_this2.maybeFileSize), _this2._parseDate(info.CreationDate), _this2._parseDate(info.ModDate), _this2.pdfDocument.getPage(currentPageNumber).then(function (pdfPage) { |
|
|
|
return Promise.all([info, metadata, contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(_this2.url), _this2._parseFileSize(_this2.maybeFileSize), _this2._parseDate(info.CreationDate), _this2._parseDate(info.ModDate), _this2.pdfDocument.getPage(currentPageNumber).then(function (pdfPage) { |
|
|
|
return _this2._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage)); |
|
|
|
return _this2._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation); |
|
|
|
})]); |
|
|
|
})]); |
|
|
|
}).then(function (_ref3) { |
|
|
|
}).then(function (_ref3) { |
|
|
|
var _ref4 = _slicedToArray(_ref3, 7), |
|
|
|
var _ref4 = _slicedToArray(_ref3, 7), |
|
|
@ -103,7 +125,7 @@ var PDFDocumentProperties = function () { |
|
|
|
fileSize = _ref4[3], |
|
|
|
fileSize = _ref4[3], |
|
|
|
creationDate = _ref4[4], |
|
|
|
creationDate = _ref4[4], |
|
|
|
modDate = _ref4[5], |
|
|
|
modDate = _ref4[5], |
|
|
|
pageSizes = _ref4[6]; |
|
|
|
pageSize = _ref4[6]; |
|
|
|
|
|
|
|
|
|
|
|
freezeFieldData({ |
|
|
|
freezeFieldData({ |
|
|
|
'fileName': fileName, |
|
|
|
'fileName': fileName, |
|
|
@ -118,9 +140,9 @@ var PDFDocumentProperties = function () { |
|
|
|
'producer': info.Producer, |
|
|
|
'producer': info.Producer, |
|
|
|
'version': info.PDFFormatVersion, |
|
|
|
'version': info.PDFFormatVersion, |
|
|
|
'pageCount': _this2.pdfDocument.numPages, |
|
|
|
'pageCount': _this2.pdfDocument.numPages, |
|
|
|
'pageSizeInch': pageSizes.inch, |
|
|
|
'pageSize': pageSize, |
|
|
|
'pageSizeMM': pageSizes.mm, |
|
|
|
'_currentPageNumber': currentPageNumber, |
|
|
|
'_currentPageNumber': currentPageNumber |
|
|
|
'_pagesRotation': pagesRotation |
|
|
|
}); |
|
|
|
}); |
|
|
|
_this2._updateUI(); |
|
|
|
_this2._updateUI(); |
|
|
|
return _this2.pdfDocument.getDownloadInfo(); |
|
|
|
return _this2.pdfDocument.getDownloadInfo(); |
|
|
@ -175,6 +197,7 @@ var PDFDocumentProperties = function () { |
|
|
|
delete this.fieldData; |
|
|
|
delete this.fieldData; |
|
|
|
this._dataAvailableCapability = (0, _pdf.createPromiseCapability)(); |
|
|
|
this._dataAvailableCapability = (0, _pdf.createPromiseCapability)(); |
|
|
|
this._currentPageNumber = 1; |
|
|
|
this._currentPageNumber = 1; |
|
|
|
|
|
|
|
this._pagesRotation = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: '_updateUI', |
|
|
|
key: '_updateUI', |
|
|
@ -216,27 +239,68 @@ var PDFDocumentProperties = function () { |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: '_parsePageSize', |
|
|
|
key: '_parsePageSize', |
|
|
|
value: function _parsePageSize(pageSizeInches) { |
|
|
|
value: function _parsePageSize(pageSizeInches, pagesRotation) { |
|
|
|
|
|
|
|
var _this3 = this; |
|
|
|
|
|
|
|
|
|
|
|
if (!pageSizeInches) { |
|
|
|
if (!pageSizeInches) { |
|
|
|
return Promise.resolve({ |
|
|
|
return Promise.resolve(undefined); |
|
|
|
inch: undefined, |
|
|
|
|
|
|
|
mm: undefined |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
var width = pageSizeInches.width, |
|
|
|
if (pagesRotation % 180 !== 0) { |
|
|
|
height = pageSizeInches.height; |
|
|
|
pageSizeInches = { |
|
|
|
|
|
|
|
width: pageSizeInches.height, |
|
|
|
return Promise.all([this.l10n.get('document_properties_page_size_in_2', { |
|
|
|
height: pageSizeInches.width |
|
|
|
width: (Math.round(width * 100) / 100).toLocaleString(), |
|
|
|
|
|
|
|
height: (Math.round(height * 100) / 100).toLocaleString() |
|
|
|
|
|
|
|
}, '{{width}} × {{height}} in'), this.l10n.get('document_properties_page_size_mm_2', { |
|
|
|
|
|
|
|
width: (Math.round(width * 25.4 * 10) / 10).toLocaleString(), |
|
|
|
|
|
|
|
height: (Math.round(height * 25.4 * 10) / 10).toLocaleString() |
|
|
|
|
|
|
|
}, '{{width}} × {{height}} mm')]).then(function (sizes) { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
inch: sizes[0], |
|
|
|
|
|
|
|
mm: sizes[1] |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches); |
|
|
|
|
|
|
|
var sizeInches = { |
|
|
|
|
|
|
|
width: Math.round(pageSizeInches.width * 100) / 100, |
|
|
|
|
|
|
|
height: Math.round(pageSizeInches.height * 100) / 100 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
var sizeMillimeters = { |
|
|
|
|
|
|
|
width: Math.round(pageSizeInches.width * 25.4 * 10) / 10, |
|
|
|
|
|
|
|
height: Math.round(pageSizeInches.height * 25.4 * 10) / 10 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
var pageName = null; |
|
|
|
|
|
|
|
var name = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES); |
|
|
|
|
|
|
|
if (!name && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) { |
|
|
|
|
|
|
|
var exactMillimeters = { |
|
|
|
|
|
|
|
width: pageSizeInches.width * 25.4, |
|
|
|
|
|
|
|
height: pageSizeInches.height * 25.4 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
var intMillimeters = { |
|
|
|
|
|
|
|
width: Math.round(sizeMillimeters.width), |
|
|
|
|
|
|
|
height: Math.round(sizeMillimeters.height) |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) { |
|
|
|
|
|
|
|
name = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES); |
|
|
|
|
|
|
|
if (name) { |
|
|
|
|
|
|
|
sizeInches = { |
|
|
|
|
|
|
|
width: Math.round(intMillimeters.width / 25.4 * 100) / 100, |
|
|
|
|
|
|
|
height: Math.round(intMillimeters.height / 25.4 * 100) / 100 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
sizeMillimeters = intMillimeters; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (name) { |
|
|
|
|
|
|
|
pageName = this.l10n.get('document_properties_page_size_name_' + name.toLowerCase(), null, name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get('document_properties_page_size_unit_' + (this._isNonMetricLocale ? 'inches' : 'millimeters'), null, this._isNonMetricLocale ? 'in' : 'mm'), pageName, this.l10n.get('document_properties_page_size_orientation_' + (isPortrait ? 'portrait' : 'landscape'), null, isPortrait ? 'portrait' : 'landscape')]).then(function (_ref6) { |
|
|
|
|
|
|
|
var _ref7 = _slicedToArray(_ref6, 4), |
|
|
|
|
|
|
|
_ref7$ = _ref7[0], |
|
|
|
|
|
|
|
width = _ref7$.width, |
|
|
|
|
|
|
|
height = _ref7$.height, |
|
|
|
|
|
|
|
unit = _ref7[1], |
|
|
|
|
|
|
|
name = _ref7[2], |
|
|
|
|
|
|
|
orientation = _ref7[3]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return _this3.l10n.get('document_properties_page_size_dimension_' + (name ? 'name_' : '') + 'string', { |
|
|
|
|
|
|
|
width: width.toLocaleString(), |
|
|
|
|
|
|
|
height: height.toLocaleString(), |
|
|
|
|
|
|
|
unit: unit, |
|
|
|
|
|
|
|
name: name, |
|
|
|
|
|
|
|
orientation: orientation |
|
|
|
|
|
|
|
}, '{{width}} × {{height}} {{unit}} (' + (name ? '{{name}}, ' : '') + '{{orientation}})'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|