首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >CSharp: word,excel,powerpoint convert to pdf,html etc using SautinSoft.UseOffice

CSharp: word,excel,powerpoint convert to pdf,html etc using SautinSoft.UseOffice

作者头像
geovindu
发布2026-06-18 16:43:40
发布2026-06-18 16:43:40
1110
举报
代码语言:javascript
复制
    /// <summary>
    /// 目标文件类型
    /// 是商业软件需要购买
    /// </summary>
    public enum FileFormat
    {
        None,
        Pdf,
        Html,
        Text,
        Doc,
        Docx,
        Xls,
        Xlsx,
        CSV,
        PPT,
        PPTx,
        SVG,
        Webp,
        Rtf

    }

    /// <summary>
    /// 文件转换
    /// geovindu,Geovin Du,涂聚文
    /// 底部有水印,是商业软件需要购买
    /// 
    /// </summary>
    public class UseOfficeHelper
    {



        /// <summary>
        /// 文件转换
        /// 其他文件类型自我优化
        /// 
        /// </summary>
        /// <param name="inpFile">源文件</param>
        /// <param name="outFile">目标文件</param>
        /// <param name="fileFormat">目标转换文件类型</param>
        /// <returns></returns>
        public static bool Convert(string inpFile, string outFile, FileFormat fileFormat)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                switch (fileFormat)
                {
                    case FileFormat.Pdf:
                        isNeedConvert=ConvertPdf(inpFile, outFile);
                        break;
                    case FileFormat.Html:
                        isNeedConvert=ConvertHtml(inpFile, outFile);    
                        break;
                    case FileFormat.Text:
                        isNeedConvert=ConvertText(inpFile, outFile);
                        break;
                    case FileFormat.Xls:
                        isNeedConvert=ConvertXls(inpFile, outFile);
                        break;
                    case FileFormat.Xlsx:
                        isNeedConvert=ConvertXlsx(inpFile, outFile);    
                        break;
                    case FileFormat.CSV:
                        isNeedConvert= ConvertCSV(inpFile, outFile);
                        break;
                    case FileFormat.Webp:
                        isNeedConvert=ConvertWebp(inpFile, outFile);
                        break;
                    case FileFormat.Doc:
                        isNeedConvert=ConvertDoc(inpFile, outFile);
                        break;
                    case FileFormat.Docx:
                        isNeedConvert= ConvertDocx(inpFile, outFile);
                        break;
                    case FileFormat.SVG:
                        break;
                    case FileFormat.Rtf:
                        isNeedConvert=ConvertRtf(inpFile, outFile);
                        break;
                    default:
                        isNeedConvert=false;
                        break;
                }
            }
            return isNeedConvert;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertPdf(string inpFile, string outFile)
        { 
            bool isNeedConvert = false;
            if(File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {
                    case ".doc":
                        isNeedConvert = ConvertDocToPdf(inpFile, outFile);
                        break;
                    case ".docx":
                        isNeedConvert = ConvertDocxTopdfFromStream(inpFile, outFile);
                        break;
                    case ".ppt":
                        isNeedConvert =  ConvertPPTToPdf(inpFile, outFile);
                        break;
                    case ".pptx":
                        isNeedConvert =  ConvertPPTXToPdf(inpFile, outFile);
                        break;
                    case ".xls":
                        isNeedConvert = ConvertXlsToPdf(inpFile, outFile);
                        break;
                    case ".xlsx":
                        isNeedConvert = ConvertXlsxToPdf(inpFile, outFile);
                        break;
                    case ".html":
                        isNeedConvert = ConvertHtmlToPdf(inpFile,outFile);
                        break;
                    case ".htm":
                        isNeedConvert = ConvertHtmlToPdf(inpFile, outFile);
                        break;
                    case ".txt":
                        isNeedConvert=ConvertTextToPdf(inpFile,outFile);
                        break;
                    case ".jpg":
                        isNeedConvert = ConvertImageToPdf(inpFile, outFile);
                        break;
                    case ".png":
                        isNeedConvert = ConvertImageToPdf(inpFile, outFile);
                        break;
                    case ".gif":
                        isNeedConvert = ConvertImageToPdf(inpFile, outFile);
                        break;
                    case ".rtf":
                        isNeedConvert=ConvertRtfToPdf(inpFile, outFile);
                        break;



                }

            }

            return isNeedConvert;
        
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertHtml(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {
                    case ".doc":
                        isNeedConvert = ConvertDocToHtml(inpFile, outFile);
                        break;
                    case ".docx":
                        isNeedConvert = ConvertDocxToHtml(inpFile, outFile);
                        break;
                    case ".ppt":
                        isNeedConvert = false;// ConvertPPTToHtml(inpFile, outFile);
                        break;
                    case ".pptx":
                        isNeedConvert = false;// ConvertPPTXToHtml(inpFile, outFile);
                        break;
                    case ".xls":
                        isNeedConvert = ConvertXlsToHtml(inpFile, outFile);
                        break;
                    case ".xlsx":
                        isNeedConvert = ConvertXlsxToHtml(inpFile, outFile);
                        break;
                    case ".html":
                        isNeedConvert = false;
                        break;
                    case ".htm":
                        isNeedConvert = false;
                        break;
                    case ".pdf":
                        isNeedConvert = false;
                        break;
                    case ".rtf":
                        isNeedConvert = ConvertRtfToHtml(inpFile, outFile);
                        break;


                }

            }

            return isNeedConvert;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertText(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {
                    case ".doc":
                        isNeedConvert = ConvertDocToText(inpFile, outFile);
                        break;
                    case ".docx":
                        isNeedConvert = ConvertDocxToText(inpFile, outFile);
                        break;
                    case ".ppt":
                        isNeedConvert = false;// ConvertPPTToText(inpFile, outFile);
                        break;
                    case ".pptx":
                        isNeedConvert = false;// ConvertPPTXToText(inpFile, outFile);
                        break;
                    case ".xls":
                        isNeedConvert = ConvertXlsToText(inpFile, outFile);
                        break;
                    case ".xlsx":
                        isNeedConvert = ConvertXlsxToText(inpFile, outFile);
                        break;
                    case ".html":
                        isNeedConvert = ConvertHtmlToText(inpFile,outFile);
                        break;
                    case ".htm":
                        isNeedConvert = ConvertHtmlToText(inpFile, outFile);
                        break;
                    case ".pdf":
                        isNeedConvert = ConvertPdfToText(inpFile, outFile);
                        break;
                    case ".rtf":
                        isNeedConvert = ConvertRtfToText(inpFile, outFile);
                        break;
                }

            }

            return isNeedConvert;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDoc(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {

                    case ".txt":
                        isNeedConvert = ConvertTextToDoc(inpFile, outFile);
                        break;
                    case ".pdf":
                        isNeedConvert = ConvertPdfToDoc(inpFile, outFile);
                        break;
                    case ".html":
                        isNeedConvert = ConvertHtmlToDoc(inpFile, outFile);
                        break;
                    case ".rtf":
                        isNeedConvert = ConvertRtfToDoc(inpFile,outFile);
                        break;
                }

            }

            return isNeedConvert;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocx(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {
                    case ".doc":
                        isNeedConvert = ConvertDocToDocx(inpFile, outFile);
                        break;
                    case ".txt":
                        isNeedConvert = ConvertTextToDocx(inpFile, outFile);
                        break;
                    case ".pdf":
                        isNeedConvert = ConvertPdfToDocx(inpFile, outFile);
                        break;
                    case ".html":
                        isNeedConvert = ConvertHtmlToDocx(inpFile, outFile);
                        break;
                    case ".rtf":
                        isNeedConvert = ConvertRtfToDocx(inpFile,outFile);
                        break;
                }

            }

            return isNeedConvert;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertCSV(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {

                    case ".xls":
                        isNeedConvert = ConvertXlsToCSV(inpFile, outFile);
                        break;
                    case ".xlsx":
                        isNeedConvert = ConvertXlsxToCSV(inpFile, outFile);
                        break;
                    
                }

            }

            return isNeedConvert;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXls(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {

                    case ".csv":
                        isNeedConvert = false;// ConvertCSVToXls(inpFile, outFile);
                        break;
                    case ".xlsx":
                        isNeedConvert = false;// ConvertXlsxToXls(inpFile, outFile);
                        break;

                }

            }

            return isNeedConvert;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsx(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {

                    case ".xls":
                        isNeedConvert = false;// ConvertXlsToXlsx(inpFile, outFile);
                        break;
                    case ".csv":
                        isNeedConvert = ConvertCsvToXlsx(inpFile, outFile);
                        break;

                }

            }

            return isNeedConvert;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertRtf(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {

                    case ".doc":
                        isNeedConvert = ConvertDocToRtf(inpFile, outFile);
                        break;
                    case ".docx":
                        isNeedConvert = ConvertDocxToRtf(inpFile, outFile);
                        break;
                    case ".ppt":
                        isNeedConvert = false;// ConvertPPTToRtf(inpFile, outFile);
                        break;
                    case ".pptx":
                        isNeedConvert = ConvertPPTxToRtf(inpFile, outFile);
                        break;
                    case ".xls":
                        isNeedConvert = ConvertXlsToRtf(inpFile, outFile);
                        break;
                    case ".xlsx":
                        isNeedConvert = ConvertXlsxToRtf(inpFile, outFile);
                        break;
                    case ".html":
                        isNeedConvert = ConvertHtmlToRtf(inpFile, outFile);
                        break;
                    case ".htm":
                        isNeedConvert = ConvertHtmlToRtf(inpFile, outFile);
                        break;
                    case ".pdf":
                        isNeedConvert = ConvertPdfToRtf(inpFile, outFile);
                        break;
                }

            }

            return isNeedConvert;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertWebp(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {

                    case ".jpg":
                        isNeedConvert = ConvertImageToWebp(inpFile, outFile);
                        break;
                    case ".png":
                        isNeedConvert = ConvertImageToWebp(inpFile, outFile);
                        break;
                    case ".gif":
                        isNeedConvert = ConvertImageToWebp(inpFile, outFile);
                        break;       
                }

            }

            return isNeedConvert;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocxTopdfFromStream(string inpFile, string outFile)
        {
            bool ok=false;
            try
            {
                // We need files only for demonstration purposes.
                // The conversion process will be done completely in memory. 
                byte[] inpData = File.ReadAllBytes(inpFile);
                byte[] outData = null;

                using (MemoryStream msInp = new MemoryStream(inpData))
                {

                    // Load a document.
                    SautinSoft.Document.DocumentCore dc = SautinSoft.Document.DocumentCore.Load(msInp, new DocxLoadOptions());

                    // Save the document to PDF format.
                    using (MemoryStream outMs = new MemoryStream())
                    {
                        dc.Save(outMs, new PdfSaveOptions());
                        outData = outMs.ToArray();
                    }
                    // Show the result for demonstration purposes.
                    if (outData != null)
                    {
                        File.WriteAllBytes(outFile, outData);

                        // Important for Linux: Install MS Fonts
                        // sudo apt install ttf-mscorefonts-installer -y

                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                    }
                    ok = true;
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocToPdf(string inpFile, string outFile)
        {

            bool ok = false;
            // Before starting, we recommend to get a free key:
            // https://sautinsoft.com/start-for-free/

            // Apply the key here:
            // UseOffice.SetLicense("...");

            // Convert DOC file to DOCX file.
            // If you need more information about UseOffice .Net email us at:
            // support@sautinsoft.com.
            SautinSoft.UseOffice u = new SautinSoft.UseOffice();

            //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.doc");
            //string outFile = Path.GetFullPath("Result.docx");

            // Prepare UseOffice .Net, loads MS Word in memory
            int ret = u.InitWord();

            // Return values:
            // 0 - Loading successfully
            // 1 - Can't load MS Word library in memory

            if (ret == 1)
            {
                Console.WriteLine("Error! Can't load MS Word library in memory");
                ok = false;
            }
            else
            {
                // Perform the conversion.
                ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOC_to_DOCX);

                // Release MS Word from memory
                u.CloseWord();

                // 0 - Converting successfully
                // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                // 3 - Converting failed, please contact with our Support Team
                // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                if (ret == 0)
                {
                    // Open the result.
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                    ok = true;
                }
                else
                {
                    Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            return ok;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocToHtml(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert DOC file to HTML file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.
                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.doc");
                //string outFile = Path.GetFullPath(@"Result.html");

                // Prepare UseOffice .Net, loads MS Word in memory.
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Converting
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOC_to_HTML);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString().Trim();
            }
            return ok;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocxToHtml(string inpFile, string outFile)
        {

            bool ok = false;
            try
            {
                // Convert DOCX file to HTML file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.docx");
                //string outFile = Path.GetFullPath("Result.html");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOCX_to_HTML);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString().Trim();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocToText(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert DOC file to Text file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.
                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.doc");
                //string outFile = Path.GetFullPath(@"Result.txt");

                // Prepare UseOffice .Net, loads MS Word in memory.
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Converting
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOC_to_TEXT);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch(Exception ex)
            {
                ex.Message.ToString().Trim();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocxToText(string inpFile,string outFile)
        {
            bool ok = false;
            try
            {
                // Convert DOCX file to Text file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.docx");
                //string outFile = Path.GetFullPath("Result.txt");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOCX_to_TEXT);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            

            }
            catch(Exception ex)
            {
                ex.Message.ToString().Trim();
            }
            return ok;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocxToPdf(string inpFile, string outFile)
        {

            bool ok = false;
            try
            {
                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                // string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.docx");
                //string outFile = Path.GetFullPath("Result.pdf");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOCX_to_PDF);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString().Trim();
            }
            return ok;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertPPTToPdf(string inpFile, string outFile)
        {

            bool ok = false;
            try
            {
                // Convert PPT file to PDF file
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.
                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.ppt");
                //string outFile = Path.GetFullPath(@"Result.pdf");

                // Prepare UseOffice .Net, loads MS PowerPoint in memory
                int ret = u.InitPowerPoint();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS PowerPoint library in memory
                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS PowerPoint library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.PPT_to_PDF);

                    // Release MS PowerPoint from memory
                    u.ClosePowerPoint();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        Console.WriteLine("Converting successfully!");
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;  


                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch (Exception ex)
            {
                ex.Message.ToString().Trim();   
            }
            return ok;


        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertPPTXToPdf(string inpFile, string outFile)
        {

            bool ok = false;
            try
            {
                // Convert PPTX file to PDF file
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.
                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.pptx");
                //string outFile = Path.GetFullPath(@"Result.pdf");

                // Prepare UseOffice .Net, loads MS PowerPoint in memory
                int ret = u.InitPowerPoint();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS PowerPoint library in memory
                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS PowerPoint library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.PPTX_to_PDF);

                    // Release MS PowerPoint from memory
                    u.ClosePowerPoint();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        Console.WriteLine("Converting successfully!");
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch (Exception ex)
            {
                ex.Message.ToString().Trim();
            }
            return ok;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertPPTxToRtf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert PPTX file to RTF file
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.
                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.pptx");
                //string outFile = Path.GetFullPath(@"Result.rtf");

                // Prepare UseOffice .Net, loads MS PowerPoint in memory
                int ret = u.InitPowerPoint();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS PowerPoint library in memory
                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS PowerPoint library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.PPTX_to_RTF);

                    // Release MS PowerPoint from memory
                    u.ClosePowerPoint();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        Console.WriteLine("Converting successfully!");
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
 
        }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="inpFile"></param>
            /// <param name="outFile"></param>
            /// <returns></returns>
            static bool ConvertXlsToPdf(string inpFile, string outFile)
          {

            bool ok = false;
            try
            {
                // Convert XLS file to PDF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xls");
                //string outFile = Path.GetFullPath("Result.pdf");

                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLS_to_PDF);

                    // Release MS Excel from memory
                    u.CloseExcel();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsxToPdf(string inpFile, string outFile)
        {
            bool ok = false;

            try
            {

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xlsx");
                //string outFile = Path.GetFullPath("Result.pdf");

                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLSX_to_PDF);

                    // Release MS Excel from memory
                    u.CloseExcel();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();  
            }
            return ok;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsToHtml(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xls");
                //string outFile = Path.GetFullPath("Result.html");

                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLS_to_HTML);

                    // Release MS Excel from memory
                    u.CloseExcel();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsxToHtml(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                SautinSoft.UseOffice u = new SautinSoft.UseOffice();
                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xlsx");
                //string outFile = Path.GetFullPath("Result.html");
                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();
                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory
                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLSX_to_HTML);
                    // Release MS Excel from memory
                    u.CloseExcel();
                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support:");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsToText(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert XLS file to Text file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xls");
                //string outFile = Path.GetFullPath("Result.txt");

                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLS_to_TEXT);

                    // Release MS Excel from memory
                    u.CloseExcel();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch(Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsxToText(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert XLSX file to Text file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xlsx");
                //string outFile = Path.GetFullPath("Result.txt");

                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLSX_to_TEXT);

                    // Release MS Excel from memory
                    u.CloseExcel();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertHtmlToDoc(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert HTML file to Doc file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.html");
                //string outFile = Path.GetFullPath("Result.doc");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.HTML_to_DOC);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertHtmlToDocx(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert HTML file to DOCX file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.html");
                //string outFile = Path.GetFullPath("Result.docx");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.HTML_to_DOCX);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertHtmlToPdf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {


                // Convert HTML file to PDF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

               // string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.html");
                //string outFile = Path.GetFullPath("Result.pdf");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {

                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.HTML_to_PDF);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }


            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertHtmlToText(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert HTML file to Text file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.html");
                //string outFile = Path.GetFullPath("Result.txt");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");
                }
                else
                {

                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.HTML_to_TEXT);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch(Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertPdfToText(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert PDF file to Text file. Works only in Office 2013 and higher.

                // If you are looking for solution without MS Office
                // Please take a look at our PDF Focus .Net: https://www.sautinsoft.com/products/pdf-focus/index.php

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

               // string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.pdf");
                //string outFile = Path.GetFullPath("Result.txt");

                // Prepare UseOffice .Net, loads MS Word in memory
                if (u.InitWord() != 0)
                {
                    Console.WriteLine("Error: Can't load MS Word in memory!");
                    Console.WriteLine("Please contact SautinSoft's support Team: support@sautinsoft.com.");
                    Console.ReadLine();
                }

                // Check MS Office version
                if (u.OfficeVersion >= UseOffice.eOfficeVersion.Office2013)
                {
                    // Converting ...
                    int result = u.ConvertFile(inpFile, outFile, UseOffice.eDirection.PDF_to_TEXT);

                    if (result == 0)
                    {
                        Console.WriteLine("Converting successfully!");
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok= true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
                else
                {
                    Console.WriteLine("To convert PDF documents, please install MS Office 2013 or higher.");
                }
                u.CloseOffice();



            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertPdfToDoc(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {

                // Convert PDF file to DOC file. Works only in Office 2013 and higher.

                // If you are looking for solution without MS Office
                // Please take a look at our PDF Focus .Net: https://www.sautinsoft.com/products/pdf-focus/index.php

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.pdf");
                //string outFile = Path.GetFullPath("Result.doc");

                // Prepare UseOffice .Net, loads MS Word in memory
                if (u.InitWord() != 0)
                {
                    Console.WriteLine("Error: Can't load MS Word in memory!");
                    Console.WriteLine("Please contact SautinSoft's support Team: support@sautinsoft.com.");
                    Console.ReadLine();
                }

                // Check MS Office version
                if (u.OfficeVersion >= UseOffice.eOfficeVersion.Office2013)
                {
                    // Converting ...
                    int result = u.ConvertFile(inpFile, outFile, UseOffice.eDirection.PDF_to_DOC);

                    if (result == 0)
                    {
                        Console.WriteLine("Converting successfully!");
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok= true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
                else
                {
                    Console.WriteLine("To convert PDF documents, please install MS Office 2013 or higher.");
                }
                u.CloseOffice();


            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertPdfToDocx(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert PDF file to DOCX file. Works only in Office 2013 and higher.

                // If you are looking for solution without MS Office
                // Please take a look at our PDF Focus .Net: https://www.sautinsoft.com/products/pdf-focus/index.php

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.pdf");
                //string outFile = Path.GetFullPath("Result.docx");

                // Prepare UseOffice .Net, loads MS Word in memory
                if (u.InitWord() != 0)
                {
                    Console.WriteLine("Error: Can't load MS Word in memory!");
                    Console.WriteLine("Please contact SautinSoft's support Team: support@sautinsoft.com.");
                    Console.ReadLine();
                }

                // Check MS Office version
                if (u.OfficeVersion >= UseOffice.eOfficeVersion.Office2013)
                {
                    // Converting ...
                    int result = u.ConvertFile(inpFile, outFile, UseOffice.eDirection.PDF_to_DOCX);

                    if (result == 0)
                    {
                        Console.WriteLine("Converting successfully!");
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
                else
                {
                    Console.WriteLine("To convert PDF documents, please install MS Office 2013 or higher.");
                }
                u.CloseOffice();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertTextToDoc(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert Text file to PDF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.txt");
                //string outFile = Path.GetFullPath("Result.doc");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.TEXT_to_DOC);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertTextToDocx(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert Text file to PDF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.txt");
                //string outFile = Path.GetFullPath("Result.docx");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {

                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.TEXT_to_DOCX);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch(Exception ex)
            { ex.Message.ToString(); }
            return ok;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertTextToPdf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert Text file to PDF file.
                 // If you need more information about UseOffice .Net email us at:
                 // support@sautinsoft.com.

                    SautinSoft.UseOffice u = new SautinSoft.UseOffice();

               // string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.txt");
               // string outFile = Path.GetFullPath("Result.pdf");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.TEXT_to_PDF);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch (Exception ex) 
            {
                ex.Message.ToString();
            }
           return ok;    

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertImageToPdf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Create a new PDF document
                Document doc = new Document(PageSize.A4);
                //string outputPath = Server.MapPath("geovindu.pdf");

                // Initialize PdfWriter
                PdfWriter.GetInstance(doc, new FileStream(outFile, FileMode.Create));

                // Open the document
                doc.Open();

                try
                {
                    // Add a paragraph
                    // doc.Add(new Paragraph("Adding an image to PDF using iTextSharp"));

                    // Load the image
                   // string imagePath = Server.MapPath("~/HB1.png"); // Replace with your image path
                    iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(inpFile);
                    // 获取图片尺寸
                    float width = img.Width;
                    float height = img.Height;
                    // Set image properties
                    img.ScaleToFit(width, height); // Resize the image
                    img.SetAbsolutePosition(0f, 0f); // Set position (x, y)
                    img.Alignment =iTextSharp.text.Element.ALIGN_CENTER; // Align the image

                    // Add the image to the document
                    doc.Add(img);
                    ok = true;

                }
                catch (Exception ex)
                {
                     ex.Message.ToString();
                }
                finally
                {
                    // Close the document
                    doc.Close();
                }
            }
            catch(Exception ex)
            { 
                ex.Message.ToString(); 
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertRtfToHtml(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert RTF file to HTML file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.rtf");
                //string outFile = Path.GetFullPath("Result.html");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");
                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.RTF_to_HTML);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch(Exception ex)
            { ex.Message.ToString(); }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertRtfToPdf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert RTF file to PDF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.rtf");
                //string outFile = Path.GetFullPath("Result.pdf");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.RTF_to_PDF);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertRtfToText(string inpFile, string outFile)
        {
            bool ok = false;
            try 
            {
                // Convert RTF file to Text file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.rtf");
                //string outFile = Path.GetFullPath("Result.txt");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.RTF_to_TEXT);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertRtfToDoc(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert RTF file to DOC file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.rtf");
                //string outFile = Path.GetFullPath("Result.doc");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.RTF_to_DOC);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertRtfToDocx(string inpFile, string outFile)
        {
            bool ok = false;
            try 
            {
                // Convert RTF file to DOCX file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.rtf");
                //string outFile = Path.GetFullPath("Result.docx");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.RTF_to_DOCX);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex) 
            { 
                ex.Message.ToString(); 
            }
            return ok;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsToCSV(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert XLS file to CSV file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

               // string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xls");
                //string outFile = Path.GetFullPath("Result.csv");

                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {

                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLS_to_CSV);

                    // Release MS Excel from memory
                    u.CloseExcel();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsxToCSV(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert XLSX file to CSV file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xlsx");
                //string outFile = Path.GetFullPath("Result.csv");

                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLSX_to_CSV);

                    // Release MS Excel from memory
                    u.CloseExcel();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocToRtf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert DOC file to RTF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.doc");
                //string outFile = Path.GetFullPath("Result.rtf");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {




                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOC_to_RTF);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocxToRtf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert DOCX file to RTF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.docx");
                //string outFile = Path.GetFullPath("Result.rtf");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {

                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOCX_to_RTF);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertHtmlToRtf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert HTML file to RTF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

               // string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.html");
                //string outFile = Path.GetFullPath("Result.rtf");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.HTML_to_RTF);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex) { ex.Message.ToString(); }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertTextToRtf(string inpFile,string outFile)
        {
            bool ok = false;
            try 
            {
                // Convert Text file to PDF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.txt");
                //string outFile = Path.GetFullPath("Result.rtf");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.TEXT_to_RTF);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch(Exception ex) 
            { 
                ex.Message.ToString();
            } 
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsToRtf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert XLS file to RTF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xls");
                //string outFile = Path.GetFullPath("Result.rtf");

                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLS_to_RTF);

                    // Release MS Excel from memory
                    u.CloseExcel();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsxToRtf(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert XLSX file to RTF file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xlsx");
                //string outFile = Path.GetFullPath("Result.rtf");

                // Prepare UseOffice .Net, loads MS Excel in memory
                int ret = u.InitExcel();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Excel library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Excel library in memory");

                }
                else
                {
                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLSX_to_RTF);

                    // Release MS Excel from memory
                    u.CloseExcel();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex) 
            { 
                ex.Message.ToString(); 
            }
            return ok;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFiel"></param>
        /// <returns></returns>
        static bool ConvertXslxToCsv(string inpFile, string outFiel)
        {
            bool ok = false;
            try 
            {
                // 1. 读取CSV文件
                //string csvFilePath = "path/to/your/csv/file.csv";
                string[] csvLines = File.ReadAllLines(inpFile);

                // 2. 创建Excel工作簿
                ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
                
                using (ExcelPackage package = new ExcelPackage())
                {
                    // 创建一个新的工作表
                    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet1");

                    // 3. 写入数据
                    for (int i = 0; i < csvLines.Length; i++)
                    {
                        string[] values = csvLines[i].Split(',');
                        for (int j = 0; j < values.Length; j++)
                        {
                            worksheet.Cells[i + 1, j + 1].Value = values[j];
                        }
                    }

                    // 4. 保存Excel文件
                    //string excelFilePath = "path/to/your/excel/file.xlsx";
                    FileInfo excelFile = new FileInfo(outFiel);
                    package.SaveAs(excelFile);
                    ok = true;
                }
 

            }
            catch (Exception ex)
            { 
                ex.Message.ToString(); 
            }
            return ok;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertPdfToRtf(string inpFile,string outFile)
        {
            bool ok = false;
            try
            {
                // Convert PDF file to RTF file. Works only in Office 2013 and higher.

                // If you are looking for solution without MS Office
                // Please take a look at our PDF Focus .Net: https://www.sautinsoft.com/products/pdf-focus/index.php

                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

               // string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.pdf");
                //string outFile = Path.GetFullPath("Result.rtf");

                // Prepare UseOffice .Net, loads MS Word in memory
                if (u.InitWord() != 0)
                {
                    Console.WriteLine("Error: Can't load MS Word in memory!");
                    Console.WriteLine("Please contact SautinSoft's support Team: support@sautinsoft.com.");
                    Console.ReadLine();
                }

                // Check MS Office version
                if (u.OfficeVersion >= UseOffice.eOfficeVersion.Office2013)
                {
                    // Converting ...
                    int result = u.ConvertFile(inpFile, outFile, UseOffice.eDirection.PDF_to_RTF);

                    if (result == 0)
                    {
                        Console.WriteLine("Converting successfully!");
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;

                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
                else
                {
                    Console.WriteLine("To convert PDF documents, please install MS Office 2013 or higher.");
                }
                u.CloseOffice();
            }
            catch(Exception ex)
            { 
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertDocToDocx(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Convert DOC file to DOCX file.
                // If you need more information about UseOffice .Net email us at:
                // support@sautinsoft.com.
                SautinSoft.UseOffice u = new SautinSoft.UseOffice();

                //string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.doc");
                //string outFile = Path.GetFullPath("Result.docx");

                // Prepare UseOffice .Net, loads MS Word in memory
                int ret = u.InitWord();

                // Return values:
                // 0 - Loading successfully
                // 1 - Can't load MS Word library in memory 

                if (ret == 1)
                {
                    Console.WriteLine("Error! Can't load MS Word library in memory");

                }
                else
                {

                    // Perform the conversion.
                    ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOC_to_DOCX);

                    // Release MS Word from memory
                    u.CloseWord();

                    // 0 - Converting successfully
                    // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
                    // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
                    // 3 - Converting failed, please contact with our Support Team
                    // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
                    if (ret == 0)
                    {
                        // Open the result.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                        ok = true;
                    }
                    else
                        Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="csvFilePath"></param>
        /// <param name="xlsxFilePath"></param>
        /// <returns></returns>
        public static bool ConvertCsvToXlsx(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Read CSV lines
                var lines = File.ReadAllLines(inpFile);

                // Create Excel document
                using (SpreadsheetDocument document = SpreadsheetDocument.Create(outFile, SpreadsheetDocumentType.Workbook))
                {
                    WorkbookPart workbookPart = document.AddWorkbookPart();
                    workbookPart.Workbook = new Workbook();

                    WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
                    worksheetPart.Worksheet = new Worksheet(new SheetData());

                    Sheets sheets = document.WorkbookPart.Workbook.AppendChild(new Sheets());
                    Sheet sheet = new Sheet()
                    {
                        Id = document.WorkbookPart.GetIdOfPart(worksheetPart),
                        SheetId = 1,
                        Name = "Sheet1"
                    };
                    sheets.Append(sheet);

                    SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();

                    // Populate data from CSV
                    foreach (var line in lines)
                    {
                        Row row = new Row();
                        var cells = line.Split(',');

                        foreach (var cellValue in cells)
                        {
                            Cell cell = new Cell()
                            {
                                DataType = CellValues.String,
                                CellValue = new CellValue(cellValue)
                            };
                            row.Append(cell);
                        }
                        sheetData.Append(row);
                    }

                    workbookPart.Workbook.Save();
                    ok = true;
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="inpFile"></param>
            /// <param name="outFile"></param>
            /// <returns></returns>
         static bool ConvertImageToWebp(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                // Load the image using ImageSharp
                using (SixLabors.ImageSharp.Image image = SixLabors.ImageSharp.Image.Load(inpFile))
                {
                    // Save the image in WebP format
                    image.Save(outFile, new WebpEncoder());
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }




    }

调用:

代码语言:javascript
复制
string wordurl = Server.MapPath("Python.docx");
string pdfurl = Server.MapPath("geovindu.pdf");
// ConvertWordToPdf(wordurl,pdfurl);
if (File.Exists(wordurl))
{
    // ConvertFromStream(wordurl, pdfurl);
    UseOfficeHelper.Convert(wordurl, pdfurl, FileFormat.Pdf);

}

if (File.Exists(pdfurl))
{
    Response.Redirect("geovindu.pdf");
    Response.Write("ok create file");
}
else
{
    Response.Write("no file");
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-10-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档