@ -18,6 +18,11 @@
'use strict' ;
'use strict' ;
/ * *
* @ typedef { Object } PDFDocumentPropertiesOptions
* @ property { string } overlayName - Name / identifier for the overlay
* /
/ * *
/ * *
* @ class
* @ class
* /
* /
@ -59,7 +64,56 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
}
}
PDFDocumentProperties . prototype = {
PDFDocumentProperties . prototype = {
getProperties : function PDFDocumentProperties _getProperties ( ) {
/ * *
* Open the document properties overlay .
* /
open : function PDFDocumentProperties _open ( ) {
Promise . all ( [ OverlayManager . open ( this . overlayName ) ,
this . dataAvailablePromise ] ) . then ( function ( ) {
this . _getProperties ( ) ;
} . bind ( this ) ) ;
} ,
/ * *
* Close the document properties overlay .
* /
close : function PDFDocumentProperties _close ( ) {
OverlayManager . close ( this . overlayName ) ;
} ,
/ * *
* Set the file size of the PDF document . This method is used to
* update the file size in the document properties overlay once it
* is known so we do not have to wait until the entire file is loaded .
*
* @ param { number } fileSize - The file size of the PDF document .
* /
setFileSize : function PDFDocumentProperties _setFileSize ( fileSize ) {
if ( fileSize > 0 ) {
this . rawFileSize = fileSize ;
}
} ,
/ * *
* Set a reference to the PDF document and the URL in order
* to populate the overlay fields with the document properties .
* Note that the overlay will contain no information if this method
* is not called .
*
* @ param { Object } pdfDocument - A reference to the PDF document .
* @ param { string } url - The URL of the document .
* /
setDocumentAndUrl :
function PDFDocumentProperties _setDocumentAndUrl ( pdfDocument , url ) {
this . pdfDocument = pdfDocument ;
this . url = url ;
this . resolveDataAvailable ( ) ;
} ,
/ * *
* @ private
* /
_getProperties : function PDFDocumentProperties _getProperties ( ) {
if ( ! OverlayManager . active ) {
if ( ! OverlayManager . active ) {
// If the dialog was closed before dataAvailablePromise was resolved,
// If the dialog was closed before dataAvailablePromise was resolved,
// don't bother updating the properties.
// don't bother updating the properties.
@ -71,7 +125,7 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
return ;
return ;
}
}
this . setFileSize ( data . length ) ;
this . setFileSize ( data . length ) ;
this . updateUI ( this . fileSizeField , this . parseFileSize ( ) ) ;
this . _ updateUI( this . fileSizeField , this . _ parseFileSize( ) ) ;
} . bind ( this ) ) ;
} . bind ( this ) ) ;
// Get the document properties.
// Get the document properties.
@ -79,15 +133,15 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
var fields = [
var fields = [
{ field : this . fileNameField ,
{ field : this . fileNameField ,
content : getPDFFileNameFromURL ( this . url ) } ,
content : getPDFFileNameFromURL ( this . url ) } ,
{ field : this . fileSizeField , content : this . parseFileSize ( ) } ,
{ field : this . fileSizeField , content : this . _ parseFileSize( ) } ,
{ field : this . titleField , content : data . info . Title } ,
{ field : this . titleField , content : data . info . Title } ,
{ field : this . authorField , content : data . info . Author } ,
{ field : this . authorField , content : data . info . Author } ,
{ field : this . subjectField , content : data . info . Subject } ,
{ field : this . subjectField , content : data . info . Subject } ,
{ field : this . keywordsField , content : data . info . Keywords } ,
{ field : this . keywordsField , content : data . info . Keywords } ,
{ field : this . creationDateField ,
{ field : this . creationDateField ,
content : this . parseDate ( data . info . CreationDate ) } ,
content : this . _ parseDate( data . info . CreationDate ) } ,
{ field : this . modificationDateField ,
{ field : this . modificationDateField ,
content : this . parseDate ( data . info . ModDate ) } ,
content : this . _ parseDate( data . info . ModDate ) } ,
{ field : this . creatorField , content : data . info . Creator } ,
{ field : this . creatorField , content : data . info . Creator } ,
{ field : this . producerField , content : data . info . Producer } ,
{ field : this . producerField , content : data . info . Producer } ,
{ field : this . versionField , content : data . info . PDFFormatVersion } ,
{ field : this . versionField , content : data . info . PDFFormatVersion } ,
@ -97,24 +151,24 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
// Show the properties in the dialog.
// Show the properties in the dialog.
for ( var item in fields ) {
for ( var item in fields ) {
var element = fields [ item ] ;
var element = fields [ item ] ;
this . updateUI ( element . field , element . content ) ;
this . _ updateUI( element . field , element . content ) ;
}
}
} . bind ( this ) ) ;
} . bind ( this ) ) ;
} ,
} ,
updateUI : function PDFDocumentProperties _updateUI ( field , content ) {
/ * *
* @ private
* /
_updateUI : function PDFDocumentProperties _updateUI ( field , content ) {
if ( field && content !== undefined && content !== '' ) {
if ( field && content !== undefined && content !== '' ) {
field . textContent = content ;
field . textContent = content ;
}
}
} ,
} ,
setFileSize : function PDFDocumentProperties _setFileSize ( fileSize ) {
/ * *
if ( fileSize > 0 ) {
* @ private
this . rawFileSize = fileSize ;
* /
}
_parseFileSize : function PDFDocumentProperties _parseFileSize ( ) {
} ,
parseFileSize : function PDFDocumentProperties _parseFileSize ( ) {
var fileSize = this . rawFileSize , kb = fileSize / 1024 ;
var fileSize = this . rawFileSize , kb = fileSize / 1024 ;
if ( ! kb ) {
if ( ! kb ) {
return ;
return ;
@ -131,18 +185,10 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
}
}
} ,
} ,
open : function PDFDocumentProperties _open ( ) {
/ * *
Promise . all ( [ OverlayManager . open ( this . overlayName ) ,
* @ private
this . dataAvailablePromise ] ) . then ( function ( ) {
* /
this . getProperties ( ) ;
_parseDate : function PDFDocumentProperties _parseDate ( inputDate ) {
} . 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
// This is implemented according to the PDF specification, but note that
// Adobe Reader doesn't handle changing the date to universal time
// Adobe Reader doesn't handle changing the date to universal time
// and doesn't use the user's time zone (they're effectively ignoring
// and doesn't use the user's time zone (they're effectively ignoring