This is my code to export to PDF in Electron 8.1.0 on Windows 10:
ipcMain.on('export-pdf', (event, pdfPath) => {
const BrowserWindow = require('electron').BrowserWindow;
const win = BrowserWindow.getFocusedWindow();
win.webContents.printToPDF({
marginsType: 2,
printBackground: false,
printSelectionOnly: false,
landscape: false,
pageSize: 'Letter',
scaleFactor: 100
}).then(data => {
fs.writeFile(`${pdfPath}.pdf`, data, (error) => {
if (error) throw error;
event.sender.send('export-pdf-end', true);
})
}).catch(error => {
logger.error(`Error at save PDF in ${pdfPath}`, error);
event.sender.send('export-pdf-end', false);
});
});
Everything works fine except the page size. Regardless of the value that I configure, the generated pdf always measures 11.69in x 16.54in and I need the exact letter format (8.5in x 11in). I have tried all the options including height and width in microns but it doesn't work.
UPDATE
I tried Electron 8.0.0 on Linux (Debian 10) and it worked perfect. I need to try the exact version on Linux and version 9 of Electron on Windows (when I have a better and cheaper Internet connection)
Any help? Thanks in advance.