@jsreport/pdfjs
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -13,2 +13,3 @@ const PDF = require('./object') | ||
const pdfA = require('./mixins/pdfa/pdfA.js') | ||
const pdfUA = require('./mixins/pdfua/pdfUA.js') | ||
const DocumentBase = require('./documentBase') | ||
@@ -52,2 +53,3 @@ | ||
pdfA(this) | ||
pdfUA(this) | ||
} | ||
@@ -54,0 +56,0 @@ |
@@ -27,3 +27,3 @@ const unionGlobalObjects = require('./utils/unionGlobalObjects') | ||
} else { | ||
if (options.copyStructTags) { | ||
if (options.copyAccessibilityTags) { | ||
nullPgRef(doc.catalog.properties.get('StructTreeRoot')?.object, page) | ||
@@ -30,0 +30,0 @@ } |
@@ -55,17 +55,42 @@ const PDF = require('../../object') | ||
let parentTreeNextKey = structTreeRoot.properties.get('ParentTreeNextKey') | ||
const structsInPage = findStructsForPageAndReplaceOldPg(structTreeRoot, newPage, originalPage, xobj) | ||
// the parents from the xobjects are in individual buckets, however this approach as well as putting the parents to the same bucket | ||
// as the ones from page content causes Acrobat prefilight error "Inconsistent parent tree mapping" | ||
const pageContents = new PDF.Object() | ||
pageContents.content = new PDF.Array(structsInPage.map(s => s.toReference())) | ||
pageContents.content = new PDF.Array(structsInPage.filter(s => xobj || s.node.get('Stm') == null).map(s => s.parent.toReference())) | ||
const parentTreeNextKey = parentTree.properties.get('Nums')[parentTree.properties.get('Nums').length - 2] | ||
const contentObject = xobj || newPage | ||
contentObject.properties.set('StructParents', parentTreeNextKey) | ||
parentTree.properties.set('Nums', new PDF.Array([ | ||
...parentTree.properties.get('Nums'), | ||
parentTreeNextKey + 1, | ||
parentTreeNextKey++, | ||
pageContents.toReference() | ||
])) | ||
structTreeRoot.properties.set('ParentTreeNextKey', parentTreeNextKey + 2) | ||
const contentObject = xobj || newPage | ||
contentObject.properties.set('StructParents', parentTreeNextKey + 1) | ||
if (!xobj) { | ||
// every xobject content structure parents goes to individual parent tree bucket | ||
const xobjStructsInPage = structsInPage.filter(s => s.node.get('Stm') != null) | ||
const groupedStructsByXObj = xobjStructsInPage.reduce( | ||
(entryMap, { node, parent }) => entryMap.set(node.get('Stm'), [...entryMap.get(node.get('Stm')) || [], parent]), | ||
new Map() | ||
) | ||
for (const [stm, parents] of groupedStructsByXObj) { | ||
const xobjContents = new PDF.Object() | ||
xobjContents.content = new PDF.Array(parents.map(p => p.toReference())) | ||
stm.object.properties.set('StructParents', parentTreeNextKey) | ||
parentTree.properties.set('Nums', new PDF.Array([ | ||
...parentTree.properties.get('Nums'), | ||
parentTreeNextKey++, | ||
xobjContents.toReference() | ||
])) | ||
} | ||
} | ||
structTreeRoot.properties.set('ParentTreeNextKey', parentTreeNextKey) | ||
} | ||
@@ -81,3 +106,3 @@ | ||
} | ||
return structsInPage.push(parent) | ||
return structsInPage.push({ parent, node: nodeOrDict }) | ||
} | ||
@@ -84,0 +109,0 @@ |
{ | ||
"name": "@jsreport/pdfjs", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "", | ||
@@ -15,3 +15,3 @@ "main": "index.js", | ||
"@jsreport/node-signpdf": "1.4.2", | ||
"crypto-js": "4.1.1", | ||
"crypto-js": "4.2.0", | ||
"parse-color": "1.0.0", | ||
@@ -21,3 +21,3 @@ "pdfjs-dist": "2.16.105" | ||
"devDependencies": { | ||
"mocha": "10.0.0", | ||
"mocha": "10.1.0", | ||
"should": "13.2.3", | ||
@@ -24,0 +24,0 @@ "standard": "16.0.4" |
103
test/test.js
@@ -321,2 +321,20 @@ const { Document, External } = require('../') | ||
it('merge followed with prepend should add xobj to the extra item in ParentTree', async () => { | ||
let document = new Document() | ||
document.append(new External(fs.readFileSync(path.join(__dirname, 'main.pdf'))), { copyAccessibilityTags: true }) | ||
document.merge(new External(fs.readFileSync(path.join(__dirname, 'header.pdf'))), { copyAccessibilityTags: true }) | ||
const bufBeforePrepent = await document.asBuffer() | ||
document = new Document() | ||
document.append(new External(fs.readFileSync(path.join(__dirname, 'main.pdf'))), { copyAccessibilityTags: true }) | ||
document.append(new External(bufBeforePrepent), { copyAccessibilityTags: true }) | ||
const pdf = await document.asBuffer() | ||
fs.writeFileSync('out.pdf', pdf) | ||
const { catalog } = await validate(pdf) | ||
const structTreeRoot = catalog.properties.get('StructTreeRoot').object | ||
structTreeRoot.properties.get('ParentTreeNextKey').should.be.eql(3) | ||
}) | ||
it('attachment should add buffer', async () => { | ||
@@ -899,3 +917,5 @@ const document = new Document() | ||
const external = new External(fs.readFileSync(path.join(__dirname, 'main.pdf'))) | ||
document.append(external) | ||
document.append(external, { | ||
copyAccessibilityTags: true | ||
}) | ||
document.info({ | ||
@@ -924,2 +944,3 @@ creationDate: new Date(2021, 2, 2, 5, 30), | ||
catalog.properties.get('OutputIntents').should.be.ok() | ||
catalog.properties.get('StructTreeRoot').should.be.ok() | ||
}) | ||
@@ -966,2 +987,82 @@ | ||
}) | ||
it('pdf/UA', async () => { | ||
const document = new Document() | ||
const external = new External(fs.readFileSync(path.join(__dirname, 'invoice.pdf'))) | ||
document.append(external, { | ||
copyAccessibilityTags: true | ||
}) | ||
document.info({ | ||
creationDate: new Date(2021, 2, 2, 5, 30), | ||
title: 'Foo-title', | ||
subject: 'Foo-subject', | ||
creator: 'Foo-creator', | ||
producer: 'Foo-producer' | ||
}) | ||
document.pdfUA() | ||
const buffer = await document.asBuffer() | ||
fs.writeFileSync('out.pdf', buffer) | ||
const { catalog, trailer } = await validate(buffer) | ||
trailer.get('ID').should.be.ok() | ||
catalog.properties.get('Names').object.properties.has('EmbeddedFiles').should.be.false() | ||
const metadataXml = catalog.properties.get('Metadata').object.content.toString() | ||
metadataXml.should.containEql('Foo-title') | ||
metadataXml.should.containEql('pdfuaid') | ||
catalog.properties.get('ViewerPreferences').get('DisplayDocTitle').should.be.true() | ||
const pageContentBuf = catalog.properties.get('Pages').object.properties.get('Kids')[0].object.properties.get('Contents').object.content.content | ||
const pageContent = zlib.unzipSync(pageContentBuf).toString('latin1') | ||
pageContent.should.containEql( | ||
['/Artifact BMC', | ||
'404 315 298 1 re', | ||
'f', | ||
'EMC'].join('\n')) | ||
pageContent.should.containEql( | ||
['/Artifact BMC', | ||
'BT', | ||
'/F14 16 Tf', | ||
'1 0 0 -1 687.84375 375 Tm', | ||
'<0141> Tj', | ||
'EMC', | ||
'ET'].join('\n')) | ||
}) | ||
it('pdf/UA shouldnt be applied twice', async () => { | ||
let document = new Document() | ||
let external = new External(fs.readFileSync(path.join(__dirname, 'invoice.pdf'))) | ||
document.append(external, { | ||
copyAccessibilityTags: true | ||
}) | ||
document.info({ | ||
creationDate: new Date(2021, 2, 2, 5, 30), | ||
title: 'Foo-title', | ||
subject: 'Foo-subject', | ||
creator: 'Foo-creator', | ||
producer: 'Foo-producer' | ||
}) | ||
document.pdfUA() | ||
let buffer = await document.asBuffer() | ||
document = new Document() | ||
external = new External(buffer) | ||
document.append(external, { | ||
copyAccessibilityTags: true | ||
}) | ||
document.pdfUA() | ||
buffer = await document.asBuffer() | ||
const { catalog } = await validate(buffer) | ||
const pageContentBuf = catalog.properties.get('Pages').object.properties.get('Kids')[0].object.properties.get('Contents').object.content.content | ||
const pageContent = zlib.unzipSync(pageContentBuf).toString('latin1') | ||
pageContent.should.not.containEql( | ||
['/Artifact BMC', | ||
'/Artifact BMC' | ||
].join('\n')) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2180700
67
6582
8
+ Addedcrypto-js@4.2.0(transitive)
- Removedcrypto-js@4.1.1(transitive)
Updatedcrypto-js@4.2.0