[Pkg-javascript-commits] [pdf.js] 54/106: Extract correct PDF format version from the catalog

David Prévot taffit at moszumanska.debian.org
Sat Jun 20 21:34:11 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 4c9b65f0e13fd290c326b38cb97436fa50b930f5
Author: Mike Corbin <mcorb at appshuttle.com>
Date:   Mon May 25 03:45:20 2015 +0100

    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.
---
 src/core/core.js       |  10 ++++++++--
 test/pdfs/basicapi.pdf | Bin 105779 -> 105779 bytes
 test/unit/api_spec.js  |   1 +
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/core/core.js b/src/core/core.js
index c81f5b7..2eb8fd5 100644
--- a/src/core/core.js
+++ b/src/core/core.js
@@ -343,6 +343,10 @@ var PDFDocument = (function PDFDocumentClosure() {
   PDFDocument.prototype = {
     parse: function PDFDocument_parse(recoveryMode) {
       this.setup(recoveryMode);
+      var version = this.catalog.catDict.get('Version');
+      if (isName(version)) {
+        this.pdfFormatVersion = version.name;
+      }
       try {
         // checking if AcroForm is present
         this.acroForm = this.catalog.catDict.get('AcroForm');
@@ -444,8 +448,10 @@ var PDFDocument = (function PDFDocumentClosure() {
           }
           version += String.fromCharCode(ch);
         }
-        // removing "%PDF-"-prefix
-        this.pdfFormatVersion = version.substring(5);
+        if (!this.pdfFormatVersion) {
+          // removing "%PDF-"-prefix
+          this.pdfFormatVersion = version.substring(5);
+        }
         return;
       }
       // May not be a PDF file, continue anyway.
diff --git a/test/pdfs/basicapi.pdf b/test/pdfs/basicapi.pdf
index 31ffcfe..2f16483 100644
Binary files a/test/pdfs/basicapi.pdf and b/test/pdfs/basicapi.pdf differ
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 75905f7..2d5d17b 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -156,6 +156,7 @@ describe('api', function() {
       var promise = doc.getMetadata();
       waitsForPromiseResolved(promise, function(metadata) {
         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');
       });
     });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list