@jsreport/pdfjs
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -6,2 +6,3 @@ const CMapFactory = require('../pdfjs-ext/core/cmap.js').CMapFactory | ||
const zlib = require('zlib') | ||
const PDF = require('../object') | ||
@@ -20,3 +21,10 @@ module.exports = (doc) => { | ||
for (const pageObject of pages) { | ||
const streamObject = pageObject.properties.get('Contents').object.content | ||
let streamObject | ||
if (Array.isArray(pageObject.properties.get('Contents'))) { | ||
streamObject = concatStreams(pageObject.properties.get('Contents')) | ||
} else { | ||
const contentsObject = pageObject.properties.get('Contents').object | ||
streamObject = contentsObject.content | ||
} | ||
await processStream({ | ||
@@ -295,1 +303,20 @@ doc, | ||
} | ||
function concatStreams (streams) { | ||
const buffers = [] | ||
for (const content of streams) { | ||
const pageStreamObject = content.object?.content?.object | ||
if (pageStreamObject) { | ||
const filterProp = pageStreamObject.properties.get('Filter') | ||
if (filterProp && filterProp.name === 'FlateDecode') { | ||
buffers.push(zlib.unzipSync(pageStreamObject.content.content)) | ||
} | ||
} | ||
} | ||
const contentsObject = new PDF.Object('Contents') | ||
const streamObject = new PDF.Stream(contentsObject) | ||
streamObject.content = zlib.deflateSync(Buffer.concat(buffers)) | ||
contentsObject.prop('Length', streamObject.content.length) | ||
contentsObject.prop('Filter', 'FlateDecode') | ||
return streamObject | ||
} |
{ | ||
"name": "@jsreport/pdfjs", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -509,2 +509,21 @@ const { Document, External } = require('../') | ||
it('processText should support page Contents as array', async () => { | ||
const document = new Document() | ||
const external = new External(fs.readFileSync(path.join(__dirname, 'page-contents-array.pdf'))) | ||
document.append(external) | ||
let docText = '' | ||
await document.processText({ | ||
resolver: (text) => { | ||
docText += text | ||
} | ||
}) | ||
await document.asBuffer() | ||
// the external PDF contains unsuported text commands like | ||
// [(pement \351lectrique ou \351lectr)6.1 (onique usag\351 dans la limite de la quantit\351)-15 ( )]TJ | ||
// in future we may support it, but at this moment it isn't important because text parsing is primarily used for embedding hidden marks with chrome | ||
docText.should.containEql('amiable') | ||
}) | ||
it('acroform with text type', async () => { | ||
@@ -511,0 +530,0 @@ const document = new Document() |
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
2828296
97
18171