From d017fc766d155af3e3200b3f3e13257610b934a8 Mon Sep 17 00:00:00 2001 From: Peter Gill Date: Sat, 2 Nov 2024 12:39:32 -0230 Subject: [PATCH] switch the pdf bakend to QuestPDF --- TownSuite.TwainScanner.sln | 6 ++ TownSuite.TwainScanner/MainFrame.cs | 67 +++++-------- TownSuite.TwainScanner/Ocr.cs | 1 - TownSuite.TwainScanner/Scanner.cs | 2 +- TownSuite.TwainScanner/TwainScanner.csproj | 53 +++++----- .../TwainScanner_enhanced.csproj | 98 ------------------- TownSuite.TwainScanner_enhanced.sln | 25 ----- 7 files changed, 62 insertions(+), 190 deletions(-) delete mode 100644 TownSuite.TwainScanner/TwainScanner_enhanced.csproj delete mode 100644 TownSuite.TwainScanner_enhanced.sln diff --git a/TownSuite.TwainScanner.sln b/TownSuite.TwainScanner.sln index cbeb0d5..fa99fdb 100644 --- a/TownSuite.TwainScanner.sln +++ b/TownSuite.TwainScanner.sln @@ -7,12 +7,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TwainScanner", "TownSuite.T EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Debug|x64.ActiveCfg = Debug|x64 + {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Debug|x64.Build.0 = Debug|x64 {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Debug|x86.ActiveCfg = Debug|x86 {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Debug|x86.Build.0 = Debug|x86 + {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Release|x64.ActiveCfg = Release|x64 + {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Release|x64.Build.0 = Release|x64 {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Release|x86.ActiveCfg = Release|x86 {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Release|x86.Build.0 = Release|x86 EndGlobalSection diff --git a/TownSuite.TwainScanner/MainFrame.cs b/TownSuite.TwainScanner/MainFrame.cs index 1c56b79..d0bc420 100644 --- a/TownSuite.TwainScanner/MainFrame.cs +++ b/TownSuite.TwainScanner/MainFrame.cs @@ -7,16 +7,13 @@ using System.Windows.Forms; using System.Linq; using System.Collections; -#if INCLUDE_TELERIK +#if INCLUDE_WIA using WIA; -using Telerik.Windows.Documents.Fixed.Model; -using Telerik.Windows.Documents.Fixed.Model.Resources; -using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf; -using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export; -using Telerik.Windows.Documents.Model; #endif using System.Threading; using System.Text.RegularExpressions; +using QuestPDF.Fluent; +using System.Windows.Media; namespace TownSuite.TwainScanner { @@ -25,7 +22,7 @@ internal partial class MainFrame : Form private Twain32 _twain; readonly string DirText; -#if INCLUDE_TELERIK +#if INCLUDE_WIA private DeviceManager deviceManager; bool removeWia = false; #else @@ -71,8 +68,6 @@ private void MainFrame_Load(object sender, EventArgs e) if (removeWia) { tabScanDrivers.TabPages.RemoveByKey("tpWIAScan"); - cmbImageType.Items.Remove("PDF"); - cmbTwainImageType.Items.Remove("PDF"); } @@ -103,7 +98,7 @@ private void MainFrame_Load(object sender, EventArgs e) DeleteFiles(); LoadTwainDrivers(); -#if INCLUDE_TELERIK +#if INCLUDE_WIA LoadWIADrivers(); GetColors(); #endif @@ -113,7 +108,7 @@ private void MainFrame_Load(object sender, EventArgs e) sourceTwianListBox.SelectedItem = UserTwainScanner; //cmbTwainImageType.SelectedIndex = 0; -#if INCLUDE_TELERIK +#if INCLUDE_WIA //WIA Settings cmbImageType.SelectedIndex = 0; cmbColor.SelectedIndex = 0; @@ -213,7 +208,7 @@ private void LoadTwainDrivers() private void btnWIAScan_Click(object sender, EventArgs e) { -#if INCLUDE_TELERIK +#if INCLUDE_WIA //Start Scanning using a Thread //Task.Factory.StartNew(StartScanning).ContinueWith(result => TriggerScan()); @@ -222,7 +217,7 @@ private void btnWIAScan_Click(object sender, EventArgs e) } -#if INCLUDE_TELERIK +#if INCLUDE_WIA private void LoadWIADrivers() { // Clear the ListBox. @@ -603,7 +598,7 @@ private void mnuAcquire_Click(object sender, EventArgs e) { switch (tabScanDrivers.SelectedTab.Name) { -#if INCLUDE_TELERIK +#if INCLUDE_WIA case "tpWIAScan": StartWIAScanning(); break; @@ -739,12 +734,10 @@ private void mnuSave_Click(object sender, EventArgs e) case "jpeg": SaveJPEG(); break; -#if INCLUDE_TELERIK case "pdf": //Save pdf SavePDF(); break; -#endif } break; case "tpWIAScan": @@ -755,12 +748,10 @@ private void mnuSave_Click(object sender, EventArgs e) //Save tiff SaveTIFF(); break; -#if INCLUDE_TELERIK case "pdf": //Save pdf SavePDF(); break; -#endif case "png": //Save PNG' SavePNG(); @@ -1007,7 +998,6 @@ private string SavePNG() return ""; } -#if INCLUDE_TELERIK private void SavePDF() { string[] sa = null; @@ -1017,36 +1007,31 @@ private void SavePDF() List SortedList = UnSortList.OrderBy(p => PadNumbers(p)).ToList(); sa = SortedList.ToArray(); - RadFixedDocument document = new RadFixedDocument(); + QuestPDF.Settings.License = QuestPDF.Infrastructure.LicenseType.Community; - foreach (string image in sa) + var pdf = Document.Create(handler => { - using (Stream stream = File.OpenRead(image)) + foreach (string image in sa) { - ImageSource imageSource = new ImageSource(stream); - RadFixedPage page = document.Pages.AddPage(); - //page.Size = new System.Windows.Size(imageSource.Width, imageSource.Height); - page.Content.AddImage(imageSource); - if (cmbResolution.SelectedValue != null && (int)(cmbResolution.SelectedValue) <= 100) - { - page.Size = PaperTypeConverter.ToSize(PaperTypes.Letter); - } - else + handler.Page(page => { - page.Size = new System.Windows.Size(imageSource.Width, imageSource.Height); - } + page.Size(QuestPDF.Helpers.PageSizes.Letter); + page.Margin(2, QuestPDF.Infrastructure.Unit.Centimetre); + page.PageColor(QuestPDF.Helpers.Colors.White); + page.DefaultTextStyle(x => x.FontSize(20)); + using (var inputStream = new FileStream(image, FileMode.Open)) + { + page.Content().Image(inputStream).FitArea(); + } + }); } - } - - PdfFormatProvider provider = new PdfFormatProvider(); + }); using (Stream output = new FileStream(Path.Combine(DirText, "tmpScan.pdf"), FileMode.OpenOrCreate)) { - provider.ExportSettings.ImageQuality = ImageQuality.High; - provider.Export(document, output); + pdf.GeneratePdf(output); } - } -#endif + #endregion private void SourceListBox_SelectedValueChanged(object sender, EventArgs e) @@ -1056,7 +1041,7 @@ private void SourceListBox_SelectedValueChanged(object sender, EventArgs e) // LoadScanPropertyValues(); //}); //t.Wait(1000); -#if INCLUDE_TELERIK +#if INCLUDE_WIA LoadScanPropertyValues(); #endif diff --git a/TownSuite.TwainScanner/Ocr.cs b/TownSuite.TwainScanner/Ocr.cs index 2ce6ec1..d564c1e 100644 --- a/TownSuite.TwainScanner/Ocr.cs +++ b/TownSuite.TwainScanner/Ocr.cs @@ -10,7 +10,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using System.Windows.Documents; using System.Windows.Forms; namespace TownSuite.TwainScanner diff --git a/TownSuite.TwainScanner/Scanner.cs b/TownSuite.TwainScanner/Scanner.cs index 7dcce93..ab54a5f 100644 --- a/TownSuite.TwainScanner/Scanner.cs +++ b/TownSuite.TwainScanner/Scanner.cs @@ -1,4 +1,4 @@ -#if INCLUDE_TELERIK +#if INCLUDE_WIA using System; using System.Runtime.InteropServices; using WIA; diff --git a/TownSuite.TwainScanner/TwainScanner.csproj b/TownSuite.TwainScanner/TwainScanner.csproj index 99ce81f..5e481b1 100644 --- a/TownSuite.TwainScanner/TwainScanner.csproj +++ b/TownSuite.TwainScanner/TwainScanner.csproj @@ -1,24 +1,25 @@  - x86 - WinExe - TownSuite.TwainScanner - net48;net8.0-windows - win;win-x86;win-x64 - TownSuite.TwainScanner - TownSuite.TwainScanner - TownSuite - TownSuite.TwainScanner - Allows you to control work of flatbed scanner, web and digital camera and any other TWAIN device from .NET environment. You can use this library in your programs written in any programming languages compatible with .NET technology. - Copyright © SARAFF 2011 - 1.0.36 - 1.0.36 - 1.0.36 - bin\$(Platform)\$(Configuration)\ - MinimumRecommendedRules.ruleset + x86 + WinExe + TownSuite.TwainScanner + net48;net8.0-windows + win;win-x86;win-x64 + TownSuite.TwainScanner + TownSuite.TwainScanner + TownSuite + TownSuite.TwainScanner + Allows you to control work of flatbed scanner, web and digital camera and any other TWAIN device from .NET environment. You can use this library in your programs written in any programming languages compatible with .NET technology. + Copyright © SARAFF 2011 + 1.0.36 + 1.0.36 + 1.0.36 + bin\$(Platform)\$(Configuration)\ + MinimumRecommendedRules.ruleset AnyCPU;x86;x64 - true - true + true + true + @@ -48,12 +49,12 @@ True - - - - - - + + + + + + @@ -114,6 +115,10 @@ + + + + diff --git a/TownSuite.TwainScanner/TwainScanner_enhanced.csproj b/TownSuite.TwainScanner/TwainScanner_enhanced.csproj deleted file mode 100644 index 8c7d0ce..0000000 --- a/TownSuite.TwainScanner/TwainScanner_enhanced.csproj +++ /dev/null @@ -1,98 +0,0 @@ - - - x86 - WinExe - TownSuite.TwainScanner - net48;net8.0-windows - win;win-x86;win-x64 - TownSuite.TwainScanner - TownSuite.TwainScanner - TownSuite - TownSuite.TwainScanner - Allows you to control work of flatbed scanner, web and digital camera and any other TWAIN device from .NET environment. You can use this library in your programs written in any programming languages compatible with .NET technology. - Copyright © SARAFF 2011 - 1.0.36 - 1.0.36 - 1.0.36 - bin\$(Platform)\$(Configuration)\ - MinimumRecommendedRules.ruleset - AnyCPU;x86 - true - true - INCLUDE_TELERIK - - - - - - NET2 - - - TownSuite.TwainScanner.Program - - - full - - - bin\$(Configuration)\Saraff.Twain.XML - pdbonly - - - - True - - - - - - - - - - - - - Form - - - MainFrame.cs - - - True - True - Resources.resx - - - Form - - - SelectSourceForm.cs - - - Component - - - - - MainFrame.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - SelectSourceForm.cs - - - Twain32.cs - - - - - - - - - - \ No newline at end of file diff --git a/TownSuite.TwainScanner_enhanced.sln b/TownSuite.TwainScanner_enhanced.sln deleted file mode 100644 index ca796d0..0000000 --- a/TownSuite.TwainScanner_enhanced.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32901.215 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TwainScanner_enhanced", "TownSuite.TwainScanner\TwainScanner_enhanced.csproj", "{658F9851-4D1C-4D57-904E-F9D7DA7F24FC}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Debug|x86.ActiveCfg = Debug|x86 - {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Debug|x86.Build.0 = Debug|x86 - {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Release|x86.ActiveCfg = Release|x86 - {658F9851-4D1C-4D57-904E-F9D7DA7F24FC}.Release|x86.Build.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {0737D522-BA75-4654-9D20-CEC80DB785D1} - EndGlobalSection -EndGlobal