Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron.webContents.printToPDF not working with NextJS page #494

Open
Matse2005 opened this issue Aug 30, 2024 · 0 comments
Open

electron.webContents.printToPDF not working with NextJS page #494

Matse2005 opened this issue Aug 30, 2024 · 0 comments

Comments

@Matse2005
Copy link

Matse2005 commented Aug 30, 2024

My current code is:

ipcMain.on('print', (event, url, id) => {
  console.log('Print to pdf started')
  console.log(id)
  var filepath = path.join(app.getPath('desktop'), 'factuur-' + id + '.pdf')

  var options = {
    // marginsType: 0,
    pageSize: 'A4' as 'A4',  // This needs to be one of the specific allowed string literals
    printBackground: true,
    printSelectionOnly: true,
    landscape: false
  }


  let win = new BrowserWindow({
    show: false,
    webPreferences: {
      nodeIntegration: true
    }
  });

  // console.log(url)
  if (url.startsWith('http'))
    win.loadURL(url);
  else if (isProd)
    win.loadURL('app://.' + url);
  else
    win.loadURL(`http://localhost:${process.argv[2]}` + url);

  win.webContents.on('did-finish-load', () => {
    win.webContents.printToPDF(options).then(data => {
      fs.writeFile(filepath, data, function (err) {
        if (err) {
          console.log(err);
        } else {
          console.log('PDF Generated Successfully');
        }
        console.log('Done')
      });
    }).catch(error => {
      console.log(error)
    });
  });
})

Now is win.webContents.printToPDF not working with a NextJS page, only with an external website even if that one is a NextJS based website. Am I doing something wrong or is this just a known or unknow issue. It currently retuns a blank page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant