Skip to content

Commit 8c281ff

Browse files
authored
Add files via upload
1 parent 5e2a316 commit 8c281ff

File tree

6 files changed

+610
-0
lines changed

6 files changed

+610
-0
lines changed

C#/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>

C#/ImageWizHelper.cs

Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Runtime.InteropServices;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace ImageWizHelperCS
11+
{
12+
public enum Layout
13+
{
14+
A0,
15+
A1,
16+
A2,
17+
A3,
18+
A4,
19+
A5,
20+
A6,
21+
A7
22+
};
23+
24+
public enum ImageDPI
25+
{
26+
DPI_100 = 100,
27+
DPI_150 = 150,
28+
DPI_200 = 200,
29+
DPI_300 = 300,
30+
DPI_500 = 500,
31+
DPI_600 = 600
32+
};
33+
34+
public enum ResetOption
35+
{
36+
No_DPI_change, // DPI will not be resetted this case .
37+
ResetAllDPI, // Every image DPI will be resetted to selected DPI. Dimension also will be changed according to DPI
38+
ResetNonDPI // If DPI is not available then DPI will setted for the image. Dimension also will be changed according to DPI
39+
};
40+
41+
public enum ImageQuality
42+
{
43+
unknown = -1,
44+
Photo_Quality = 70,
45+
Document_Quality = 40,
46+
Compressed_Document = 20
47+
};
48+
49+
[StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Ansi)]
50+
public struct RECT
51+
{
52+
public Int32 left;
53+
public Int32 top;
54+
public Int32 right;
55+
public Int32 bottom;
56+
}
57+
58+
public enum ConversionType
59+
{
60+
CONVERSIONTYPE_NO_CONVERSION = 0,
61+
CONVERSIONTYPE_CONVERT_TO_BW = 1,
62+
CONVERSIONTYPE_CONVERT_TO_GREY = 2
63+
}
64+
65+
public class ImageWizHelper
66+
{
67+
const string DLL_NAME = "ImageWizHelper.dll";
68+
69+
[DllImport("ImageWizHelper.dll", SetLastError = true, CharSet = CharSet.Ansi)]
70+
static extern IntPtr Initialize(String LogFileName);
71+
72+
[DllImport("ImageWizHelper.dll", SetLastError = true, CharSet = CharSet.Ansi)]
73+
static extern Int32 Terminate(IntPtr ImageWizHelper);
74+
75+
[DllImport("ImageWizHelper.dll", SetLastError = true, CharSet = CharSet.Ansi)]
76+
static extern Int32 GetLastErrorCode();
77+
78+
[DllImport("ImageWizHelper.dll", SetLastError = true, CharSet = CharSet.Ansi)]
79+
static extern Int32 GetErrorDescription(Int32 error, StringBuilder desc_buffer, ref Int32 desc_len);//StringBuilder desc_buffer
80+
81+
82+
[DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
83+
static extern Int32 UnlockLibraryWithModuleIdentity(String licPath, StringBuilder err_buff);
84+
85+
[DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
86+
private static extern Int32 GetPageCountInImageFile(IntPtr ImageWizHelper, string filename, string pwd);
87+
88+
[DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
89+
private static extern Int32 getImageQuality(IntPtr ImageWizHelper, IntPtr objQuality);
90+
91+
[DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
92+
private static extern Int32 CompressToTIFF(IntPtr ImageWizHelper, String[] InFileName, Int32 InFileCount, String OutputFileName, ResetOption Option);
93+
94+
[DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
95+
private static extern Int32 CompressToPDF(IntPtr ImageWizHelper, String[] InFileName, Int32 InFileCount, String OutputFileName, ResetOption Option);
96+
97+
[DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
98+
private static extern Int32 CompressToJpeg(IntPtr ImageWizHelper, String InFileName, String OutputFileName, ResetOption Option);
99+
100+
[DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
101+
private static extern Int32 SetDPI(IntPtr ImageWizHelper, ImageDPI Dpi);
102+
103+
[DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
104+
private static extern Int32 SetImageQuality(IntPtr ImageWizHelper, ImageQuality Quality);
105+
106+
[DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
107+
private static extern void EnableExifRotation(IntPtr ImageWizHelper);
108+
109+
[DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
110+
private static extern void DisableExifRotation(IntPtr ImageWizHelper);
111+
112+
[DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
113+
private static extern Int32 GetErrorDescription(Int32 ErrorValue, StringBuilder ErrorDesc, Int32 MaxLen);
114+
115+
[DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
116+
private static extern Int32 GetMaskImage(IntPtr ImageWizHelper, String FileName, String OutputFileName, Int32 PageNum, [MarshalAs(UnmanagedType.LPArray)] RECT[] RectData, Int32 RectCount, Int32 maskValue);
117+
118+
[DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
119+
private static extern Int32 CompressPagesToTiff_Array(IntPtr ImageWizHelper, String InputFileName, String OutputFileName, Int32[] PageArray, Int32 PageArrayCount, Boolean Append, ResetOption Option);
120+
121+
[DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
122+
private static extern Int32 CompressPagesToTiff_Range(IntPtr ImageWizHelper, String InputFileName, String OutputFileName, Int32 StartPageNum, Int32 EndPageNum, Boolean Append, ResetOption Option);
123+
124+
[DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
125+
private static extern Int32 SetConversion(IntPtr ImageWizHelper, Int32 Conversion);
126+
127+
[DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
128+
private static extern Int32 GetConversion(IntPtr ImageWizHelper, ref Int32 Conversion);
129+
130+
[DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
131+
private static extern Int32 AppendToTiff(IntPtr ImageWizHelper, String InputFile, String OutPutFile, ResetOption Option);
132+
133+
//Win API def
134+
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
135+
private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]String lpFileName);
136+
137+
public IntPtr ImageWizHandle { get; set; }
138+
String licPath = String.Empty;
139+
String[] lic_name = { "ImageWizHelper_extrieve_windows", "ImageWizHelper_extrieve_windows_with_data_pdf" };//license name
140+
141+
public String DllName = "ImageWizHelper.dll";
142+
public ImageWizHelper(String dll_path)
143+
{
144+
//Console.WriteLine(CurrentPath);
145+
String dllPath = Path.Combine(dll_path, DllName);//****Here We Are Taking The Dll Path From Where We Have Plased The Dll. Full Path With Name.
146+
String LogFileName = Path.Combine(dll_path, "ImageWizHelper_Error.log");
147+
if (File.Exists(dllPath))
148+
{
149+
//****Here We are Loading The Dll****
150+
if(LoadLibrary(dllPath) == IntPtr.Zero) throw new Exception("Dll isn't Load Successfully|" + dll_path + "|" + DLL_NAME);
151+
StringBuilder error_info = new StringBuilder(1024);
152+
if (UnlockLibrary(dll_path, error_info) == 0)//unlock library using input.
153+
{
154+
if (error_info.Length > 0)
155+
throw new Exception(error_info.ToString());
156+
}
157+
158+
ImageWizHandle = Initialize(LogFileName); //Initilizing the Handle of ImageWizHelper
159+
if (ImageWizHandle == IntPtr.Zero) throw new Exception("unable to load memory");
160+
}
161+
}
162+
public void UninitializeHelper()
163+
{
164+
if (ImageWizHandle != IntPtr.Zero)
165+
{
166+
Terminate(ImageWizHandle);
167+
ImageWizHandle = IntPtr.Zero;
168+
}
169+
}
170+
public Int32 GetPageCount(string filename, string pwd)
171+
{
172+
return GetPageCountInImageFile(ImageWizHandle, filename, pwd);
173+
}
174+
175+
public Int32 getErrorDescription(Int32 error, StringBuilder error_buff, Int32 len)
176+
{
177+
return GetErrorDescription(error, error_buff, len);
178+
}
179+
180+
//function for unlock the library using unlock functionality
181+
public Int32 UnlockLibrary(String lic_path, StringBuilder err_buff)
182+
{
183+
Int32 index = lic_path.IndexOf("bin");
184+
String path = Path.Combine(lic_path.Substring(0, (lic_path.Length - lic_path.Substring(index).Length)), "DLL");//path of DLL
185+
if(!Directory.Exists(path))
186+
{
187+
Directory.CreateDirectory(path);//if doesn't exist create directory of DLL
188+
}
189+
String licfile_path1 = Path.Combine(path, lic_name[0] + ".lic");
190+
String licfile_path2 = licfile_path2 = Path.Combine(path, lic_name[1] + ".lic");
191+
192+
if (File.Exists(licfile_path1) && File.Exists(licfile_path2))
193+
{
194+
throw new Exception("license should be only one");
195+
}
196+
197+
if (File.Exists(licfile_path1))
198+
{
199+
return UnlockLibraryWithModuleIdentity(licfile_path1, err_buff);
200+
}
201+
else if (File.Exists(licfile_path2))
202+
{
203+
UnlockLibraryWithModuleIdentity(licfile_path2, err_buff);
204+
}
205+
else
206+
{
207+
Console.WriteLine(path);
208+
throw new Exception("license doesn't exist in the DLL directory");
209+
}
210+
return 0;
211+
}
212+
public Int32 CompressAndAddToTIFF(String[] InFileName, String OutputFileName, ResetOption Option)
213+
{
214+
return CompressToTIFF(ImageWizHandle, InFileName, InFileName.Length, OutputFileName, Option);
215+
}
216+
public int AppendToTIFF(String inputFile, String outputFile, ResetOption resetOption)
217+
{
218+
return AppendToTiff(ImageWizHandle, inputFile, outputFile, ResetOption.ResetAllDPI);
219+
}
220+
public Int32 CompressAndAddToPDF(String[] InFileName, String outputFile, ResetOption Option)
221+
{
222+
return CompressToPDF(ImageWizHandle, InFileName, InFileName.Length, outputFile, Option);
223+
}
224+
public Int32 CompressAndAddToJPG(String[] InFileName, String outputFile, ResetOption Option)
225+
{
226+
return CompressToPDF(ImageWizHandle, InFileName, InFileName.Length, outputFile, Option);
227+
}
228+
public Int32 GetMaskedImage(String inputFileName, String outputFile, Int32 PageNum, RECT[] RectData)
229+
{
230+
return GetMaskImage(ImageWizHandle, inputFileName, outputFile, PageNum, RectData, RectData.Length, 1);
231+
}
232+
233+
public Int32 CompressToTiff_By_PageArray(String inputFileName, String outputFile, Int32[] PageArray, Boolean Append, ResetOption option)
234+
{
235+
return CompressPagesToTiff_Array(ImageWizHandle, inputFileName, outputFile, PageArray, PageArray.Length, Append, option);
236+
}
237+
238+
public Int32 CompressToTiff_By_PageRange(String inputFileName, String outputFileName, Int32 startPage, Int32 EndPage, Boolean Append, ResetOption option = ResetOption.ResetAllDPI)
239+
{
240+
return CompressPagesToTiff_Range(ImageWizHandle, inputFileName, outputFileName, startPage, EndPage, Append, option);
241+
}
242+
243+
public Int32 AppentTo_Tiff(String InputFile, String OutputFile, ResetOption option)
244+
{
245+
return AppendToTiff(ImageWizHandle, InputFile, OutputFile, option);
246+
}
247+
public Int32 SetConversion(ConversionType convertionType)
248+
{
249+
return SetConversion(ImageWizHandle, (Int32)convertionType);
250+
}
251+
public Int32 SetUpDPI(ImageDPI DPI)
252+
{
253+
return SetDPI(ImageWizHandle, DPI);
254+
}
255+
256+
public Int32 SetupBPP(Int32 ConvType)
257+
{
258+
return SetConversion(ImageWizHandle, ConvType);
259+
}
260+
261+
public ImageQuality GetImageQuality()
262+
{
263+
IntPtr objquality;
264+
objquality = new IntPtr();
265+
266+
int ret = getImageQuality(ImageWizHandle, objquality);
267+
268+
if (ret != 0) { return ImageQuality.unknown; }
269+
270+
return ImageQuality.Photo_Quality;
271+
272+
}
273+
public Int32 GetConversionType()
274+
{
275+
Int32 ConvType = 0;
276+
GetConversion(ImageWizHandle, ref ConvType);
277+
return ConvType;
278+
}
279+
280+
public Int32 TerminateHandle(IntPtr Handle)
281+
{
282+
return Terminate(Handle);
283+
}
284+
}
285+
}

C#/ImageWizHelperCS.csproj

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{CDDCE8D7-043C-41EB-9710-AF75D623A36C}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>ImageWizHelperDemo</RootNamespace>
10+
<AssemblyName>ImageWizHelperDemo</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
36+
<DebugSymbols>true</DebugSymbols>
37+
<OutputPath>bin\x86\Debug\</OutputPath>
38+
<DefineConstants>DEBUG;TRACE</DefineConstants>
39+
<DebugType>full</DebugType>
40+
<PlatformTarget>x86</PlatformTarget>
41+
<ErrorReport>prompt</ErrorReport>
42+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
43+
<Prefer32Bit>true</Prefer32Bit>
44+
</PropertyGroup>
45+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
46+
<OutputPath>bin\x86\Release\</OutputPath>
47+
<DefineConstants>TRACE</DefineConstants>
48+
<Optimize>true</Optimize>
49+
<DebugType>pdbonly</DebugType>
50+
<PlatformTarget>x86</PlatformTarget>
51+
<ErrorReport>prompt</ErrorReport>
52+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
53+
<Prefer32Bit>true</Prefer32Bit>
54+
</PropertyGroup>
55+
<ItemGroup>
56+
<Reference Include="System" />
57+
<Reference Include="System.Core" />
58+
<Reference Include="System.Xml.Linq" />
59+
<Reference Include="System.Data.DataSetExtensions" />
60+
<Reference Include="Microsoft.CSharp" />
61+
<Reference Include="System.Data" />
62+
<Reference Include="System.Net.Http" />
63+
<Reference Include="System.Xml" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<Compile Include="ImageWizHelper.cs" />
67+
<Compile Include="Program.cs" />
68+
<Compile Include="Properties\AssemblyInfo.cs" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<None Include="App.config" />
72+
</ItemGroup>
73+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
74+
</Project>

C#/ImageWizHelperCS.csproj.user

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
4+
<StartArguments>-i "D:\WithWork\Abhishek\TestImageWizHelperTool\InputFile\PAN_HRIC.jpg" -o "D:\Rajesh\TestProject\ImageWizHelperDemo\output\a.tiff" -ct "tiff"</StartArguments>
5+
<EnableUnmanagedDebugging>true</EnableUnmanagedDebugging>
6+
</PropertyGroup>
7+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
8+
<StartArguments>-i "D:\WithWork\Abhishek\TestImageWizHelperTool\Input\RD UAM Points %281%29.pdf" -o "D:\WithWork\Abhishek\TestImageWizHelperTool\output\a.tiff" -ct "pdf"</StartArguments>
9+
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
10+
</PropertyGroup>
11+
</Project>

0 commit comments

Comments
 (0)