Files
Electron.NET/ElectronNET.WebApp/Controllers/PdfController.cs
Konstantin Gross eee84d214e App API:
* Summaries rewritten
* Added new parameters / Removed not supported parameters
* Added some new methods like appFocus(options), appHasSingleLock, etc.
2020-05-31 03:09:54 +02:00

43 lines
1.4 KiB
C#

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();
}
}
}