Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Javascript-Electron Cannot create pdf of current 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);
    });
});
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!