From 928b89382e6b2350e740c481e7d6f44e8405e43c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 24 Jul 2018 15:02:14 +0200 Subject: [PATCH] [api-minor] Add an `IsLinearized` property to the `PDFDocument.documentInfo` getter, to allow accessing the linearization status through the API (via `PDFDocumentProxy.getMetadata`) There was a (somewhat) recent question on IRC about accessing the linearization status of a PDF document, and this patch contains a simple way to expose that through already existing API methods. Please note that during setup/parsing in `PDFDocument` the linearization data is already being fetched and parsed, provided of course that it exists. Hence this patch will *not* cause any additional data to be loaded. --- src/core/document.js | 5 +++-- test/unit/api_spec.js | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/core/document.js b/src/core/document.js index dfc46df98..df243e1bb 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -535,12 +535,13 @@ var PDFDocument = (function PDFDocumentClosure() { return shadow(this, 'numPages', num); }, get documentInfo() { - var docInfo = { + const docInfo = { PDFFormatVersion: this.pdfFormatVersion, + IsLinearized: !!this.linearization, IsAcroFormPresent: !!this.acroForm, IsXFAPresent: !!this.xfa, }; - var infoDict; + let infoDict; try { infoDict = this.xref.trailer.get('Info'); } catch (err) { diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 2f79d4cc3..1a643e0ae 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -28,6 +28,7 @@ import { } from '../../src/display/api'; import { GlobalWorkerOptions } from '../../src/display/worker_options'; import isNodeJS from '../../src/shared/is_node'; +import { Metadata } from '../../src/display/metadata'; describe('api', function() { let basicApiFileName = 'basicapi.pdf'; @@ -802,11 +803,18 @@ describe('api', function() { }); it('gets metadata', function(done) { var promise = doc.getMetadata(); - promise.then(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'); - expect(metadata.contentDispositionFilename).toEqual(null); + promise.then(function({ info, metadata, contentDispositionFilename, }) { + expect(info['Title']).toEqual('Basic API Test'); + // The following are PDF.js specific, non-standard, properties. + expect(info['PDFFormatVersion']).toEqual('1.7'); + expect(info['IsLinearized']).toEqual(false); + expect(info['IsAcroFormPresent']).toEqual(false); + expect(info['IsXFAPresent']).toEqual(false); + + expect(metadata instanceof Metadata).toEqual(true); + expect(metadata.get('dc:title')).toEqual('Basic API Test'); + + expect(contentDispositionFilename).toEqual(null); done(); }).catch(function (reason) { done.fail(reason);