Я пытаюсь распечатать страницу на электронном js, я пытался следовать пошаговому видео на YouTube и пытался скопировать каждый код, который, как говорят люди, работал, но когда я пробую, ничего не происходит, ни печатной страницы, ни ошибка в журнале консоли. документация на электронном веб-сайте больше не работает, или я сделал что-то не так в коде?
этот код ниже - то, что я следовал из определенного видео на YouTube, из того, что я видел, что оно должно работать
это мой главный. js
const electron = require('electron');
const { Menu } = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const url = require('url');
const isDev = require('electron-is-dev');
const fs = require('fs');
const os = require('os');
const ipc = electron.ipcMain;
const shell =electron.shell;
let mainWindow;
ipc.on('print-to-pdf', function(event){
const pdfpath = path.join(os.tmpdir(), 'print.pdf');
const win = BrowserWindow.fromWebContents(event.sender);
win.webContents.printToPDF({}, function(error, data){
if(error) return console.log(error.message);
fs.writeFile(pdfpath, data, function(err){
if(err) return console.log(err.message);
shell.openExternal('file://'+pdfpath );
event.sender.send('wrote-pdf', pdfpath);
})
})
});
это мой рендерер. js
const ipc = require('electron').ipcRenderer;
const printpdfbutton = document.getElementById('print-pdf');
printpdfbutton.addEventListener('click', function(event){
ipc.send('print-to-pdf');
});
ipc.on('wrote-pdf', function(event, path){
const message = `wrote PDF to : ${path}`;
document.getElementById('pdf-path').innerHTML = message;
});
это мой индекс. html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="podium.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<button id='print-pdf'>Convert to PDF</button>
<label id='pdf-path'></label>
<!-- Don't go beyond this -->
</body>
<script>
require('./renderer.js');
</script>
</html>
возможно, решение состоит в том, чтобы использовать зависимость или есть другой код, который работает?
, пожалуйста, помогите мне, спасибо