[英]Is there any way to change the title and save type of file dialog on electron?
[英]Electron Save Dialog Specify File Type
我在电子应用程序中有一个保存对话框。 目前,当用户点击“保存”时,它将使用默认名称和文件扩展名foo.pdf进行保存。
更改名称时,不会添加文件扩展名。
有没有办法确保将.pdf文件扩展名添加到所有文件名?
document.getElementById("pdf-btn").onclick = function() {
var webv = document.getElementById('appview');
dialog.showSaveDialog({
defaultPath: '~/foo.pdf'
}, function(file_path) {
if (file_path) {
webv.printToPDF({}, function(err, data) {
if (err) {
dialog.showErrorBox('Error', err);
return;
}
fs.writeFile(file_path, data, function(err) {
if (err) {
dialog.showErrorBox('Error', err);
return;
}
// addext = file_path + ".pdf";
//
// save_pdf_path = addext;
save_pdf_path = file_path;
var message = "<p> Write PDF file: " + save_pdf_path + " successfully!</p>";
console.log(message);
});
});
}
});
}
通过添加以下代码,我能够指定文件扩展名。
dialog.showSaveDialog({
filters: [{
name: 'Adobe PDF',
extensions: ['pdf']
}]
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.