question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: PDF2Pic is not a constructor

See original GitHub issue

Hi everyone, I’m trying to use pdf2pic as the example :

let PDF2Pic = require('pdf2pic').default
let converter = new PDF2Pic({
  density: 100,           // output pixels per inch
  savename: "untitled",   // output file name
  savedir: "./images",    // output file location
  format: "png",          // output file format
  size: 600               // output size in pixels
})

// by default the first page of the pdf will be converted
// to image
converter.convert("/path/to/pdf/sample.pdf")
  .then(resolve => {
    console.log("image converted successfully")
  })

But it returns the following error :

/mnt/c/Users/totorelmatador/Desktop/test/test.js:3
let converter = new PDF2Pic({
                ^

TypeError: PDF2Pic is not a constructor
    at Object.<anonymous> (/mnt/c/Users/totorelmatador/Desktop/test/test.js:3:17)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

I do not understand what is the source of the problem… I tried to remove the .defaut from the require as follow :

let PDF2Pic = require('pdf2pic')

But I obtain this error :

(node:2145) UnhandledPromiseRejectionWarning: Error: Could not execute GraphicsMagick/ImageMagick: gm "identify" "-ping" "-format" "%p" "./extracted.pdf" this most likely means the gm/convert binaries can't be found
    at ChildProcess.<anonymous> (/mnt/c/Users/totorelmatador/Desktop/test/node_modules/gm/lib/command.js:232:12)
    at emitOne (events.js:116:13)
    at ChildProcess.emit (events.js:211:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:196:12)
    at onErrorNT (internal/child_process.js:372:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:695:11)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
(node:2145) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2145) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2145) UnhandledPromiseRejectionWarning: Error: Could not execute GraphicsMagick/ImageMagick: gm "convert" "-density" "100x100" "-quality" "75" "-[0]" "-resize" "600x" "-compress" "jpeg" "./tattoo_process/untitled_1.png" this most likely means the gm/convert binaries can't be found
    at ChildProcess.<anonymous> (/mnt/c/Users/totorelmatador/Desktop/test/node_modules/gm/lib/command.js:232:12)
    at emitOne (events.js:116:13)
    at ChildProcess.emit (events.js:211:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:196:12)
    at onErrorNT (internal/child_process.js:372:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:695:11)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
(node:2145) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

Can someone help me ? 😄 Thank you !

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
yakovmeistercommented, Jun 1, 2019

Hi everyone, I have updated the read me file to address this concern. As for the path issue in windows, it would be hard for me to troubleshoot that one as I’m currently using linux. Also, it would be helpful if you can post your node version so I can troubleshoot and possibly update it on my free time. Thanks.

1reaction
AntonC9018commented, Apr 8, 2019

@gopeter remove “.default”. It worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: PDF2Pic is not a constructor - - Bountysource
Hi everyone, I'm trying to use pdf2pic as the example : let PDF2Pic = require('pdf2pic').default let converter = new PDF2Pic({ density: 100, ...
Read more >
pdf2pic - npm
A utility for converting pdf to image and base64 format.. Latest version: 2.1.4, last published: 2 years ago. Start using pdf2pic in your ......
Read more >
TypeError: Image is not a constructor - jquery - Stack Overflow
It looks like your variable Image is causing the problem(Assuming it is in the global scope). In such case your Image object is...
Read more >
[solved] Contrib-pdfmake node - help please getting node to ...
Both examples give the debug error "TypeError: URLBrowserResolver is not a constructor". Thinking I must be doing something simple incorrectly ? Have tried...
Read more >
Reference — pdf2image latest documentation
Bytes of the PDF file. dpi. Dots per inch, can be seen as the relative resolution of the output PDF, higher is better...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found