-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensions.cs
More file actions
28 lines (25 loc) · 1.01 KB
/
Extensions.cs
File metadata and controls
28 lines (25 loc) · 1.01 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
using Avalonia;
namespace Avae.Printables
{
public static class Extensions
{
public static AppBuilder UseXpsPrintables(this AppBuilder builder)
{
var implementation = Printable.Default;
if(implementation is null)
throw new ArgumentNullException(nameof(implementation), "UsePrintables must be set before.");
if (implementation is PrintingService service)
{
string ConvertXpsToPdf(string file)
{
var path = Path.GetTempPath() + "temp.pdf";
PdfSharp.Xps.XpsConverter.Convert(file, path, 0);
return path;
}
service.Conversions.Add(".xps", (file) => Task.FromResult(ConvertXpsToPdf(file)));
service.Entries.Add(".xps", (title, file) => Task.FromResult<PrinterBase>(new PdfPrinter(PrintingService.GetActiveWindow(), title, ConvertXpsToPdf(file))));
}
return builder;
}
}
}