Open kefniark opened 4 years ago
I think I will just take some inspiration from your code and switch the canvas by a real canvas. I just need to extract few images like the cover anyway π
Btw, I would suggest to change that Sync
method by a promise you can await
pdfData = new Uint8Array(fs.readFileSync(pdfURL));
by
import util from 'util'
const readFile= util.promisify(fs.readFile);
...
pdfData = new Uint8Array(await readFile(pdfURL));
Thanks for pointing this out. I'd only tested it on pure node and chose node-canvas accordingly. I'll try to find a workaround for this but in the meantime feel free to fork the repo and make the necessary changes for your use case. (Please do submit a PR if you find a solution that works for node too π)
I think I will just take some inspiration from your code and switch the canvas by a real canvas. I just need to extract few images like the cover anyway π
Btw, I would suggest to change that
Sync
method by a promise you canawait
pdfData = new Uint8Array(fs.readFileSync(pdfURL));
by
import util from 'util' const readFile= util.promisify(fs.readFile); ... pdfData = new Uint8Array(await readFile(pdfURL));
I'll make this change you suggested here - thanks for pointing this out too.
Hi guys, Same issue for me, I tried to rebuild it after the installation but it still won't work But great reactivity @olliet88 thanks!
@Yarin4 just to double check - did you rebuild it against electron using electron-rebuild
or against node using npm rebuild
?
If you rebuilt against node could you try rebuilding against electron and reporting back? It'd be really useful thanks.
@Yarin4 just to double check - did you rebuild it against electron using
electron-rebuild
or against node usingnpm rebuild
?If you rebuilt against node could you try rebuilding against electron and reporting back? It'd be really useful thanks.
I used electron-rebuild but I actually think I am missing a package I'll have to check again
Same issue for me Electron 11.1.1
when I used electron-rebuild, it fails and reports an error.
β ΄ Building module: canvas, Completed: 0C:\Workspace\ELECTRON\getPDFtext\get-pdf-text\node_modules\canvas\src\backend\Backend.h(3,10): fatal error C1083: ζ ζ³ζεΌε
ζ¬ζδ»Ά: βcairo.hβ: No suc
h file or directory [C:\Workspace\ELECTRON\getPDFtext\get-pdf-te
xt\node_modules\canvas\build\canvas.vcxproj]
β Building module
β Rebuild Failed
An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild 'C:\Workspace\ELECTRON\getPDFtext\get-pdf-text\node_modules\canvas'.
Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
You should update to master branch of node-canvas (v3.0.0) v2 has a lot of build issues with electron rebuild. The update also requires updating pdfjs-dist's canvas dependency to master branch as well, so I used a fork.
https://github.com/Automattic/node-canvas https://github.com/Tenpi/pdfjs-dist
Run this to fix: electron-rebuild -f -w canvas
Specifically on windows, the canvas node depends on multiple dll files so I just added this with webpack copy plugin.
let copyPatterns = []
if (process.platform === "win32") {
copyPatterns.push(...[
{from: "node_modules/canvas/build/Release/jpeg62.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libcairo-2.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libexpat-1.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libfontconfig-1.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libfreetype-6.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libglib-2.0-0.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libgmodule-2.0-0.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libgobject-2.0-0.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libgthread-2.0-0.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libintl-8.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libpango-1.0-0.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libpangocairo-1.0-0.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libpangoft2-1.0-0.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libpangowin32-1.0-0.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/libpng14-14.dll", to: "[name][ext]"},
{from: "node_modules/canvas/build/Release/zlib1.dll", to: "[name][ext]"}
])
}
// add plugin
new CopyPlugin({
patterns: copyPatterns
})
Description
I like the idea of this lib, and I was surprised to see someone else working on the same thing few hours ago π
Apparently the dependence to
canvas
caused issues with other flavor of JS like electron Seems like only node binding are managed