mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-05 13:54:47 +00:00
* Summaries rewritten * Added new parameters / Removed not supported parameters * Added some new methods like appFocus(options), appHasSingleLock, etc.
43 lines
1.4 KiB
C#
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();
|
|
}
|
|
}
|
|
} |