Skip to content

Commit 1f56d24

Browse files
committed
Adds basic PDF info
1 parent f76adca commit 1f56d24

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
@@ -1277,6 +1277,11 @@ var PDFView = {
12771277
self.documentInfo = info;
12781278
self.metadata = metadata;
12791279

1280+
// Provides some basic debug information
1281+
console.log('PDF ' + pdfDocument.fingerprint + ' [' +
1282+
info.PDFFormatVersion + ' ' + (info.Producer || '-') +
1283+
' / ' + (info.Creator || '-') + ']');
1284+
12801285
var pdfTitle;
12811286
if (metadata) {
12821287
if (metadata.has('dc:title'))

0 commit comments

Comments
 (0)