forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdfController.cs
More file actions
43 lines (39 loc) · 1.44 KB
/
Copy pathPdfController.cs
File metadata and controls
43 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using ElectronNET.API;
using ElectronNET.API.Entities;
namespace ElectronNET.WebApp.Controllers
{
public class PdfController : Controller
{
public IActionResult Index()
{
if (HybridSupport.IsElectronActive)
{
Electron.IpcMain.On("print-pdf", async (args) =>
{
BrowserWindow mainWindow = Electron.WindowManager.BrowserWindows.First();
var saveOptions = new SaveDialogOptions
{
Title = "Save an PDF-File",
DefaultPath = await Electron.App.GetPathAsync(PathName.Documents),
Filters = new FileFilter[]
{
new FileFilter { Name = "PDF", Extensions = new string[] { "pdf" } }
}
};
var path = await Electron.Dialog.ShowSaveDialogAsync(mainWindow, saveOptions);
if (await mainWindow.WebContents.PrintToPDFAsync(path))
{
await Electron.Shell.OpenExternalAsync("file://" + path);
}
else
{
Electron.Dialog.ShowErrorBox("Error", "Failed to create pdf file.");
}
});
}
return View();
}
}
}