Browse Source

Extract correct PDF format version from the catalog

The 'Version' field of the most recent document catalog, if present, is
intended to supersede the value in the file prologue.

This is significant for incrementally-built PDF documents and generators that
emit a low version in the prologue and later apply a format version based on
PDF features used, such as Apple's CoreGraphics/Quartz PDF backend.

Fixes the internal version variable, as well as the PDFFormatVersion reported
by the API and consumed by viewers.
Mike Corbin 10 years ago
parent
commit
4c9b65f0e1
  1. 6
      src/core/core.js
  2. BIN
      test/pdfs/basicapi.pdf
  3. 1
      test/unit/api_spec.js

6
src/core/core.js

@ -343,6 +343,10 @@ var PDFDocument = (function PDFDocumentClosure() {
PDFDocument.prototype = { PDFDocument.prototype = {
parse: function PDFDocument_parse(recoveryMode) { parse: function PDFDocument_parse(recoveryMode) {
this.setup(recoveryMode); this.setup(recoveryMode);
var version = this.catalog.catDict.get('Version');
if (isName(version)) {
this.pdfFormatVersion = version.name;
}
try { try {
// checking if AcroForm is present // checking if AcroForm is present
this.acroForm = this.catalog.catDict.get('AcroForm'); this.acroForm = this.catalog.catDict.get('AcroForm');
@ -444,8 +448,10 @@ var PDFDocument = (function PDFDocumentClosure() {
} }
version += String.fromCharCode(ch); version += String.fromCharCode(ch);
} }
if (!this.pdfFormatVersion) {
// removing "%PDF-"-prefix // removing "%PDF-"-prefix
this.pdfFormatVersion = version.substring(5); this.pdfFormatVersion = version.substring(5);
}
return; return;
} }
// May not be a PDF file, continue anyway. // May not be a PDF file, continue anyway.

BIN
test/pdfs/basicapi.pdf

Binary file not shown.

1
test/unit/api_spec.js

@ -156,6 +156,7 @@ describe('api', function() {
var promise = doc.getMetadata(); var promise = doc.getMetadata();
waitsForPromiseResolved(promise, function(metadata) { waitsForPromiseResolved(promise, function(metadata) {
expect(metadata.info['Title']).toEqual('Basic API Test'); expect(metadata.info['Title']).toEqual('Basic API Test');
expect(metadata.info['PDFFormatVersion']).toEqual('1.7');
expect(metadata.metadata.get('dc:title')).toEqual('Basic API Test'); expect(metadata.metadata.get('dc:title')).toEqual('Basic API Test');
}); });
}); });

Loading…
Cancel
Save