Hướng dẫn spawn wkhtmltopdf enoent - sinh ra wkhtmltopdf enoent

Tôi gặp sự cố khi sử dụng WKHTMLTOPDF, tôi vừa cài đặt phiên bản 64BITS và phụ thuộc NodeJS nhưng tôi gặp lỗi:

Mã của tôi :

var wkhtmltopdf = require('wkhtmltopdf');

wkhtmltopdf('http://google.com/', { pageSize: 'letter' }).pipe(fs.createWriteStream('/out.pdf'));

Lỗi của tôi:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:1001:11)
    at Process.ChildProcess._handle.onexit (child_process.js:792:34)

npm ERR!  start: `node ./bin/www`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the *******@1.2.0 start script.
npm ERR! This is most likely a problem with the GestionDettes package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get their info via:
npm ERR!     npm owner ls GestionDettes
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! cwd C:\xampp\htdocs\*******
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\xampp\htdocs\********\npm-debug.log
npm ERR! not ok code 0

Đã hỏi ngày 12 tháng 3 năm 2015 lúc 10:40Mar 12, 2015 at 10:40

Hướng dẫn spawn wkhtmltopdf enoent - sinh ra wkhtmltopdf enoent

6

Đảm bảo công cụ dòng lệnh WKHTMLTOPDF được cài đặt. Bạn có thể tải xuống từ: http://wkhtmltopdf.org/doads.html

Sau đó đảm bảo thư mục bin trên đường dẫn của bạn. C:\Program Files\wkhtmltopdf\bin là đường dẫn cài đặt mặc định. Xác minh rằng nó là chính xác cho máy của bạn.

Đã trả lời ngày 12 tháng 5 năm 2016 lúc 14:28May 12, 2016 at 14:28

Michael Stramelmichael StramelMichael Stramel

1.2811 Huy hiệu vàng15 Huy hiệu bạc18 Huy hiệu đồng1 gold badge15 silver badges18 bronze badges

0

Thêm tùy chọn spawnOptions làm việc cho tôi

wkhtmltopdf('http://google.com/', { pageSize: 'letter' spawnOptions:{shell: true}}).pipe(fs.createWriteStream('/out.pdf'));

Đã trả lời ngày 22 tháng 12 năm 2021 lúc 15:24Dec 22, 2021 at 15:24

Vì chúng tôi đang sử dụng báo cáo của JS với container docker, vì vậy chúng tôi đã phải đối mặt với vấn đề thực thi lỗi sinh sản wkhtmltopdf.exe trong khi hiển thị PDF trong hệ thống Windows 10.

Cách chúng tôi đã giải quyết:- Trong gói, JSON Chúng tôi đã thêm gói "wkhtmltopdf-installer" để nó được cập nhật wkhtmltopdf.exe là 64bit.in package,json we added "wkhtmltopdf-installer" package explicitly so it's updated wkhtmltopdf.exe as 64bit.

{"wkhtmltopdf-installer": "~ 0.3.2"}

Đã trả lời ngày 4 tháng 8 năm 2020 lúc 4:59Aug 4, 2020 at 4:59

this.wkhtmltopdf = async function () {
    try {
        console.log("createpdf")
        var response = await $http({
            url: '/wkhtmltopdf',
            method: "POST",
            responseType: 'blob',
            data:{"b":"XXX"}
        });

        if (response.status != 200) {
            this.message = this.gs("downloadFailed", "There was an error downloading the file");
            return;
        }

        var blob = new Blob([response.data], { type: 'application/*' });
        saveAs(blob, 'test.pdf');
    } catch (err) {
        $window.alert('There was an error in getting the file');
    }
};

Tôi đã cài đặt công cụ từ trang web chính thức của họ theo khuyến nghị của người dùng trong các chủ đề khác và trong NPM chính thức: https://www.npmjs.com/package/wkhtmltopdf
https://www.npmjs.com/package/wkhtmltopdf

C:\Users\Samer\Desktop\ALL fineon projects\azure-fineon-webapp-fo\node_modules\wkhtmltopdf\index.js:161
    throw new Error(err); // critical error
    ^

Error: Error: spawn wkhtmltopdf ENOENT
    at ChildProcess. (C:\Users\xxx\Desktop\ALL xxprojects\azure-xx-webapp-fo\node_modules\wkhtmltopdf\index.js:161:11)
    at Object.onceWrapper (events.js:286:20)
    at ChildProcess.emit (events.js:198:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)