[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.
This commit is contained in:
Jonas Jenwald 2018-07-24 15:02:14 +02:00
parent 8a4466139b
commit 928b89382e
2 changed files with 16 additions and 7 deletions

View File

@ -535,12 +535,13 @@ var PDFDocument = (function PDFDocumentClosure() {
return shadow(this, 'numPages', num); return shadow(this, 'numPages', num);
}, },
get documentInfo() { get documentInfo() {
var docInfo = { const docInfo = {
PDFFormatVersion: this.pdfFormatVersion, PDFFormatVersion: this.pdfFormatVersion,
IsLinearized: !!this.linearization,
IsAcroFormPresent: !!this.acroForm, IsAcroFormPresent: !!this.acroForm,
IsXFAPresent: !!this.xfa, IsXFAPresent: !!this.xfa,
}; };
var infoDict; let infoDict;
try { try {
infoDict = this.xref.trailer.get('Info'); infoDict = this.xref.trailer.get('Info');
} catch (err) { } catch (err) {

View File

@ -28,6 +28,7 @@ import {
} from '../../src/display/api'; } from '../../src/display/api';
import { GlobalWorkerOptions } from '../../src/display/worker_options'; import { GlobalWorkerOptions } from '../../src/display/worker_options';
import isNodeJS from '../../src/shared/is_node'; import isNodeJS from '../../src/shared/is_node';
import { Metadata } from '../../src/display/metadata';
describe('api', function() { describe('api', function() {
let basicApiFileName = 'basicapi.pdf'; let basicApiFileName = 'basicapi.pdf';
@ -802,11 +803,18 @@ describe('api', function() {
}); });
it('gets metadata', function(done) { it('gets metadata', function(done) {
var promise = doc.getMetadata(); var promise = doc.getMetadata();
promise.then(function(metadata) { promise.then(function({ info, metadata, contentDispositionFilename, }) {
expect(metadata.info['Title']).toEqual('Basic API Test'); expect(info['Title']).toEqual('Basic API Test');
expect(metadata.info['PDFFormatVersion']).toEqual('1.7'); // The following are PDF.js specific, non-standard, properties.
expect(metadata.metadata.get('dc:title')).toEqual('Basic API Test'); expect(info['PDFFormatVersion']).toEqual('1.7');
expect(metadata.contentDispositionFilename).toEqual(null); 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(); done();
}).catch(function (reason) { }).catch(function (reason) {
done.fail(reason); done.fail(reason);