Printing: Replace PDFtoPrinter with PdfiumViewer
This commit is contained in:
@ -153,7 +153,7 @@ namespace Elwig.Documents {
|
|||||||
|
|
||||||
public async Task Print(int copies = 1) {
|
public async Task Print(int copies = 1) {
|
||||||
if (PdfPath == null) throw new InvalidOperationException("Pdf file has not been generated yet");
|
if (PdfPath == null) throw new InvalidOperationException("Pdf file has not been generated yet");
|
||||||
await Pdf.Print(PdfPath, copies);
|
await Pdf.Print(PdfPath, copies, DoublePaged);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Show() {
|
public void Show() {
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2739.15" />
|
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2739.15" />
|
||||||
<PackageReference Include="NJsonSchema" Version="11.0.2" />
|
<PackageReference Include="NJsonSchema" Version="11.0.2" />
|
||||||
|
<PackageReference Include="PdfiumViewer" Version="2.13.0" />
|
||||||
|
<PackageReference Include="PdfiumViewer.Native.x86_64.no_v8-no_xfa" Version="2018.4.8.256" />
|
||||||
<PackageReference Include="RazorLight" Version="2.3.1" />
|
<PackageReference Include="RazorLight" Version="2.3.1" />
|
||||||
<PackageReference Include="ScottPlot.WPF" Version="5.0.39" />
|
<PackageReference Include="ScottPlot.WPF" Version="5.0.39" />
|
||||||
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
|
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
|
||||||
|
@ -8,15 +8,12 @@ using System.Windows;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using PdfiumViewer;
|
||||||
|
using System.Drawing.Printing;
|
||||||
|
|
||||||
namespace Elwig.Helpers.Printing {
|
namespace Elwig.Helpers.Printing {
|
||||||
public static class Pdf {
|
public static class Pdf {
|
||||||
|
|
||||||
private static readonly string PdfToPrinter = new string[] { App.ExePath }
|
|
||||||
.Union(Environment.GetEnvironmentVariable("PATH")?.Split(';') ?? [])
|
|
||||||
.Select(x => Path.Combine(x, "PDFtoPrinter.exe"))
|
|
||||||
.Where(File.Exists)
|
|
||||||
.FirstOrDefault() ?? throw new FileNotFoundException("PDFtoPrinter executable not found");
|
|
||||||
private static readonly string WinziPrint = new string[] { App.ExePath }
|
private static readonly string WinziPrint = new string[] { App.ExePath }
|
||||||
.Union(Environment.GetEnvironmentVariable("PATH")?.Split(';') ?? [])
|
.Union(Environment.GetEnvironmentVariable("PATH")?.Split(';') ?? [])
|
||||||
.Select(x => Path.Combine(x, "WinziPrint.exe"))
|
.Select(x => Path.Combine(x, "WinziPrint.exe"))
|
||||||
@ -91,21 +88,24 @@ namespace Elwig.Helpers.Printing {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task Print(string path, int copies = 1) {
|
public static async Task Print(string path, int copies = 1, bool doublePaged = false) {
|
||||||
|
await Print(path, new() {
|
||||||
|
Copies = (short)copies,
|
||||||
|
Collate = true,
|
||||||
|
Duplex = doublePaged ? Duplex.Vertical : Duplex.Simplex,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task Print(string path, PrinterSettings settings) {
|
||||||
try {
|
try {
|
||||||
var p = new Process() { StartInfo = new() {
|
using var doc = PdfDocument.Load(path);
|
||||||
FileName = PdfToPrinter,
|
using var printDoc = doc.CreatePrintDocument(PdfPrintMode.CutMargin);
|
||||||
CreateNoWindow = true,
|
printDoc.PrinterSettings = settings;
|
||||||
UseShellExecute = false,
|
printDoc.Print();
|
||||||
} };
|
|
||||||
p.StartInfo.ArgumentList.Add(path);
|
|
||||||
p.StartInfo.ArgumentList.Add("/s");
|
|
||||||
p.StartInfo.ArgumentList.Add($"copies={copies}");
|
|
||||||
p.Start();
|
|
||||||
await p.WaitForExitAsync();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MessageBox.Show("Beim Drucken ist ein Fehler aufgetreten:\n\n" + e.Message, "Fehler beim Drucken", MessageBoxButton.OK, MessageBoxImage.Error);
|
MessageBox.Show("Beim Drucken ist ein Fehler aufgetreten:\n\n" + e.Message, "Fehler beim Drucken", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
}
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -706,8 +706,7 @@ namespace Elwig.Windows {
|
|||||||
private async void PrintButton_Click(object sender, RoutedEventArgs evt) {
|
private async void PrintButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
if (PrintDocument == null) return;
|
if (PrintDocument == null) return;
|
||||||
PrintButton.IsEnabled = false;
|
PrintButton.IsEnabled = false;
|
||||||
var res = MessageBox.Show($"Sollen {PrintDocument.Pages} Blätter ({PrintDocument.TotalPages} Seiten) gedruckt werden?\n" +
|
var res = MessageBox.Show($"Sollen {PrintDocument.Pages} Blätter ({PrintDocument.TotalPages} Seiten) gedruckt werden?",
|
||||||
$"Sind die \"Duplex-Einstellungen\" des Standarddruckers entsprechend eingestellt (doppelseitig bzw. einseitig)?",
|
|
||||||
"Rundschreiben drucken", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
|
"Rundschreiben drucken", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
|
||||||
if (res == MessageBoxResult.Yes) {
|
if (res == MessageBoxResult.Yes) {
|
||||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
::mkdir "C:\Program Files\Elwig"
|
::mkdir "C:\Program Files\Elwig"
|
||||||
::curl --fail -s -L "https://github.com/emendelson/pdftoprinter/raw/main/PDFtoPrinter.exe" -z "C:\Program Files\Elwig\PDFtoPrinter.exe" -o "C:\Program Files\Elwig\PDFtoPrinter.exe"
|
|
||||||
mkdir "C:\ProgramData\Elwig\resources"
|
mkdir "C:\ProgramData\Elwig\resources"
|
||||||
copy /b /y Documents\*.css "C:\ProgramData\Elwig\resources"
|
copy /b /y Documents\*.css "C:\ProgramData\Elwig\resources"
|
||||||
copy /b /y Documents\*.cshtml "C:\ProgramData\Elwig\resources"
|
copy /b /y Documents\*.cshtml "C:\ProgramData\Elwig\resources"
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
</Task>
|
</Task>
|
||||||
</UsingTask>
|
</UsingTask>
|
||||||
<Target Name="CustomBeforeBuild" BeforeTargets="BeforeBuild">
|
<Target Name="CustomBeforeBuild" BeforeTargets="BeforeBuild">
|
||||||
<Exec Command="curl --fail -s -L "https://github.com/emendelson/pdftoprinter/raw/main/PDFtoPrinter.exe" -z "$(ProjectDir)\Files\PDFtoPrinter.exe" -o "$(ProjectDir)\Files\PDFtoPrinter.exe"" />
|
|
||||||
<Exec Command="dotnet publish "$(ProjectDir)\..\Elwig\Elwig.csproj" "/p:PublishProfile=$(ProjectDir)\..\Elwig\Properties\PublishProfiles\FolderProfile.pubxml"" />
|
<Exec Command="dotnet publish "$(ProjectDir)\..\Elwig\Elwig.csproj" "/p:PublishProfile=$(ProjectDir)\..\Elwig\Properties\PublishProfiles\FolderProfile.pubxml"" />
|
||||||
<GetFileVersion AssemblyPath="..\Elwig\bin\Publish\Elwig.exe">
|
<GetFileVersion AssemblyPath="..\Elwig\bin\Publish\Elwig.exe">
|
||||||
<Output TaskParameter="Version" PropertyName="ElwigFileVersion" />
|
<Output TaskParameter="Version" PropertyName="ElwigFileVersion" />
|
||||||
@ -36,7 +35,6 @@
|
|||||||
</Target>
|
</Target>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Files\config.ini" />
|
<None Include="Files\config.ini" />
|
||||||
<None Include="Files\PDFtoPrinter.exe" />
|
|
||||||
<None Include="Files\WinziPrint.exe" />
|
<None Include="Files\WinziPrint.exe" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -10,9 +10,6 @@
|
|||||||
<Component Directory="InstallFolder">
|
<Component Directory="InstallFolder">
|
||||||
<File Source="$(ProjectDir)\Files\WinziPrint.exe" Id="WinziPrint.exe"/>
|
<File Source="$(ProjectDir)\Files\WinziPrint.exe" Id="WinziPrint.exe"/>
|
||||||
</Component>
|
</Component>
|
||||||
<Component Directory="InstallFolder">
|
|
||||||
<File Source="$(ProjectDir)\Files\PDFtoPrinter.exe" Id="PDFtoPrinter.exe"/>
|
|
||||||
</Component>
|
|
||||||
</ComponentGroup>
|
</ComponentGroup>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
</Wix>
|
</Wix>
|
||||||
|
Reference in New Issue
Block a user