unpdf 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const pdfjsDist = require('pdfjs-dist');
4
-
5
3
  async function getDocumentProxy(data) {
6
4
  const { getDocument } = await getPDFJSImports();
7
5
  const pdf = await getDocument({
@@ -15,8 +13,7 @@ async function getDocumentProxy(data) {
15
13
  async function getPDFJSImports() {
16
14
  try {
17
15
  const { default: mod } = await import('pdfjs-dist/legacy/build/pdf');
18
- const { getDocument, version } = mod;
19
- return { getDocument, version };
16
+ return mod;
20
17
  } catch (e) {
21
18
  console.error(e);
22
19
  throw new Error(
@@ -52,9 +49,10 @@ async function getImagesFromPage(data, pageNumber) {
52
49
  const pdf = await getDocumentProxy(data);
53
50
  const page = await pdf.getPage(pageNumber);
54
51
  const operatorList = await page.getOperatorList();
52
+ const { OPS } = await getPDFJSImports();
55
53
  const images = [];
56
54
  for (const op of operatorList.fnArray) {
57
- if (op !== pdfjsDist.OPS.paintImageXObject)
55
+ if (op !== OPS.paintImageXObject)
58
56
  continue;
59
57
  const image = await page.objs.get(operatorList.argsArray[op][0]);
60
58
  if (image.data)
@@ -1,5 +1,3 @@
1
- import { OPS } from 'pdfjs-dist';
2
-
3
1
  async function getDocumentProxy(data) {
4
2
  const { getDocument } = await getPDFJSImports();
5
3
  const pdf = await getDocument({
@@ -13,8 +11,7 @@ async function getDocumentProxy(data) {
13
11
  async function getPDFJSImports() {
14
12
  try {
15
13
  const { default: mod } = await import('pdfjs-dist/legacy/build/pdf');
16
- const { getDocument, version } = mod;
17
- return { getDocument, version };
14
+ return mod;
18
15
  } catch (e) {
19
16
  console.error(e);
20
17
  throw new Error(
@@ -50,6 +47,7 @@ async function getImagesFromPage(data, pageNumber) {
50
47
  const pdf = await getDocumentProxy(data);
51
48
  const page = await pdf.getPage(pageNumber);
52
49
  const operatorList = await page.getOperatorList();
50
+ const { OPS } = await getPDFJSImports();
53
51
  const images = [];
54
52
  for (const op of operatorList.fnArray) {
55
53
  if (op !== OPS.paintImageXObject)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unpdf",
3
3
  "type": "module",
4
- "version": "0.2.1",
4
+ "version": "0.2.2",
5
5
  "packageManager": "pnpm@8.6.12",
6
6
  "description": "Utilities to work with PDFs",
7
7
  "author": "Johann Schopplich <pkg@johannschopplich.com>",