From 8c281ff35d5a5af915942c4a014385ad9d9e43ec Mon Sep 17 00:00:00 2001 From: raviextrieve <129574979+raviextrieve@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:26:01 +0530 Subject: [PATCH] Add files via upload --- C#/App.config | 6 + C#/ImageWizHelper.cs | 285 ++++++++++++++++++++++++++++++++ C#/ImageWizHelperCS.csproj | 74 +++++++++ C#/ImageWizHelperCS.csproj.user | 11 ++ C#/Program.cs | 198 ++++++++++++++++++++++ C#/Properties/AssemblyInfo.cs | 36 ++++ 6 files changed, 610 insertions(+) create mode 100644 C#/App.config create mode 100644 C#/ImageWizHelper.cs create mode 100644 C#/ImageWizHelperCS.csproj create mode 100644 C#/ImageWizHelperCS.csproj.user create mode 100644 C#/Program.cs create mode 100644 C#/Properties/AssemblyInfo.cs diff --git a/C#/App.config b/C#/App.config new file mode 100644 index 0000000..00bfd11 --- /dev/null +++ b/C#/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/C#/ImageWizHelper.cs b/C#/ImageWizHelper.cs new file mode 100644 index 0000000..10eaffc --- /dev/null +++ b/C#/ImageWizHelper.cs @@ -0,0 +1,285 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace ImageWizHelperCS +{ + public enum Layout + { + A0, + A1, + A2, + A3, + A4, + A5, + A6, + A7 + }; + + public enum ImageDPI + { + DPI_100 = 100, + DPI_150 = 150, + DPI_200 = 200, + DPI_300 = 300, + DPI_500 = 500, + DPI_600 = 600 + }; + + public enum ResetOption + { + No_DPI_change, // DPI will not be resetted this case . + ResetAllDPI, // Every image DPI will be resetted to selected DPI. Dimension also will be changed according to DPI + ResetNonDPI // If DPI is not available then DPI will setted for the image. Dimension also will be changed according to DPI + }; + + public enum ImageQuality + { + unknown = -1, + Photo_Quality = 70, + Document_Quality = 40, + Compressed_Document = 20 + }; + + [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Ansi)] + public struct RECT + { + public Int32 left; + public Int32 top; + public Int32 right; + public Int32 bottom; + } + + public enum ConversionType + { + CONVERSIONTYPE_NO_CONVERSION = 0, + CONVERSIONTYPE_CONVERT_TO_BW = 1, + CONVERSIONTYPE_CONVERT_TO_GREY = 2 + } + + public class ImageWizHelper + { + const string DLL_NAME = "ImageWizHelper.dll"; + + [DllImport("ImageWizHelper.dll", SetLastError = true, CharSet = CharSet.Ansi)] + static extern IntPtr Initialize(String LogFileName); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CharSet = CharSet.Ansi)] + static extern Int32 Terminate(IntPtr ImageWizHelper); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CharSet = CharSet.Ansi)] + static extern Int32 GetLastErrorCode(); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CharSet = CharSet.Ansi)] + static extern Int32 GetErrorDescription(Int32 error, StringBuilder desc_buffer, ref Int32 desc_len);//StringBuilder desc_buffer + + + [DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + static extern Int32 UnlockLibraryWithModuleIdentity(String licPath, StringBuilder err_buff); + + [DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 GetPageCountInImageFile(IntPtr ImageWizHelper, string filename, string pwd); + + [DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 getImageQuality(IntPtr ImageWizHelper, IntPtr objQuality); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 CompressToTIFF(IntPtr ImageWizHelper, String[] InFileName, Int32 InFileCount, String OutputFileName, ResetOption Option); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 CompressToPDF(IntPtr ImageWizHelper, String[] InFileName, Int32 InFileCount, String OutputFileName, ResetOption Option); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 CompressToJpeg(IntPtr ImageWizHelper, String InFileName, String OutputFileName, ResetOption Option); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 SetDPI(IntPtr ImageWizHelper, ImageDPI Dpi); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 SetImageQuality(IntPtr ImageWizHelper, ImageQuality Quality); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern void EnableExifRotation(IntPtr ImageWizHelper); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern void DisableExifRotation(IntPtr ImageWizHelper); + + [DllImport("ImageWizHelper.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 GetErrorDescription(Int32 ErrorValue, StringBuilder ErrorDesc, Int32 MaxLen); + + [DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 GetMaskImage(IntPtr ImageWizHelper, String FileName, String OutputFileName, Int32 PageNum, [MarshalAs(UnmanagedType.LPArray)] RECT[] RectData, Int32 RectCount, Int32 maskValue); + + [DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 CompressPagesToTiff_Array(IntPtr ImageWizHelper, String InputFileName, String OutputFileName, Int32[] PageArray, Int32 PageArrayCount, Boolean Append, ResetOption Option); + + [DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 CompressPagesToTiff_Range(IntPtr ImageWizHelper, String InputFileName, String OutputFileName, Int32 StartPageNum, Int32 EndPageNum, Boolean Append, ResetOption Option); + + [DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 SetConversion(IntPtr ImageWizHelper, Int32 Conversion); + + [DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 GetConversion(IntPtr ImageWizHelper, ref Int32 Conversion); + + [DllImport("ImageWizHelper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + private static extern Int32 AppendToTiff(IntPtr ImageWizHelper, String InputFile, String OutPutFile, ResetOption Option); + + //Win API def + [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)] + private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]String lpFileName); + + public IntPtr ImageWizHandle { get; set; } + String licPath = String.Empty; + String[] lic_name = { "ImageWizHelper_extrieve_windows", "ImageWizHelper_extrieve_windows_with_data_pdf" };//license name + + public String DllName = "ImageWizHelper.dll"; + public ImageWizHelper(String dll_path) + { + //Console.WriteLine(CurrentPath); + 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. + String LogFileName = Path.Combine(dll_path, "ImageWizHelper_Error.log"); + if (File.Exists(dllPath)) + { + //****Here We are Loading The Dll**** + if(LoadLibrary(dllPath) == IntPtr.Zero) throw new Exception("Dll isn't Load Successfully|" + dll_path + "|" + DLL_NAME); + StringBuilder error_info = new StringBuilder(1024); + if (UnlockLibrary(dll_path, error_info) == 0)//unlock library using input. + { + if (error_info.Length > 0) + throw new Exception(error_info.ToString()); + } + + ImageWizHandle = Initialize(LogFileName); //Initilizing the Handle of ImageWizHelper + if (ImageWizHandle == IntPtr.Zero) throw new Exception("unable to load memory"); + } + } + public void UninitializeHelper() + { + if (ImageWizHandle != IntPtr.Zero) + { + Terminate(ImageWizHandle); + ImageWizHandle = IntPtr.Zero; + } + } + public Int32 GetPageCount(string filename, string pwd) + { + return GetPageCountInImageFile(ImageWizHandle, filename, pwd); + } + + public Int32 getErrorDescription(Int32 error, StringBuilder error_buff, Int32 len) + { + return GetErrorDescription(error, error_buff, len); + } + + //function for unlock the library using unlock functionality + public Int32 UnlockLibrary(String lic_path, StringBuilder err_buff) + { + Int32 index = lic_path.IndexOf("bin"); + String path = Path.Combine(lic_path.Substring(0, (lic_path.Length - lic_path.Substring(index).Length)), "DLL");//path of DLL + if(!Directory.Exists(path)) + { + Directory.CreateDirectory(path);//if doesn't exist create directory of DLL + } + String licfile_path1 = Path.Combine(path, lic_name[0] + ".lic"); + String licfile_path2 = licfile_path2 = Path.Combine(path, lic_name[1] + ".lic"); + + if (File.Exists(licfile_path1) && File.Exists(licfile_path2)) + { + throw new Exception("license should be only one"); + } + + if (File.Exists(licfile_path1)) + { + return UnlockLibraryWithModuleIdentity(licfile_path1, err_buff); + } + else if (File.Exists(licfile_path2)) + { + UnlockLibraryWithModuleIdentity(licfile_path2, err_buff); + } + else + { + Console.WriteLine(path); + throw new Exception("license doesn't exist in the DLL directory"); + } + return 0; + } + public Int32 CompressAndAddToTIFF(String[] InFileName, String OutputFileName, ResetOption Option) + { + return CompressToTIFF(ImageWizHandle, InFileName, InFileName.Length, OutputFileName, Option); + } + public int AppendToTIFF(String inputFile, String outputFile, ResetOption resetOption) + { + return AppendToTiff(ImageWizHandle, inputFile, outputFile, ResetOption.ResetAllDPI); + } + public Int32 CompressAndAddToPDF(String[] InFileName, String outputFile, ResetOption Option) + { + return CompressToPDF(ImageWizHandle, InFileName, InFileName.Length, outputFile, Option); + } + public Int32 CompressAndAddToJPG(String[] InFileName, String outputFile, ResetOption Option) + { + return CompressToPDF(ImageWizHandle, InFileName, InFileName.Length, outputFile, Option); + } + public Int32 GetMaskedImage(String inputFileName, String outputFile, Int32 PageNum, RECT[] RectData) + { + return GetMaskImage(ImageWizHandle, inputFileName, outputFile, PageNum, RectData, RectData.Length, 1); + } + + public Int32 CompressToTiff_By_PageArray(String inputFileName, String outputFile, Int32[] PageArray, Boolean Append, ResetOption option) + { + return CompressPagesToTiff_Array(ImageWizHandle, inputFileName, outputFile, PageArray, PageArray.Length, Append, option); + } + + public Int32 CompressToTiff_By_PageRange(String inputFileName, String outputFileName, Int32 startPage, Int32 EndPage, Boolean Append, ResetOption option = ResetOption.ResetAllDPI) + { + return CompressPagesToTiff_Range(ImageWizHandle, inputFileName, outputFileName, startPage, EndPage, Append, option); + } + + public Int32 AppentTo_Tiff(String InputFile, String OutputFile, ResetOption option) + { + return AppendToTiff(ImageWizHandle, InputFile, OutputFile, option); + } + public Int32 SetConversion(ConversionType convertionType) + { + return SetConversion(ImageWizHandle, (Int32)convertionType); + } + public Int32 SetUpDPI(ImageDPI DPI) + { + return SetDPI(ImageWizHandle, DPI); + } + + public Int32 SetupBPP(Int32 ConvType) + { + return SetConversion(ImageWizHandle, ConvType); + } + + public ImageQuality GetImageQuality() + { + IntPtr objquality; + objquality = new IntPtr(); + + int ret = getImageQuality(ImageWizHandle, objquality); + + if (ret != 0) { return ImageQuality.unknown; } + + return ImageQuality.Photo_Quality; + + } + public Int32 GetConversionType() + { + Int32 ConvType = 0; + GetConversion(ImageWizHandle, ref ConvType); + return ConvType; + } + + public Int32 TerminateHandle(IntPtr Handle) + { + return Terminate(Handle); + } + } +} diff --git a/C#/ImageWizHelperCS.csproj b/C#/ImageWizHelperCS.csproj new file mode 100644 index 0000000..e3e17ea --- /dev/null +++ b/C#/ImageWizHelperCS.csproj @@ -0,0 +1,74 @@ + + + + + Debug + AnyCPU + {CDDCE8D7-043C-41EB-9710-AF75D623A36C} + Exe + ImageWizHelperDemo + ImageWizHelperDemo + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/C#/ImageWizHelperCS.csproj.user b/C#/ImageWizHelperCS.csproj.user new file mode 100644 index 0000000..3c8c37a --- /dev/null +++ b/C#/ImageWizHelperCS.csproj.user @@ -0,0 +1,11 @@ + + + + -i "D:\WithWork\Abhishek\TestImageWizHelperTool\InputFile\PAN_HRIC.jpg" -o "D:\Rajesh\TestProject\ImageWizHelperDemo\output\a.tiff" -ct "tiff" + true + + + -i "D:\WithWork\Abhishek\TestImageWizHelperTool\Input\RD UAM Points %281%29.pdf" -o "D:\WithWork\Abhishek\TestImageWizHelperTool\output\a.tiff" -ct "pdf" + false + + \ No newline at end of file diff --git a/C#/Program.cs b/C#/Program.cs new file mode 100644 index 0000000..b56b12c --- /dev/null +++ b/C#/Program.cs @@ -0,0 +1,198 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace ImageWizHelperCS +{ + class Program + { + public static String InputFile { get; set; }// decalre input file to store the input image path. + public static String OutputFile { get; set; }//decalre output file to store the output image path with file name and extension + public static String app_name { get; set; }//decalre app name to store the current application name calling the ImageWizHelper DLL. + public static String compression_type { get; set; }//decalre compression type to store the compression format "TIFF"/"PDF"/"JPG" + + //function for read argument + static Boolean ReadArguments(String[] args) + { + int index = 0; + if (args.Length == 0)//**checking have any argument or not + { + DefineUsage(); + return false; + } + do + { + if (index == args.Length) + break; + + switch (args[index].ToUpper()) + { + case "-I": + if (index == args.Length) return false; + index++; + InputFile = args[index]; + break; + case "-O": + if (index == args.Length) return false; + index++; + OutputFile = args[index]; + break; + //case "-AN": + // if (index == args.Length) return false; + // index++; + // app_name = args[index]; + // break; + case "-CT": + if (index == args.Length) return false; + index++; + compression_type = args[index]; + break; + } + index++; + } while (true); + if (compression_type == null)//default compression type + { + compression_type = "TIFF"; + } + return true; + } + + //this fuction will call when argument is null. + static void DefineUsage() + { + Console.WriteLine("Exe path"+" " + "-I " + "-O " + "-CT " + "<[PDF" + "/TIFF" + "/JPG]>");//Message of Input format to run the exe. + } + + //This Function is used when we choose the Default options. + static Boolean PDFtoTiff(ImageWizHelper ObjimageWizHelper) + { + int len = 1024, ret; + StringBuilder error_buff = new StringBuilder(len); // declare the varible of string buider for getting error description. + if (InputFile == null)// checking input file is null. + { + throw new Exception("Input file name not provided"); + } + + if (OutputFile == null) // checking output is null + { + throw new Exception("Output file name not provided"); + } + ret = ObjimageWizHelper.CompressAndAddToTIFF(new String[] { InputFile }, OutputFile, ResetOption.ResetAllDPI); //compress pdf to tiff using argument (inputfile), string(output file), resetoption(enum defined in the ImageWizHelper Interface). + if (ret != 0) + { + Int32 err = (ObjimageWizHelper.getErrorDescription(ret, error_buff, len));//get error desc from error code(ret),error_buff(stringBuilder) and length of StringBuilder. + if (!String.IsNullOrEmpty(error_buff.ToString())) // checking error_buff have some value or not. + { + throw new Exception(error_buff.ToString()); + } + } + return true; + } + + //function for compress the tiff file into pdf file. + static Boolean TifftoPdf(ImageWizHelper ObjimageWizHelper) + { + int len = 1024, ret; + StringBuilder error_buff = new StringBuilder(len); // declare the varible of string buider for getting error description. + + if (InputFile == null) // checking input file is null. + { + throw new Exception("Input file name not provided"); + } + + if (OutputFile == null) // checking output file is null. + { + throw new Exception("Output file name not provided"); + } + ret = ObjimageWizHelper.CompressAndAddToPDF(new String[] { InputFile }, OutputFile, ResetOption.ResetAllDPI); //compress tiff to pdf using argument (inputfile), string(output file), resetoption(enum defined in the ImageWizHelper Interface). + if (ret != 0) + { + Int32 err = (ObjimageWizHelper.getErrorDescription(ret, error_buff, len));//get error desc from error code(ret),error_buff(stringBuilder) and length of StringBuilder. + if (!String.IsNullOrEmpty(error_buff.ToString())) // checking error_buff have some value or not. + { + throw new Exception(error_buff.ToString()); + } + } + return true; + } + + //function for compress the image file into jpg file. + static Boolean CompressToJpg(ImageWizHelper ObjimageWizHelper) + { + int ret, len = 1024; + StringBuilder error_buff = new StringBuilder(len); // declare the varible of string buider for getting error description. + + if (InputFile == null) // checking input file is null. + { + throw new Exception("Input file name not provided"); + } + + if (OutputFile == null) // checking input file is null. + { + throw new Exception("Output file name not provided"); + } + ret = ObjimageWizHelper.CompressAndAddToJPG(new String[] { InputFile }, OutputFile, ResetOption.ResetAllDPI); //compress image to jpg file using argument (inputfile), string(output file), resetoption(enum defined in the ImageWizHelper Interface). + if (ret != 0) + { + Int32 err = (ObjimageWizHelper.getErrorDescription(ret, error_buff, len));//get error desc from error code(ret), error_buff(stringBuilder) and length of StringBuilder. + if (!String.IsNullOrEmpty(error_buff.ToString())) // checking error_buff have some value or not. + { + throw new Exception(error_buff.ToString()); + } + } + return true; + } + static void Main(string[] args) + { + IntPtr Handle = IntPtr.Zero; // declare handle + Boolean ret; + String CurrentPath = AppDomain.CurrentDomain.BaseDirectory; //getting exe directory path + StringBuilder err_desc = new StringBuilder(0); + ImageWizHelper ObjimageWizHelper = null; //create a object of ImageWizHelper class. + try + { + if (!ReadArguments(args)) + { + throw new Exception("Failed to read argument"); + } + //object of constructor ImageWizHelper. + ObjimageWizHelper = new ImageWizHelper(CurrentPath); // Assigning object of the ImageWizHelper class. This same object will be used for calling every funtionalities of ImageWizHelper. + + switch (compression_type) + { + case "TIFF": + case "TIF": + case "tif": + case "tiff": + ret = PDFtoTiff(ObjimageWizHelper); // call the function for compress the pdf to tiff. + if (ret) Console.Write("Tiff file Successfully Generated....."); // output type if compression successfull. + break; + case "PDF": + case "pdf": + ret = TifftoPdf(ObjimageWizHelper); // call the function for compress the tiff to pdf. + if (ret) Console.Write("Pdf file Successfully Generated.....");// output type if compression successfull. + break; + case "JPG": + case "jpg": + ret = CompressToJpg(ObjimageWizHelper); // call the function for compress the image file to jpg file. + if (ret) Console.Write("Jpg file Successfully Generated.....");// output type if compression successfull. + break; + } + + } + catch (Exception ex) + { + Console.WriteLine(ex); + Console.ReadLine(); + } + finally + { + ObjimageWizHelper.TerminateHandle(ObjimageWizHelper.ImageWizHandle);//finally close the image wiz handle + } + } + } +} diff --git a/C#/Properties/AssemblyInfo.cs b/C#/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ced017c --- /dev/null +++ b/C#/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ImageWizHelperCS")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ImageWizHelperDemo")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cddce8d7-043c-41eb-9710-af75d623a36c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]