title: Javascript-Electron Cannot create pdf of current browser. Have problem with method printToPDF
body: <p>With the code snippets below, I am trying to create a pdf file showing the contents of the electron browser.</p>
  <p>I am seeing first three console logs, but cannot see the one right after the <code>printToPDF</code> method.<br />
  Looks like it got stuck reaching <code>printToPDF</code> method and I have no error messages to share.<br />
  Any idea why cannot go further ?</p>
  <p>Main.js:</p>
  <pre><code>&quot;use strict&quot;;
  const electron = require('electron')
  const fs = require('fs')
  const app = electron.app
  const BrowserWindow = electron.BrowserWindow
  const ipc = electron.ipcMain
  const path = require('path')
  const url = require('url')
  const shell = electron.shell
  
  ipc.on(&quot;print-to-pdf&quot;, function (event) {
  console.log(&quot;reached to ipc&quot;);
  const pdfPath = &quot;C:\\Temp\\print.pdf&quot;;
  console.log(&quot;pdfPath:&quot; + pdfPath);
  const win = BrowserWindow.fromWebContents(event.sender);
  console.log(&quot;created const win&quot;);
  win.webContents.printToPDF({printBackground: true, landscape: true},function (error, data) {
      console.log(&quot;reached to printToPDF method:&quot;);
      if (error) throw error;
      fs.writeFile(pdfPath, data, function (error) {
      if (error) {
          throw error;
      }
      shell.openExternal(&quot;file://&quot; + pdfPath);
      event.sender.send(&quot;wrote-pdf&quot;, pdfPath);
      });
  });
  });
  </code></pre>