mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Now also fetch 'Document Info Dictionary', and expose 'raw' metadata attributes
This commit is contained in:
parent
ab198e89cc
commit
edc1694620
3 changed files with 29 additions and 28 deletions
22
src/core.js
22
src/core.js
|
@ -587,13 +587,15 @@ var PDFDocModel = (function PDFDocModelClosure() {
|
|||
this.mainXRefEntriesOffset);
|
||||
this.xref = xref;
|
||||
this.catalog = new Catalog(xref);
|
||||
if (xref.trailer && xref.trailer.has('ID')) {
|
||||
var fileID = '';
|
||||
var id = xref.fetchIfRef(xref.trailer.get('ID'))[0];
|
||||
id.split('').forEach(function(el) {
|
||||
fileID += Number(el.charCodeAt(0)).toString(16);
|
||||
});
|
||||
this.fileID = fileID;
|
||||
if (xref.trailer) {
|
||||
if (xref.trailer.has('ID')) {
|
||||
var fileID = '';
|
||||
var id = xref.fetchIfRef(xref.trailer.get('ID'))[0];
|
||||
id.split('').forEach(function(el) {
|
||||
fileID += Number(el.charCodeAt(0)).toString(16);
|
||||
});
|
||||
this.fileID = fileID;
|
||||
}
|
||||
}
|
||||
},
|
||||
get numPages() {
|
||||
|
@ -602,6 +604,11 @@ var PDFDocModel = (function PDFDocModelClosure() {
|
|||
// shadow the prototype getter
|
||||
return shadow(this, 'numPages', num);
|
||||
},
|
||||
getDocumentInfo: function pdfDocGetDocumentInfo() {
|
||||
if (this.xref.trailer.has('Info')) {
|
||||
return this.xref.fetch(this.xref.trailer.get('Info'));
|
||||
}
|
||||
},
|
||||
getFingerprint: function pdfDocGetFingerprint() {
|
||||
if (this.fileID) {
|
||||
return this.fileID;
|
||||
|
@ -645,6 +652,7 @@ var PDFDoc = (function PDFDocClosure() {
|
|||
this.stream = stream;
|
||||
this.pdfModel = new PDFDocModel(stream);
|
||||
this.fingerprint = this.pdfModel.getFingerprint();
|
||||
this.info = this.pdfModel.getDocumentInfo();
|
||||
this.catalog = this.pdfModel.catalog;
|
||||
this.objs = new PDFObjects();
|
||||
|
||||
|
|
|
@ -44,25 +44,7 @@ var Metadata = (function MetadataClosure() {
|
|||
for (ii = 0, iLength = entries.length; ii < iLength; ii++) {
|
||||
var entry = entries[ii];
|
||||
var name = entry.nodeName.toLowerCase();
|
||||
var entryName = name.split(':');
|
||||
entryName = (entryName.length > 1) ? entryName[1] : entryName[0];
|
||||
switch (name) {
|
||||
case 'pdf:moddate':
|
||||
case 'xap:createdate':
|
||||
case 'xap:metadatadate':
|
||||
case 'xap:modifydate':
|
||||
this.metadata[entryName] = new Date(entry.textContent.trim());
|
||||
break;
|
||||
|
||||
default:
|
||||
// For almost all entries we just add them to the metadata object
|
||||
if (this.metadata[entryName]) {
|
||||
this.metadata[name] = entry.textContent.trim();
|
||||
} else {
|
||||
this.metadata[entryName] = entry.textContent.trim();
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.metadata[name] = entry.textContent.trim();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue