So I have this Electron app and in one of the .html-files I link another script that provides some utility-functions to the program and one of those is this one:
function openPDF(filePath){
let pdfWindow = new electron.remote.BrowserWindow({
icon: './build/icon.png',
width: 1200,
height: 800,
webPreferences: {
plugins: true
}
});
pdfWindow.loadURL(url.format({
pathname: filePath,
protocol: 'file:',
slashes: true
}));
pdfWindow.setMenu(null);
pdfWindow.on("closed", function () {
pdfWindow = null
});
}
So this should use the integrated PDF-Viewer of Electron (which uses Chromium) to open the PDF in a new window. I used the infamous plugins: true
, I tried through most of the thousands of preferences you can define for a BrowserWindow but it always opens the window and then starts to download the file instead of displaying it.
I triple checked the file path, the "imports" etc., updated everything but I can't seem to find the problem. Electron natively supports this since 1.6.4 but it doesn't work for me.
Help me, Stack Overflow, you are my only hope.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…