|
|
@ -18,42 +18,33 @@ |
|
|
|
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
var PDFDocumentProperties = { |
|
|
|
/** |
|
|
|
overlayName: null, |
|
|
|
* @class |
|
|
|
rawFileSize: 0, |
|
|
|
*/ |
|
|
|
|
|
|
|
var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() { |
|
|
|
// Document property fields (in the viewer).
|
|
|
|
/** |
|
|
|
fileNameField: null, |
|
|
|
* @constructs PDFDocumentProperties |
|
|
|
fileSizeField: null, |
|
|
|
* @param {PDFDocumentPropertiesOptions} options |
|
|
|
titleField: null, |
|
|
|
*/ |
|
|
|
authorField: null, |
|
|
|
function PDFDocumentProperties(options) { |
|
|
|
subjectField: null, |
|
|
|
this.rawFileSize = 0; |
|
|
|
keywordsField: null, |
|
|
|
this.url = null; |
|
|
|
creationDateField: null, |
|
|
|
this.pdfDocument = null; |
|
|
|
modificationDateField: null, |
|
|
|
|
|
|
|
creatorField: null, |
|
|
|
|
|
|
|
producerField: null, |
|
|
|
|
|
|
|
versionField: null, |
|
|
|
|
|
|
|
pageCountField: null, |
|
|
|
|
|
|
|
url: null, |
|
|
|
|
|
|
|
pdfDocument: null, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialize: function documentPropertiesInitialize(options) { |
|
|
|
|
|
|
|
this.overlayName = options.overlayName; |
|
|
|
this.overlayName = options.overlayName; |
|
|
|
|
|
|
|
|
|
|
|
// Set the document property fields.
|
|
|
|
// Set the document property fields.
|
|
|
|
this.fileNameField = options.fileNameField; |
|
|
|
this.fileNameField = options.fileNameField || null; |
|
|
|
this.fileSizeField = options.fileSizeField; |
|
|
|
this.fileSizeField = options.fileSizeField || null; |
|
|
|
this.titleField = options.titleField; |
|
|
|
this.titleField = options.titleField || null; |
|
|
|
this.authorField = options.authorField; |
|
|
|
this.authorField = options.authorField || null; |
|
|
|
this.subjectField = options.subjectField; |
|
|
|
this.subjectField = options.subjectField || null; |
|
|
|
this.keywordsField = options.keywordsField; |
|
|
|
this.keywordsField = options.keywordsField || null; |
|
|
|
this.creationDateField = options.creationDateField; |
|
|
|
this.creationDateField = options.creationDateField || null; |
|
|
|
this.modificationDateField = options.modificationDateField; |
|
|
|
this.modificationDateField = options.modificationDateField || null; |
|
|
|
this.creatorField = options.creatorField; |
|
|
|
this.creatorField = options.creatorField || null; |
|
|
|
this.producerField = options.producerField; |
|
|
|
this.producerField = options.producerField || null; |
|
|
|
this.versionField = options.versionField; |
|
|
|
this.versionField = options.versionField || null; |
|
|
|
this.pageCountField = options.pageCountField; |
|
|
|
this.pageCountField = options.pageCountField || null; |
|
|
|
|
|
|
|
|
|
|
|
// Bind the event listener for the Close button.
|
|
|
|
// Bind the event listener for the Close button.
|
|
|
|
if (options.closeButton) { |
|
|
|
if (options.closeButton) { |
|
|
@ -65,135 +56,139 @@ var PDFDocumentProperties = { |
|
|
|
}.bind(this)); |
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
|
|
|
|
OverlayManager.register(this.overlayName, this.close.bind(this)); |
|
|
|
OverlayManager.register(this.overlayName, this.close.bind(this)); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getProperties: function documentPropertiesGetProperties() { |
|
|
|
PDFDocumentProperties.prototype = { |
|
|
|
if (!OverlayManager.active) { |
|
|
|
getProperties: function PDFDocumentProperties_getProperties() { |
|
|
|
// If the dialog was closed before dataAvailablePromise was resolved,
|
|
|
|
if (!OverlayManager.active) { |
|
|
|
// don't bother updating the properties.
|
|
|
|
// If the dialog was closed before dataAvailablePromise was resolved,
|
|
|
|
return; |
|
|
|
// don't bother updating the properties.
|
|
|
|
} |
|
|
|
|
|
|
|
// Get the file size (if it hasn't already been set).
|
|
|
|
|
|
|
|
this.pdfDocument.getDownloadInfo().then(function(data) { |
|
|
|
|
|
|
|
if (data.length === this.rawFileSize) { |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this.setFileSize(data.length); |
|
|
|
// Get the file size (if it hasn't already been set).
|
|
|
|
this.updateUI(this.fileSizeField, this.parseFileSize()); |
|
|
|
this.pdfDocument.getDownloadInfo().then(function(data) { |
|
|
|
}.bind(this)); |
|
|
|
if (data.length === this.rawFileSize) { |
|
|
|
|
|
|
|
return; |
|
|
|
// Get the document properties.
|
|
|
|
} |
|
|
|
this.pdfDocument.getMetadata().then(function(data) { |
|
|
|
this.setFileSize(data.length); |
|
|
|
var fields = [ |
|
|
|
this.updateUI(this.fileSizeField, this.parseFileSize()); |
|
|
|
{ field: this.fileNameField, |
|
|
|
}.bind(this)); |
|
|
|
content: getPDFFileNameFromURL(this.url) }, |
|
|
|
|
|
|
|
{ field: this.fileSizeField, content: this.parseFileSize() }, |
|
|
|
// Get the document properties.
|
|
|
|
{ field: this.titleField, content: data.info.Title }, |
|
|
|
this.pdfDocument.getMetadata().then(function(data) { |
|
|
|
{ field: this.authorField, content: data.info.Author }, |
|
|
|
var fields = [ |
|
|
|
{ field: this.subjectField, content: data.info.Subject }, |
|
|
|
{ field: this.fileNameField, |
|
|
|
{ field: this.keywordsField, content: data.info.Keywords }, |
|
|
|
content: getPDFFileNameFromURL(this.url) }, |
|
|
|
{ field: this.creationDateField, |
|
|
|
{ field: this.fileSizeField, content: this.parseFileSize() }, |
|
|
|
content: this.parseDate(data.info.CreationDate) }, |
|
|
|
{ field: this.titleField, content: data.info.Title }, |
|
|
|
{ field: this.modificationDateField, |
|
|
|
{ field: this.authorField, content: data.info.Author }, |
|
|
|
content: this.parseDate(data.info.ModDate) }, |
|
|
|
{ field: this.subjectField, content: data.info.Subject }, |
|
|
|
{ field: this.creatorField, content: data.info.Creator }, |
|
|
|
{ field: this.keywordsField, content: data.info.Keywords }, |
|
|
|
{ field: this.producerField, content: data.info.Producer }, |
|
|
|
{ field: this.creationDateField, |
|
|
|
{ field: this.versionField, content: data.info.PDFFormatVersion }, |
|
|
|
content: this.parseDate(data.info.CreationDate) }, |
|
|
|
{ field: this.pageCountField, content: this.pdfDocument.numPages } |
|
|
|
{ field: this.modificationDateField, |
|
|
|
]; |
|
|
|
content: this.parseDate(data.info.ModDate) }, |
|
|
|
|
|
|
|
{ field: this.creatorField, content: data.info.Creator }, |
|
|
|
// Show the properties in the dialog.
|
|
|
|
{ field: this.producerField, content: data.info.Producer }, |
|
|
|
for (var item in fields) { |
|
|
|
{ field: this.versionField, content: data.info.PDFFormatVersion }, |
|
|
|
var element = fields[item]; |
|
|
|
{ field: this.pageCountField, content: this.pdfDocument.numPages } |
|
|
|
this.updateUI(element.field, element.content); |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Show the properties in the dialog.
|
|
|
|
|
|
|
|
for (var item in fields) { |
|
|
|
|
|
|
|
var element = fields[item]; |
|
|
|
|
|
|
|
this.updateUI(element.field, element.content); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateUI: function PDFDocumentProperties_updateUI(field, content) { |
|
|
|
|
|
|
|
if (field && content !== undefined && content !== '') { |
|
|
|
|
|
|
|
field.textContent = content; |
|
|
|
} |
|
|
|
} |
|
|
|
}.bind(this)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateUI: function documentPropertiesUpdateUI(field, content) { |
|
|
|
setFileSize: function PDFDocumentProperties_setFileSize(fileSize) { |
|
|
|
if (field && content !== undefined && content !== '') { |
|
|
|
if (fileSize > 0) { |
|
|
|
field.textContent = content; |
|
|
|
this.rawFileSize = fileSize; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
setFileSize: function documentPropertiesSetFileSize(fileSize) { |
|
|
|
parseFileSize: function PDFDocumentProperties_parseFileSize() { |
|
|
|
if (fileSize > 0) { |
|
|
|
var fileSize = this.rawFileSize, kb = fileSize / 1024; |
|
|
|
this.rawFileSize = fileSize; |
|
|
|
if (!kb) { |
|
|
|
} |
|
|
|
return; |
|
|
|
}, |
|
|
|
} else if (kb < 1024) { |
|
|
|
|
|
|
|
return mozL10n.get('document_properties_kb', { |
|
|
|
parseFileSize: function documentPropertiesParseFileSize() { |
|
|
|
size_kb: (+kb.toPrecision(3)).toLocaleString(), |
|
|
|
var fileSize = this.rawFileSize, kb = fileSize / 1024; |
|
|
|
size_b: fileSize.toLocaleString() |
|
|
|
if (!kb) { |
|
|
|
}, '{{size_kb}} KB ({{size_b}} bytes)'); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
} else if (kb < 1024) { |
|
|
|
return mozL10n.get('document_properties_mb', { |
|
|
|
return mozL10n.get('document_properties_kb', { |
|
|
|
size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(), |
|
|
|
size_kb: (+kb.toPrecision(3)).toLocaleString(), |
|
|
|
size_b: fileSize.toLocaleString() |
|
|
|
size_b: fileSize.toLocaleString() |
|
|
|
}, '{{size_mb}} MB ({{size_b}} bytes)'); |
|
|
|
}, '{{size_kb}} KB ({{size_b}} bytes)'); |
|
|
|
} |
|
|
|
} else { |
|
|
|
}, |
|
|
|
return mozL10n.get('document_properties_mb', { |
|
|
|
|
|
|
|
size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(), |
|
|
|
open: function PDFDocumentProperties_open() { |
|
|
|
size_b: fileSize.toLocaleString() |
|
|
|
Promise.all([OverlayManager.open(this.overlayName), |
|
|
|
}, '{{size_mb}} MB ({{size_b}} bytes)'); |
|
|
|
this.dataAvailablePromise]).then(function () { |
|
|
|
} |
|
|
|
this.getProperties(); |
|
|
|
}, |
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
close: function PDFDocumentProperties_close() { |
|
|
|
|
|
|
|
OverlayManager.close(this.overlayName); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parseDate: function PDFDocumentProperties_parseDate(inputDate) { |
|
|
|
|
|
|
|
// This is implemented according to the PDF specification, but note that
|
|
|
|
|
|
|
|
// Adobe Reader doesn't handle changing the date to universal time
|
|
|
|
|
|
|
|
// and doesn't use the user's time zone (they're effectively ignoring
|
|
|
|
|
|
|
|
// the HH' and mm' parts of the date string).
|
|
|
|
|
|
|
|
var dateToParse = inputDate; |
|
|
|
|
|
|
|
if (dateToParse === undefined) { |
|
|
|
|
|
|
|
return ''; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open: function documentPropertiesOpen() { |
|
|
|
// Remove the D: prefix if it is available.
|
|
|
|
Promise.all([OverlayManager.open(this.overlayName), |
|
|
|
if (dateToParse.substring(0,2) === 'D:') { |
|
|
|
this.dataAvailablePromise]).then(function () { |
|
|
|
dateToParse = dateToParse.substring(2); |
|
|
|
this.getProperties(); |
|
|
|
} |
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
close: function documentPropertiesClose() { |
|
|
|
|
|
|
|
OverlayManager.close(this.overlayName); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parseDate: function documentPropertiesParseDate(inputDate) { |
|
|
|
|
|
|
|
// This is implemented according to the PDF specification, but note that
|
|
|
|
|
|
|
|
// Adobe Reader doesn't handle changing the date to universal time
|
|
|
|
|
|
|
|
// and doesn't use the user's time zone (they're effectively ignoring
|
|
|
|
|
|
|
|
// the HH' and mm' parts of the date string).
|
|
|
|
|
|
|
|
var dateToParse = inputDate; |
|
|
|
|
|
|
|
if (dateToParse === undefined) { |
|
|
|
|
|
|
|
return ''; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the D: prefix if it is available.
|
|
|
|
// Get all elements from the PDF date string.
|
|
|
|
if (dateToParse.substring(0,2) === 'D:') { |
|
|
|
// JavaScript's Date object expects the month to be between
|
|
|
|
dateToParse = dateToParse.substring(2); |
|
|
|
// 0 and 11 instead of 1 and 12, so we're correcting for this.
|
|
|
|
} |
|
|
|
var year = parseInt(dateToParse.substring(0,4), 10); |
|
|
|
|
|
|
|
var month = parseInt(dateToParse.substring(4,6), 10) - 1; |
|
|
|
|
|
|
|
var day = parseInt(dateToParse.substring(6,8), 10); |
|
|
|
|
|
|
|
var hours = parseInt(dateToParse.substring(8,10), 10); |
|
|
|
|
|
|
|
var minutes = parseInt(dateToParse.substring(10,12), 10); |
|
|
|
|
|
|
|
var seconds = parseInt(dateToParse.substring(12,14), 10); |
|
|
|
|
|
|
|
var utRel = dateToParse.substring(14,15); |
|
|
|
|
|
|
|
var offsetHours = parseInt(dateToParse.substring(15,17), 10); |
|
|
|
|
|
|
|
var offsetMinutes = parseInt(dateToParse.substring(18,20), 10); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// As per spec, utRel = 'Z' means equal to universal time.
|
|
|
|
|
|
|
|
// The other cases ('-' and '+') have to be handled here.
|
|
|
|
|
|
|
|
if (utRel === '-') { |
|
|
|
|
|
|
|
hours += offsetHours; |
|
|
|
|
|
|
|
minutes += offsetMinutes; |
|
|
|
|
|
|
|
} else if (utRel === '+') { |
|
|
|
|
|
|
|
hours -= offsetHours; |
|
|
|
|
|
|
|
minutes -= offsetMinutes; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get all elements from the PDF date string.
|
|
|
|
// Return the new date format from the user's locale.
|
|
|
|
// JavaScript's Date object expects the month to be between
|
|
|
|
var date = new Date(Date.UTC(year, month, day, hours, minutes, seconds)); |
|
|
|
// 0 and 11 instead of 1 and 12, so we're correcting for this.
|
|
|
|
var dateString = date.toLocaleDateString(); |
|
|
|
var year = parseInt(dateToParse.substring(0,4), 10); |
|
|
|
var timeString = date.toLocaleTimeString(); |
|
|
|
var month = parseInt(dateToParse.substring(4,6), 10) - 1; |
|
|
|
return mozL10n.get('document_properties_date_string', |
|
|
|
var day = parseInt(dateToParse.substring(6,8), 10); |
|
|
|
{date: dateString, time: timeString}, |
|
|
|
var hours = parseInt(dateToParse.substring(8,10), 10); |
|
|
|
'{{date}}, {{time}}'); |
|
|
|
var minutes = parseInt(dateToParse.substring(10,12), 10); |
|
|
|
|
|
|
|
var seconds = parseInt(dateToParse.substring(12,14), 10); |
|
|
|
|
|
|
|
var utRel = dateToParse.substring(14,15); |
|
|
|
|
|
|
|
var offsetHours = parseInt(dateToParse.substring(15,17), 10); |
|
|
|
|
|
|
|
var offsetMinutes = parseInt(dateToParse.substring(18,20), 10); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// As per spec, utRel = 'Z' means equal to universal time.
|
|
|
|
|
|
|
|
// The other cases ('-' and '+') have to be handled here.
|
|
|
|
|
|
|
|
if (utRel === '-') { |
|
|
|
|
|
|
|
hours += offsetHours; |
|
|
|
|
|
|
|
minutes += offsetMinutes; |
|
|
|
|
|
|
|
} else if (utRel === '+') { |
|
|
|
|
|
|
|
hours -= offsetHours; |
|
|
|
|
|
|
|
minutes -= offsetMinutes; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Return the new date format from the user's locale.
|
|
|
|
return PDFDocumentProperties; |
|
|
|
var date = new Date(Date.UTC(year, month, day, hours, minutes, seconds)); |
|
|
|
})(); |
|
|
|
var dateString = date.toLocaleDateString(); |
|
|
|
|
|
|
|
var timeString = date.toLocaleTimeString(); |
|
|
|
|
|
|
|
return mozL10n.get('document_properties_date_string', |
|
|
|
|
|
|
|
{date: dateString, time: timeString}, |
|
|
|
|
|
|
|
'{{date}}, {{time}}'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|