yakovmeister / pdf2image

A utility for converting pdf to image and base64 format.
MIT License
412 stars 140 forks source link

How to run this project #209

Closed dev3py closed 1 month ago

dev3py commented 1 month ago

I have installed all the pre-requsites. When i ran the npm run build command the dist folder was formed. And in dump folder i can see the images That were converted from the pdf1.pdf & pdf2.pdf which was in the /test/data/ folder. But how can i convert my pdfs to images. Can someone give me the step to convert my pdfs to images. I replace the pdf1.pdf & pdf2.pdf with my pdfs and ran the build and i got this error

pdf2pic@3.1.1 build npm run test && npm run clean && npm run rollup

pdf2pic@3.1.1 test nyc --reporter=lcov npm run mocha

pdf2pic@3.1.1 mocha mocha test/*/.test.ts

graphics 1) should return page numbers 2) should return page numbers (from stream) ✔ should return file information (630ms) ✔ should return all of the options (default options) ✔ should set and return all of the options (custom options) ✔ should by default use width as height if no height is given ✔ should by not set height if preserveAspectRatio is true ✔ should save first page as image file (995ms) 3) should save second page as image file 4) should save second page as base64 string 5) should save second page as buffer

PDF2Pic Core ✔ should use default options (367ms) ✔ should convert pdf to pic (file input, first page) (425ms) ✔ should convert pdf to pic (buffer input, first page) (442ms) ✔ should convert pdf to pic (base64 input, first page) (459ms) 6) should convert pdf to pic (file input, second page, base64 output) 7) should convert pdf to pic (buffer input, second page, base64 output) 8) should convert pdf to pic (base64 input, second page, base64 output) 9) should convert pdf to pic (file input, bulk 2 pages) 10) should convert pdf to pic (file input, bulk all pages) 11) should convert pdf to pic (buffer input, bulk all pages) 12) should convert pdf to pic (base64 input, bulk all pages) responseType: buffer 13) should convert pdf to pic (file input, first page) 14) should convert pdf to pic (buffer input, second page) 15) should convert pdf to pic (base64 input, second page) 16) should convert pdf to pic (base64 input, bulk all pages) preserveAspectRatio 17) should preserve aspect ratio of pages ✔ should set height automatically (360ms) ✔ should set width automatically (411ms)

resolveResponseType ✔ should resolve to image if convertOptions is undefined ✔ should resolve to image if responseType is image ✔ should resolve to base64 if responseType is base64 ✔ should resolve to buffer if responseType is buffer ✔ should throw an error if convertOptions is invalid type ✔ should throw an error if convertOptions is invalid responseType

18 passing (8s) 17 failing

1) graphics should return page numbers:

  AssertionError: expected '1' to equal '1 2 3 4 5 6 7 8 9'
  + expected - actual

  -1
  +1 2 3 4 5 6 7 8 9

  at D:\NIPL-PROJECTS\pdf2image\test\graphics.test.ts:19:31
  at Generator.next (<anonymous>)
  at fulfilled (test\graphics.test.ts:5:58)
  at processTicksAndRejections (node:internal/process/task_queues:95:5)

2) graphics should return page numbers (from stream):

  AssertionError: expected '1' to equal '1 2 3 4 5 6 7 8 9'
  + expected - actual

  -1
  +1 2 3 4 5 6 7 8 9

  at D:\NIPL-PROJECTS\pdf2image\test\graphics.test.ts:28:31
  at Generator.next (<anonymous>)
  at fulfilled (test\graphics.test.ts:5:58)
  at processTicksAndRejections (node:internal/process/task_queues:95:5)

3) graphics should save second page as image file: Error: Command failed: Requested FirstPage is greater than the number of pages in the file: 1 No pages will be processed (FirstPage > LastPage). gm convert: Postscript delegate failed (C:\Users\rampr\AppData\Local\Temp\gmm8apF3).

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

4) graphics should save second page as base64 string: Error: Command failed: gm identify: Improper image header (./dump/savefiletest/frombase64.png). gm identify: Request did not return an image.

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

5) graphics should save second page as buffer: Error: Command failed: gm identify: Improper image header (./dump/savefiletest/tobuffer.png). gm identify: Request did not return an image.

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

6) PDF2Pic Core should convert pdf to pic (file input, second page, base64 output): Error: Command failed: gm identify: Improper image header (./dump/fromfiletest/frombase64.png). gm identify: Request did not return an image.

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

7) PDF2Pic Core should convert pdf to pic (buffer input, second page, base64 output): Error: Command failed: gm identify: Improper image header (./dump/fromfiletest/frombase64.png). gm identify: Request did not return an image.

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

8) PDF2Pic Core should convert pdf to pic (base64 input, second page, base64 output): Error: Command failed: gm identify: Improper image header (./dump/fromfiletest/frombase64.png). gm identify: Request did not return an image.

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

9) PDF2Pic Core should convert pdf to pic (file input, bulk 2 pages): Error: Command failed: Requested FirstPage is greater than the number of pages in the file: 1 No pages will be processed (FirstPage > LastPage). gm convert: Postscript delegate failed (C:\Users\rampr\AppData\Local\Temp\gm598kYb).

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

10) PDF2Pic Core should convert pdf to pic (file input, bulk all pages):

  AssertionError: expected [ { name: 'test-3.1.png', …(4) } ] to have a length of 9 but got 1
  + expected - actual

  -1
  +9

  at D:\NIPL-PROJECTS\pdf2image\test\index.test.ts:226:54
  at Generator.next (<anonymous>)
  at fulfilled (test\index.test.ts:5:58)
  at processTicksAndRejections (node:internal/process/task_queues:95:5)

11) PDF2Pic Core should convert pdf to pic (buffer input, bulk all pages):

  AssertionError: expected [ { name: 'test-3.1.png', …(4) } ] to have a length of 9 but got 1
  + expected - actual

  -1
  +9

  at D:\NIPL-PROJECTS\pdf2image\test\index.test.ts:249:54
  at Generator.next (<anonymous>)
  at fulfilled (test\index.test.ts:5:58)
  at processTicksAndRejections (node:internal/process/task_queues:95:5)

12) PDF2Pic Core should convert pdf to pic (base64 input, bulk all pages):

  AssertionError: expected [ { …(3) } ] to have a length of 9 but got 1
  + expected - actual

  -1
  +9

  at D:\NIPL-PROJECTS\pdf2image\test\index.test.ts:274:56
  at Generator.next (<anonymous>)
  at fulfilled (test\index.test.ts:5:58)
  at processTicksAndRejections (node:internal/process/task_queues:95:5)

13) PDF2Pic Core responseType: buffer should convert pdf to pic (file input, first page): Error: Command failed: gm identify: Improper image header (./dump/fromfiletest/out-buffer-1.png). gm identify: Request did not return an image.

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

14) PDF2Pic Core responseType: buffer should convert pdf to pic (buffer input, second page): Error: Command failed: gm identify: Improper image header (./dump/fromfiletest/out-buffer-2.png). gm identify: Request did not return an image.

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

15) PDF2Pic Core responseType: buffer should convert pdf to pic (base64 input, second page): Error: Command failed: gm identify: Improper image header (./dump/fromfiletest/out-buffer-3.png). gm identify: Request did not return an image.

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)

16) PDF2Pic Core responseType: buffer should convert pdf to pic (base64 input, bulk all pages):

  AssertionError: expected [ { …(3) } ] to have a length of 9 but got 1
  + expected - actual

  -1
  +9

  at D:\NIPL-PROJECTS\pdf2image\test\index.test.ts:363:58
  at Generator.next (<anonymous>)
  at fulfilled (test\index.test.ts:5:58)
  at processTicksAndRejections (node:internal/process/task_queues:95:5)

17) PDF2Pic Core preserveAspectRatio should preserve aspect ratio of pages: Error: Command failed: Requested FirstPage is greater than the number of pages in the file: 1 No pages will be processed (FirstPage > LastPage). gm convert: Postscript delegate failed (C:\Users\rampr\AppData\Local\Temp\gmyHKCGV).

  at ChildProcess.onExit (node_modules\gm\lib\command.js:318:17)
  at ChildProcess.emit (node:events:518:28)
  at ChildProcess.emit (node:domain:488:12)
  at ChildProcess.cp.emit (node_modules\gm\node_modules\cross-spawn\lib\enoent.js:40:29)
  at maybeClose (node:internal/child_process:1105:16)
  at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5)
mskec commented 1 month ago

Hi @dev3py,

This repository holds pdf2pic npm package. You run it by installing it in your node.js project and using library's API.

Library's API can be found in the README. You can also reference repository with examples