@jsreport/jsreport-pdf-utils
Advanced tools
Comparing version 4.1.1 to 4.2.0
@@ -125,6 +125,2 @@ const parsePdf = require('./utils/parsePdf') | ||
if (outlines) { | ||
doc.outlines(outlines) | ||
} | ||
doc.processText({ | ||
@@ -173,2 +169,7 @@ resolver: async (text, { remove, getPosition }) => { | ||
if (outlines) { | ||
// needs to be after the processText because it may need pdfDest processed | ||
doc.outlines(outlines) | ||
} | ||
if (pdfPassword) { | ||
@@ -213,2 +214,4 @@ doc.encrypt({ | ||
} | ||
throw e | ||
} | ||
@@ -215,0 +218,0 @@ } |
@@ -1,2 +0,2 @@ | ||
const pdfjs = require('pdfjs-dist/legacy/build/pdf.js') | ||
const { External } = require('@jsreport/pdfjs') | ||
@@ -66,8 +66,2 @@ function parseGroup (text, hiddenPageFields) { | ||
async function getPageText (pageNum, doc) { | ||
const page = await doc.getPage(pageNum) | ||
const textContent = await page.getTextContent() | ||
return textContent.items.reduce((a, v) => a + v.str, '') | ||
} | ||
module.exports = async (contentBuffer, { | ||
@@ -78,12 +72,8 @@ hiddenPageFields = {}, | ||
}) => { | ||
let doc | ||
let pages = null | ||
try { | ||
const loadTask = pdfjs.getDocument(contentBuffer) | ||
if (password != null) { | ||
loadTask.onPassword = (updatePassword) => updatePassword(password) | ||
} | ||
doc = await loadTask.promise | ||
const ext = new External(contentBuffer) | ||
pages = await ext.parseText() | ||
} catch (e) { | ||
// pdf.js fails on empty pdfs even it is valid | ||
// seems better to just log warning than crash completely | ||
// keep the back compatibility and avoid hard crash on pdf parse | ||
console.warn('Failed to parse pdf. Items, groups and text isn\'t filled: ' + e) | ||
@@ -101,4 +91,3 @@ | ||
const result = { pages: [] } | ||
for (let i = 1; i < doc.numPages + 1; i++) { | ||
const text = await getPageText(i, doc) | ||
for (const text of pages) { | ||
const parsedGroup = parseGroup(text, hiddenPageFields) | ||
@@ -105,0 +94,0 @@ const page = { |
{ | ||
"name": "@jsreport/jsreport-pdf-utils", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"description": "jsreport extension providing pdf operations like merge or concatenation", | ||
@@ -36,3 +36,3 @@ "keywords": [ | ||
"@jsreport/node-signpdf": "1.4.2", | ||
"@jsreport/pdfjs": "1.5.0", | ||
"@jsreport/pdfjs": "1.6.0", | ||
"cheerio": "1.0.0-rc.12", | ||
@@ -42,10 +42,9 @@ "lodash.omit": "4.5.0", | ||
"node-forge": "1.3.1", | ||
"parse-color": "1.0.0", | ||
"pdfjs-dist": "2.16.105" | ||
"parse-color": "1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@jsreport/jsreport-assets": "4.1.0", | ||
"@jsreport/jsreport-assets": "4.1.1", | ||
"@jsreport/jsreport-child-templates": "4.1.0", | ||
"@jsreport/jsreport-chrome-pdf": "4.1.0", | ||
"@jsreport/jsreport-core": "4.2.1", | ||
"@jsreport/jsreport-core": "4.3.1", | ||
"@jsreport/jsreport-handlebars": "4.0.1", | ||
@@ -57,2 +56,3 @@ "@jsreport/jsreport-jsrender": "4.0.0", | ||
"mocha": "10.1.0", | ||
"pdfjs-dist": "2.16.105", | ||
"puppeteer": "22.4.1", | ||
@@ -59,0 +59,0 @@ "rimraf": "2.6.3", |
@@ -10,4 +10,9 @@ # @jsreport/jsreport-pdf-utils | ||
### 4.1.1 | ||
### 4.2.0 | ||
- stop using pdfjs-dist for test parsing and use our implementation | ||
- support external pdf with missing EOL after endstream improve merging pdf outlines | ||
### 4.1.1 | ||
- dont set lang when it was already filled, fixes compatibility with newer chrome | ||
@@ -14,0 +19,0 @@ |
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
7
86
1700762
15
8090
+ Added@jsreport/pdfjs@1.6.0(transitive)
- Removedpdfjs-dist@2.16.105
- Removed@jsreport/pdfjs@1.5.0(transitive)
- Removeddommatrix@1.0.3(transitive)
- Removedpdfjs-dist@2.16.105(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)
Updated@jsreport/pdfjs@1.6.0