Cannot create pdf of current electron browser. Have problem with method printToPDF

With the code snippets below, I am trying to create a pdf file showing the contents of the electron browser.

I am seeing first three console logs, but cannot see the one right after the printToPDF method.
Looks like it got stuck reaching printToPDF method and I have no error messages to share.
Any idea why cannot go further ?

Main.js:

"use strict";
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("print-to-pdf", function (event) {
console.log("reached to ipc");
const pdfPath = "C:\Temp\print.pdf";
console.log("pdfPath:" + pdfPath);
const win = BrowserWindow.fromWebContents(event.sender);
console.log("created const win");
win.webContents.printToPDF({printBackground: true, landscape: true},function (error, data) {
    console.log("reached to printToPDF method:");
    if (error) throw error;
    fs.writeFile(pdfPath, data, function (error) {
    if (error) {
        throw error;
    }
    shell.openExternal("file://" + pdfPath);
    event.sender.send("wrote-pdf", pdfPath);
    });
});
});