k-yle / pdf-to-img

📃📸 Converts PDFs to images in nodejs
https://npm.im/pdf-to-img
MIT License
85 stars 22 forks source link

TypeError: it is not a function #159

Closed Manasseh-Ankrah closed 2 years ago

Manasseh-Ankrah commented 2 years ago

Please I need help on how to solve this issue. Thank you!

k-yle commented 2 years ago

Hi, a bit more information would be helpful.....

Manasseh-Ankrah commented 2 years ago

//index.js

const { pdf } = require("pdf-to-img");

it("generates a PDF", async () => { for await (const page of await pdf("https://v.nicmid.com/STSAC20961459074225052.pdf")) { expect(page).toMatchImageSnapshot(); } });

//Error Message

PS C:\Users\Manasseh Ankrah\Documents\Projects\i-sticker\backend> node pdf-img C:\Users\Manasseh Ankrah\Documents\Projects\i-sticker\backend\pdf-img.js:3 it("generates a PDF", async () => { ^

ReferenceError: it is not defined at Object. (C:\Users\Manasseh Ankrah\Documents\Projects\i-sticker\backend\pdf-img.js:3:1) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) at node:internal/main/run_main_module:17:47 PS C:\Users\Manasseh Ankrah\Documents\Projects\i-sticker\backend>

k-yle commented 2 years ago

you're using a code snippet for a testing framework such as jest or mocha.

If you want to use this module without a test framework, just use something like this:

for await (const page of await pdf("./path/to/my/file.pdf")) {
  expect(page).toMatchImageSnapshot();
}
Manasseh-Ankrah commented 2 years ago

Thanks for your reply I really appreciate it.

Manasseh-Ankrah commented 2 years ago

Please, does this library support pdf from urls ? example: https://v.nicmid.com/STSAC20961459074225052.pdf

k-yle commented 2 years ago

No, you must download the file using a different module

Manasseh-Ankrah commented 2 years ago

Alright, Thank You