Convert PDF to image without webviewer UI

WebViewer Version: 8.2

Hello, I’m trying to reproduce the following guide Convert PDF to image in JavaScript Without Webviewer UI but having trouble with the PDFDoc.

When executing the following line const doc = await PDFNet.PDFDoc.createFromURL(url);, it throws the follwing error Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'createFromURL') at <anonymous>:17:41.

I think it’s because the FullAPI is not enabled correctly, so I went to the API documentation for the enableFullPDF() and encountered that this method is deprecated since version 8.0, could you give me an updated example on how to accomplish the same as that guide but with 8.2?

Thanks!

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi,

I think you can just call Core.enableFullPDF(); in v8.2. What the documentation means is that the fullAPI parameter in WebViewer constructor is deprecated.

Thanks.

Wanbo

Then I don’t know why it’s not working, I have the following code:

<html>
  <body>
      <h1>HI!</h1>
    <script src="./lib-8.2.0/core/webviewer-core.min.js"></script>
    <script>
    (async function() {
      Core.setWorkerPath('./lib-8.2.0/core');
      Core.enableFullPDF();
      const licenseKey = 'license here';
      await PDFNet.initialize(licenseKey);

      console.log(PDFNet.PDFDoc);
      const doc = await PDFNet.PDFDoc.createFromURL('http://localhost/path/to/preview_file.pdf');
      const pdfdraw = await PDFNet.PDFDraw.create(92);
      const itr = await doc.getPageIterator(1);
      const currPage = await itr.current();  
      const pngBuffer = await pdfdraw.exportStream(currPage, 'PNG');
      console.log(pngBuffer);
    //   const tifBuffer = await pdfdraw.exportStream(currPage, 'TIFF');
    })()
    </script>
  </body>
</html>

As you can see it’s basically copied from the guide I told you about, if I run the code the console prints the following:

undefined
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'createFromURL')
    at generateThumbnail.html:13:39

I don’t know what I am doing wrong since I’ve tested all the paths and they are correct.
I’ve also tried different PDF URLs and none have worked.

Thanks,
Sergi