Skip to content

Commit

Permalink
switch the pdf bakend to QuestPDF
Browse files Browse the repository at this point in the history
  • Loading branch information
majorsilence committed Nov 2, 2024
1 parent c09ff07 commit d017fc7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 190 deletions.
6 changes: 6 additions & 0 deletions TownSuite.TwainScanner.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 26 additions & 41 deletions TownSuite.TwainScanner/MainFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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");
}


Expand Down Expand Up @@ -103,7 +98,7 @@ private void MainFrame_Load(object sender, EventArgs e)
DeleteFiles();

LoadTwainDrivers();
#if INCLUDE_TELERIK
#if INCLUDE_WIA
LoadWIADrivers();
GetColors();
#endif
Expand All @@ -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;
Expand Down Expand Up @@ -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());

Expand All @@ -222,7 +217,7 @@ private void btnWIAScan_Click(object sender, EventArgs e)

}

#if INCLUDE_TELERIK
#if INCLUDE_WIA
private void LoadWIADrivers()
{
// Clear the ListBox.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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":
Expand All @@ -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();
Expand Down Expand Up @@ -1007,7 +998,6 @@ private string SavePNG()
return "";
}

#if INCLUDE_TELERIK
private void SavePDF()
{
string[] sa = null;
Expand All @@ -1017,36 +1007,31 @@ private void SavePDF()
List<string> 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)
Expand All @@ -1056,7 +1041,7 @@ private void SourceListBox_SelectedValueChanged(object sender, EventArgs e)
// LoadScanPropertyValues();
//});
//t.Wait(1000);
#if INCLUDE_TELERIK
#if INCLUDE_WIA
LoadScanPropertyValues();
#endif

Expand Down
1 change: 0 additions & 1 deletion TownSuite.TwainScanner/Ocr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion TownSuite.TwainScanner/Scanner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if INCLUDE_TELERIK
#if INCLUDE_WIA
using System;
using System.Runtime.InteropServices;
using WIA;
Expand Down
53 changes: 29 additions & 24 deletions TownSuite.TwainScanner/TwainScanner.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<RootNamespace>TownSuite.TwainScanner</RootNamespace>
<TargetFrameworks>net48;net8.0-windows</TargetFrameworks>
<RuntimeIdentifiers>win;win-x86;win-x64</RuntimeIdentifiers>
<AssemblyName>TownSuite.TwainScanner</AssemblyName>
<AssemblyTitle>TownSuite.TwainScanner</AssemblyTitle>
<Company>TownSuite</Company>
<Product>TownSuite.TwainScanner</Product>
<Description>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.</Description>
<Copyright>Copyright © SARAFF 2011</Copyright>
<AssemblyVersion>1.0.36</AssemblyVersion>
<FileVersion>1.0.36</FileVersion>
<PackageVersion>1.0.36</PackageVersion>
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<RootNamespace>TownSuite.TwainScanner</RootNamespace>
<TargetFrameworks>net48;net8.0-windows</TargetFrameworks>
<RuntimeIdentifiers>win;win-x86;win-x64</RuntimeIdentifiers>
<AssemblyName>TownSuite.TwainScanner</AssemblyName>
<AssemblyTitle>TownSuite.TwainScanner</AssemblyTitle>
<Company>TownSuite</Company>
<Product>TownSuite.TwainScanner</Product>
<Description>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.</Description>
<Copyright>Copyright © SARAFF 2011</Copyright>
<AssemblyVersion>1.0.36</AssemblyVersion>
<FileVersion>1.0.36</FileVersion>
<PackageVersion>1.0.36</PackageVersion>
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Platforms>AnyCPU;x86;x64</Platforms>
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<!-- <DefineConstants>INCLUDE_WIA</DefineConstants> -->
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile />
Expand Down Expand Up @@ -48,12 +49,12 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Security" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Security" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Update="MainFrame.cs">
Expand Down Expand Up @@ -114,6 +115,10 @@
<ItemGroup>
<EmbeddedResource Include="Resources\scanner.bmp" />
</ItemGroup>
<ItemGroup>
<!-- <PackageReference Include="Wia.Interop.Townsuite.x86" Version="1.0.1" /> -->
<PackageReference Include="QuestPDF" Version="2024.10.2" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net48' ">
<FrameworkReference Include="Microsoft.WindowsDesktop.App" />
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
Expand Down
98 changes: 0 additions & 98 deletions TownSuite.TwainScanner/TwainScanner_enhanced.csproj

This file was deleted.

Loading

0 comments on commit d017fc7

Please sign in to comment.