[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:
parent
8a4466139b
commit
928b89382e
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user