How to load a third-party module properly?

Skip to first unread message

Nov 7, 2021, 10:45:38 PM11/7/21
to zotero-dev

Hi, I am trying to add bookmarks(or outlines) to a pdf file by pdf-lib in Javascript. Demo code can be run successfully in an NPM environment, but the transferred code in Zotero didn’t work.

I load the pdf-lib file by

  var fileLoader = Components.classes[";1"]

The PDFLib seems to be imported as a global object, I can use PDFLib in the Zotero Run Javascript window and the demo code works fine. But the code in the plugin didn’t work.

Then I look into the code in Zotfile, the pdfjs library seems to be wrapped in an HTML file. Maybe I can try to use pdf-lib like pdfjs in zotfile? As a newbie to javascript, I even don’t know where to get some useful data about this kind of library import? I hope someone cloud give me some clues about this.

Emiliano Heyns

Nov 8, 2021, 4:45:47 PM11/8/21
to zotero-dev
You're going to have to use a bundler. I can heartily recommend esbuild, which is simple to use and blazingly fast.
Reply all
Reply to author
0 new messages