Skip to content

Commit abaed05

Browse files
committed
Merge pull request mozilla#2346 from yurydelendik/info
Adds basic PDF info
2 parents 00fad28 + 1f56d24 commit abaed05

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/core.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,17 @@ var PDFDocument = (function PDFDocumentClosure() {
495495
if (find(stream, '%PDF-', 1024)) {
496496
// Found the header, trim off any garbage before it.
497497
stream.moveStart();
498+
// Reading file format version
499+
var MAX_VERSION_LENGTH = 12;
500+
var version = '', ch;
501+
while ((ch = stream.getChar()) > ' ') {
502+
if (version.length >= MAX_VERSION_LENGTH) {
503+
break;
504+
}
505+
version += ch;
506+
}
507+
// removing "%PDF-"-prefix
508+
this.pdfFormatVersion = version.substring(5);
498509
return;
499510
}
500511
// May not be a PDF file, continue anyway.
@@ -519,7 +530,9 @@ var PDFDocument = (function PDFDocumentClosure() {
519530
if (this.xref.trailer.has('Info')) {
520531
var infoDict = this.xref.trailer.get('Info');
521532

522-
docInfo = {};
533+
docInfo = {
534+
PDFFormatVersion: this.pdfFormatVersion
535+
};
523536
var validEntries = DocumentInfoValidators.entries;
524537
// Only fill the document info with valid entries from the spec.
525538
for (var key in validEntries) {

web/viewer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,11 @@ var PDFView = {
12881288
self.documentInfo = info;
12891289
self.metadata = metadata;
12901290

1291+
// Provides some basic debug information
1292+
console.log('PDF ' + pdfDocument.fingerprint + ' [' +
1293+
info.PDFFormatVersion + ' ' + (info.Producer || '-') +
1294+
' / ' + (info.Creator || '-') + ']');
1295+
12911296
var pdfTitle;
12921297
if (metadata) {
12931298
if (metadata.has('dc:title'))

0 commit comments

Comments
 (0)