|
@@ -39,12 +39,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
var DEFAULT_FIELD_CONTENT = '-';
|
|
|
|
|
|
var PDFDocumentProperties = function () {
|
|
|
- function PDFDocumentProperties(_ref, overlayManager) {
|
|
|
+ function PDFDocumentProperties(_ref, overlayManager, eventBus) {
|
|
|
var overlayName = _ref.overlayName,
|
|
|
fields = _ref.fields,
|
|
|
container = _ref.container,
|
|
|
closeButton = _ref.closeButton;
|
|
|
- var l10n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ui_utils.NullL10n;
|
|
|
+
|
|
|
+ var _this = this;
|
|
|
+
|
|
|
+ var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
|
|
|
|
|
|
_classCallCheck(this, PDFDocumentProperties);
|
|
|
|
|
@@ -58,15 +61,20 @@ var PDFDocumentProperties = function () {
|
|
|
closeButton.addEventListener('click', this.close.bind(this));
|
|
|
}
|
|
|
this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
|
|
|
+ if (eventBus) {
|
|
|
+ eventBus.on('pagechanging', function (evt) {
|
|
|
+ _this._currentPageNumber = evt.pageNumber;
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
_createClass(PDFDocumentProperties, [{
|
|
|
key: 'open',
|
|
|
value: function open() {
|
|
|
- var _this = this;
|
|
|
+ var _this2 = this;
|
|
|
|
|
|
var freezeFieldData = function freezeFieldData(data) {
|
|
|
- Object.defineProperty(_this, 'fieldData', {
|
|
|
+ Object.defineProperty(_this2, 'fieldData', {
|
|
|
value: Object.freeze(data),
|
|
|
writable: false,
|
|
|
enumerable: true,
|
|
@@ -74,17 +82,18 @@ var PDFDocumentProperties = function () {
|
|
|
});
|
|
|
};
|
|
|
Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(function () {
|
|
|
- if (_this.fieldData) {
|
|
|
- _this._updateUI();
|
|
|
+ var currentPageNumber = _this2._currentPageNumber;
|
|
|
+ if (_this2.fieldData && currentPageNumber === _this2.fieldData['_currentPageNumber']) {
|
|
|
+ _this2._updateUI();
|
|
|
return;
|
|
|
}
|
|
|
- _this.pdfDocument.getMetadata().then(function (_ref2) {
|
|
|
+ _this2.pdfDocument.getMetadata().then(function (_ref2) {
|
|
|
var info = _ref2.info,
|
|
|
metadata = _ref2.metadata,
|
|
|
contentDispositionFilename = _ref2.contentDispositionFilename;
|
|
|
|
|
|
- return Promise.all([info, metadata, contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(_this.url), _this._parseFileSize(_this.maybeFileSize), _this._parseDate(info.CreationDate), _this._parseDate(info.ModDate), _this.pdfDocument.getPageSizeInches().then(function (pageSizeInches) {
|
|
|
- return _this._parsePageSize(pageSizeInches);
|
|
|
+ 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(pdfPage.pageSizeInches);
|
|
|
})]);
|
|
|
}).then(function (_ref3) {
|
|
|
var _ref4 = _slicedToArray(_ref3, 7),
|
|
@@ -94,7 +103,7 @@ var PDFDocumentProperties = function () {
|
|
|
fileSize = _ref4[3],
|
|
|
creationDate = _ref4[4],
|
|
|
modDate = _ref4[5],
|
|
|
- pageSize = _ref4[6];
|
|
|
+ pageSizes = _ref4[6];
|
|
|
|
|
|
freezeFieldData({
|
|
|
'fileName': fileName,
|
|
@@ -108,21 +117,26 @@ var PDFDocumentProperties = function () {
|
|
|
'creator': info.Creator,
|
|
|
'producer': info.Producer,
|
|
|
'version': info.PDFFormatVersion,
|
|
|
- 'pageCount': _this.pdfDocument.numPages,
|
|
|
- 'pageSizeInch': pageSize.inch,
|
|
|
- 'pageSizeMM': pageSize.mm
|
|
|
+ 'pageCount': _this2.pdfDocument.numPages,
|
|
|
+ 'pageSizeInch': pageSizes.inch,
|
|
|
+ 'pageSizeMM': pageSizes.mm,
|
|
|
+ '_currentPageNumber': currentPageNumber
|
|
|
});
|
|
|
- _this._updateUI();
|
|
|
- return _this.pdfDocument.getDownloadInfo();
|
|
|
+ _this2._updateUI();
|
|
|
+ return _this2.pdfDocument.getDownloadInfo();
|
|
|
}).then(function (_ref5) {
|
|
|
var length = _ref5.length;
|
|
|
|
|
|
- return _this._parseFileSize(length);
|
|
|
+ _this2.maybeFileSize = length;
|
|
|
+ return _this2._parseFileSize(length);
|
|
|
}).then(function (fileSize) {
|
|
|
- var data = (0, _ui_utils.cloneObj)(_this.fieldData);
|
|
|
+ if (fileSize === _this2.fieldData['fileSize']) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var data = (0, _ui_utils.cloneObj)(_this2.fieldData);
|
|
|
data['fileSize'] = fileSize;
|
|
|
freezeFieldData(data);
|
|
|
- _this._updateUI();
|
|
|
+ _this2._updateUI();
|
|
|
});
|
|
|
});
|
|
|
}
|
|
@@ -148,7 +162,7 @@ var PDFDocumentProperties = function () {
|
|
|
}, {
|
|
|
key: 'setFileSize',
|
|
|
value: function setFileSize(fileSize) {
|
|
|
- if (typeof fileSize === 'number' && fileSize > 0) {
|
|
|
+ if (Number.isInteger(fileSize) && fileSize > 0) {
|
|
|
this.maybeFileSize = fileSize;
|
|
|
}
|
|
|
}
|
|
@@ -160,6 +174,7 @@ var PDFDocumentProperties = function () {
|
|
|
this.maybeFileSize = 0;
|
|
|
delete this.fieldData;
|
|
|
this._dataAvailableCapability = (0, _pdf.createPromiseCapability)();
|
|
|
+ this._currentPageNumber = 1;
|
|
|
}
|
|
|
}, {
|
|
|
key: '_updateUI',
|
|
@@ -203,23 +218,25 @@ var PDFDocumentProperties = function () {
|
|
|
key: '_parsePageSize',
|
|
|
value: function _parsePageSize(pageSizeInches) {
|
|
|
if (!pageSizeInches) {
|
|
|
- return Promise.resolve([undefined, undefined]);
|
|
|
- }
|
|
|
- var sizes_two_units = {
|
|
|
- 'width_in': Math.round(pageSizeInches.width * 100) / 100,
|
|
|
- 'height_in': Math.round(pageSizeInches.height * 100) / 100,
|
|
|
- '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(function (_ref6) {
|
|
|
- var _ref7 = _slicedToArray(_ref6, 2),
|
|
|
- parsedPageSizeInches = _ref7[0],
|
|
|
- parsedPageSizeMM = _ref7[1];
|
|
|
-
|
|
|
return Promise.resolve({
|
|
|
- inch: parsedPageSizeInches,
|
|
|
- mm: parsedPageSizeMM
|
|
|
+ inch: undefined,
|
|
|
+ mm: undefined
|
|
|
});
|
|
|
+ }
|
|
|
+ var width = pageSizeInches.width,
|
|
|
+ height = pageSizeInches.height;
|
|
|
+
|
|
|
+ return Promise.all([this.l10n.get('document_properties_page_size_in_2', {
|
|
|
+ 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]
|
|
|
+ };
|
|
|
});
|
|
|
}
|
|
|
}, {
|