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

 

 

   /// <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 DuConvert(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:
                        isNeedConvert=ConvertSvg(inpFile, outFile); 
                        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 = ConvertCsvToXls(inpFile, outFile);
                        break;
                    case ".xlsx":
                        isNeedConvert = 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 = 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 ConvertSvg(string inpFile, string outFile)
        {
            bool isNeedConvert = false;
            if (File.Exists(inpFile))
            {
                FileInfo fileInfo = new FileInfo(inpFile); //获上传源文件的扩展名
                switch (fileInfo.Extension.ToLower())
                {

                    case ".jpg":
                        isNeedConvert = ConvertImagedToSvg(inpFile,outFile);// ConvertJpgToSvg(inpFile, outFile);
                        break;
                    case ".png":
                        isNeedConvert = ConvertPngToSvg(inpFile, outFile);
                        break;
                    case ".gif":
                        isNeedConvert = ConvertImagedToSvg(inpFile, outFile);// ConvertGifToSvg(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 DocumentFormat.OpenXml.Spreadsheet.Workbook();

                    WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
                    worksheetPart.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.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 ConvertCsvToXls(string inpFile, string outFile)
        {
            bool ok = false;
            Encoding encoding = Encoding.UTF8;
            char delimiter = ',';
            try
            {
                DataTable dataTable = ReadCsv(inpFile, encoding, delimiter);
                ok = ConvertDataTableToXls(dataTable, outFile);

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

            }
            return ok;
        }


        /// <summary>
        /// Reads a CSV file and returns its contents as a DataTable
        /// </summary>
        static DataTable ReadCsv(string filePath, Encoding encoding, char delimiter)
        {
            try
            {
                using (var reader = new StreamReader(filePath, encoding))
                using (var csv = new CsvReader(reader, new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture)
                {
                    Delimiter = delimiter.ToString(),
                    HasHeaderRecord = true,
                    IgnoreBlankLines = true,
                    TrimOptions = CsvHelper.Configuration.TrimOptions.Trim
                }))
                {
                    using (var dr = new CsvDataReader(csv))
                    {
                        var dt = new DataTable();
                        dt.Load(dr);
                        return dt;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to read CSV file: {ex.Message}", ex);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="outputPath"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        static bool ConvertDataTableToXls(DataTable dataTable, string outputPath)
        {
            bool ok = false;
            try
            {
                // Create a new spreadsheet document
                using (SpreadsheetDocument document = SpreadsheetDocument.Create(outputPath, SpreadsheetDocumentType.Workbook))
                {
                    // Add a WorkbookPart to the document
                    WorkbookPart workbookPart = document.AddWorkbookPart();
                    workbookPart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook();

                    // Add a WorksheetPart to the WorkbookPart
                    WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
                    worksheetPart.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.Worksheet(new SheetData());

                    // Add Sheets to the Workbook
                    Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());

                    // Append a new worksheet and associate it with the workbook
                    Sheet sheet = new Sheet()
                    {
                        Id = workbookPart.GetIdOfPart(worksheetPart),
                        SheetId = 1,
                        Name = "Sheet1"
                    };
                    sheets.Append(sheet);

                    // Get the SheetData object
                    SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();

                    // Add header row
                    Row headerRow = new Row();
                    foreach (DataColumn column in dataTable.Columns)
                    {
                        Cell cell = CreateCell(column.ColumnName, CellValues.String);
                        headerRow.AppendChild(cell);
                    }
                    sheetData.AppendChild(headerRow);

                    // Add data rows
                    foreach (DataRow row in dataTable.Rows)
                    {
                        Row dataRow = new Row();
                        foreach (var item in row.ItemArray)
                        {
                            CellValues cellType = GetCellValueType(item);
                            string cellValue = GetCellValueAsString(item, cellType);
                            Cell cell = CreateCell(cellValue, cellType);
                            dataRow.AppendChild(cell);
                        }
                        sheetData.AppendChild(dataRow);
                    }

                    // Save the workbook
                    workbookPart.Workbook.Save();
                    ok = true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to create XLS file: {ex.Message}", ex);
            }
            return ok;
        }

        /// <summary>
        /// Creates a new Excel cell with the specified value and type
        /// </summary>
        private static Cell CreateCell(string value, CellValues cellType)
        {
            Cell cell = new Cell();
            cell.DataType = new EnumValue<CellValues>(cellType);
            cell.CellValue = new CellValue(value);
            return cell;
        }

        /// <summary>
        /// Determines the cell value type based on the object type
        /// </summary>
        private static CellValues GetCellValueType(object value)
        {
            if (value == DBNull.Value)
                return CellValues.String;

            Type type = value.GetType();

            if (type == typeof(int) || type == typeof(long) || type == typeof(short) || type == typeof(byte))
                return CellValues.Number;
            else if (type == typeof(float) || type == typeof(double) || type == typeof(decimal))
                return CellValues.Number;
            else if (type == typeof(DateTime))
                return CellValues.Date;
            else if (type == typeof(bool))
                return CellValues.Boolean;
            else
                return CellValues.String;
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="cellType"></param>
        /// <returns></returns>
        private static string GetCellValueAsString(object value, DocumentFormat.OpenXml.Spreadsheet.CellValues cellType)
        {
            if (value == DBNull.Value || value == null)
                return string.Empty;

            if (cellType == DocumentFormat.OpenXml.Spreadsheet.CellValues.Boolean)
            {
                return (value is bool boolVal && boolVal) ? "1" : "0";
            }
            else if (cellType == DocumentFormat.OpenXml.Spreadsheet.CellValues.Number)
            {
                if (value is DateTime dateVal)
                {
                    return dateVal.ToOADate().ToString(CultureInfo.InvariantCulture);
                }
                return Convert.ToString(value, CultureInfo.InvariantCulture);
            }
            else if (cellType == DocumentFormat.OpenXml.Spreadsheet.CellValues.String ||
                     cellType == DocumentFormat.OpenXml.Spreadsheet.CellValues.SharedString)
            {
                return Convert.ToString(value) ?? string.Empty;
            }
            else
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFileh"></param>
        /// <returns></returns>
        static bool ConvertXlsToXlsx(string inpFile, string outFileh)
        {
            bool ok=false;
            try
            {
                using (var package = new ExcelPackage(new FileInfo(outFileh)))
                {
                    using (var stream = File.OpenRead(inpFile))
                    {
                        var worksheet = package.Workbook.Worksheets.Add("Sheet1");
                        worksheet.Cells.LoadFromText(new StreamReader(stream).ReadToEnd());
                    }
                    package.Save();
                    ok = true;
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString().Trim();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xlsFilePath"></param>
        /// <param name="xlsxFilePath"></param>
        /// <returns></returns>
        static bool ConvertXlsToXlsxTwo(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                Excel.Application excelApp = new Excel.Application { Visible = false };
                Excel.Workbook workbook = excelApp.Workbooks.Open(inpFile);

                workbook.SaveAs(outFile, Excel.XlFileFormat.xlOpenXMLWorkbook); // 保存为 .xlsx 格式
                workbook.Close();
                excelApp.Quit();
                ok = true;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xlsFilePath"></param>
        /// <param name="xlsxFilePath"></param>
        /// <returns></returns>
        static bool ConvertXlsToXlsxThree(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                //创建Workbook对象
                Spire.Xls.Workbook workbook = new Spire.Xls.Workbook();

                //加载一个XLS文件
                workbook.LoadFromFile(inpFile);

                //将XLS文件另存为XLSX格式
                workbook.SaveToFile(outFile, ExcelVersion.Version2016);

                ok = true;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        static bool ConvertXlsxToXls(string inpFile, string outFile)
        {
            bool ok = false;
            try
            {
                //创建Workbook对象
                Spire.Xls.Workbook workbook = new Spire.Xls.Workbook();

                //加载一个XLSX文件
                workbook.LoadFromFile(inpFile);

                //将XLSX文件转为XLS格式
                workbook.SaveToFile(outFile, ExcelVersion.Version97to2003);
                ok = true;
            }
            catch(Exception ex)
            {
                ex.Message.ToString().Trim();   
            }
            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;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileOriginPath"></param>
        /// <param name="fileSavePath"></param>
        /// <returns></returns>
        static bool ConvertPngToSvg(string fileOriginPath, string fileSavePath)
        {
            bool ok = true;
            try
            {
                using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileOriginPath))
                {
                    Aspose.Imaging.ImageOptions.SvgOptions svgOptions = new Aspose.Imaging.ImageOptions.SvgOptions();
                    Aspose.Imaging.ImageOptions.SvgRasterizationOptions svgRasterizationOptions = new Aspose.Imaging.ImageOptions.SvgRasterizationOptions
                    {
                        PageWidth = image.Width,
                        PageHeight = image.Height
                    };
                    svgOptions.VectorRasterizationOptions = svgRasterizationOptions;
                    image.Save(fileSavePath, svgOptions);
                    ok = true;
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }

            return ok;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileOriginPath"></param>
        /// <param name="fileSavePath"></param>
        /// <returns></returns>
        static bool ConvertImagedToSvg(string fileOriginPath, string fileSavePath)
        {
            bool ok = true;
            try
            {
                using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileOriginPath))
                {
                    Aspose.Imaging.ImageOptions.SvgOptions svgOptions = new Aspose.Imaging.ImageOptions.SvgOptions();
                    Aspose.Imaging.ImageOptions.SvgRasterizationOptions svgRasterizationOptions = new Aspose.Imaging.ImageOptions.SvgRasterizationOptions
                    {
                        PageWidth = image.Width,
                        PageHeight = image.Height
                    };
                    svgOptions.VectorRasterizationOptions = svgRasterizationOptions;
                    image.Save(fileSavePath, svgOptions);
                    ok = true;
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }

            return ok;
        }
    }

  

 

 

 

 

 调用:

string wordurl = Server.MapPath("Python.docx");
string pdfurl = Server.MapPath("geovindu.pdf");
// ConvertWordToPdf(wordurl,pdfurl);
if (File.Exists(wordurl))
{
    // ConvertFromStream(wordurl, pdfurl);
    UseOfficeHelper.DuConvert(wordurl, pdfurl, FileFormat.Pdf);

}

if (File.Exists(pdfurl))
{
    Response.Redirect("geovindu.pdf");
    Response.Write("ok create file");
}
else
{
    Response.Write("no file");
}

  

 

 

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml.Presentation;
using SautinSoft.Document;
using SautinSoft.Document.MailMerging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;



namespace MicorosoftOfficeDemo
{

    /// <summary>
    /// 
    /// </summary>
    public partial class sautinsoftcovertpdf : System.Web.UI.Page
    {


        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    string wordurl = Server.MapPath("geovindu.docx");
                    string pdfurl = Server.MapPath("geovindu.pdf");
                    // ConvertWordToPdf(wordurl,pdfurl);
                    if (File.Exists(wordurl))
                        ConvertDocxTopdfFromStream(wordurl, pdfurl);

                    if (File.Exists(pdfurl))
                    {
                        Response.Write("ok create file");
                    }
                    else
                    {
                        Response.Write("no file");
                    }

                }
                catch (Exception ex)
                {
                    Response.Write(ex.ToString());
                }
            }
        }


        /// <summary>
        ///Docx
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertDocxTopdfFromStream(string inpFile, string outFile)
        {

            // 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 });
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertDocToPdf(string inpFile, string outFile)
        {
            // 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");
                return;
            }

            // 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 });
            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");


        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertDocTohtml(string inpFile, string outFile)
        {

            // 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");
                return;
            }

            // 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 });
            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertDocxToHtml(string inpFile, string outFile)
        {
            // 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");
                return;
            }

            // 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 });
            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void DocxConvertWordToPdf(string inpFile, string outFile)
        {
            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");
                return;
            }

            // 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 });
            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertPPTToPdf(string inpFile, string outFile)
        {
            // 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");
                return;
            }

            // 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 });

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

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertPPTXToPdf(string inpFile, string outFile)
        {
            // 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");
                return;
            }

            // 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 });

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

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertXlsToPdf(string inpFile, string outFile)
        {
            // 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");
                return;
            }

            // 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 });
            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertXlsxToPdf(string inpFile, string outFile)
        {
            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");
                return;
            }

            // 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 });
            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertXlsToHtml(string inpFile, string outFile)
        {
            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");
                return;
            }

            // 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 });
            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inpFile"></param>
        /// <param name="outFile"></param>
        static void ConvertXlsxToHtml(string inpFile, string outFile)
        {
            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");
                return;
            }
            // 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 });
            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support:");

         }
    }
}

  

using System;
using System.IO;
using System.Collections.Generic;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
			// Before starting, we recommend to get a free key:
            // https://sautinsoft.com/start-for-free/
            
            // Apply the key here:
			// UseOffice.SetLicense("...");

            // Convert Word Excel PowerPoint documents to PDF format.
            // If you need more information about UseOffice .Net email us at:
            // support@sautinsoft.com.
            SautinSoft.UseOffice u = new SautinSoft.UseOffice();

            // The directory which contains Word, Excel, PowerPoint files: *.doc, *.docx, *.rtf, *.txt, *.xls, *.xlsx, *.csv, *.ppt, *.pptx
            string directoryWithFiles = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\");

            //Prepare UseOffice .Net, loads MS Word, Excel, PowerPoint into memory
            int ret = u.InitOffice();

            // Return values:
            // 0 - Loading successfully
            // 1 - Can't load MS Excel (Word and PowePoint are loaded successfully)
            // 10 - Can't load MS Word (Excel and PowerPoint are loaded successfully)
            // 11 - Can't load MS Word and Excel (PowerPoint loaded successfully)
            // 100 - Can't load MS PowerPoint (Excel and Word are loaded successfully)
            // 101 - Can't load MS Excel and PowerPoint (Word loaded successfully)
            // 110 - Can't load PowerPoint and Word (Excel loaded successfully)
            // 111 - Can't load MS Office

            if (ret == 111)
                return;

            string[] filters = null;

            switch (ret)
            {
                case 0: filters = new string[] { "*.doc", "*.docx", "*.rtf", "*.txt", "*.xls", "*.xlsx", "*.csv", "*.ppt", "*.pptx" }; break;
                case 1: filters = new string[] { "*.doc", "*.docx", "*.rtf", "*.txt", "*.ppt", "*.pptx" }; break;
                case 10: filters = new string[] { "*.xls", "*.xlsx", "*.csv", "*.ppt", "*.pptx" }; break;
                case 11: filters = new string[] { "*.ppt", "*.pptx" }; break;
                case 100: filters = new string[] { "*.doc", "*.docx", "*.rtf", "*.txt", "*.xls", "*.xlsx", "*.csv" }; break;
                case 101: filters = new string[] { "*.doc", "*.docx", "*.rtf", "*.txt" }; break;
                case 110: filters = new string[] { "*.xls", "*.xlsx", "*.csv" }; break;
                default: return;
            }

            // Convert all documents (Word, Excel, PorwerPoint) to PDF.

            // 1. Get list of MS Office files from directory
            List<string> inpFiles = new List<string>();

            foreach (string filter in filters)
            {
                inpFiles.AddRange(Directory.GetFiles(directoryWithFiles, filter));
            }

            // 2. Convert all documents to PDF.
            string ext = "";
            string outFilePath = "";
            DirectoryInfo outDir = new DirectoryInfo(Directory.GetCurrentDirectory()).CreateSubdirectory("Results");

            for (int i = 0; i < inpFiles.Count; i++)
            {
                SautinSoft.UseOffice.eDirection direction = SautinSoft.UseOffice.eDirection.DOC_to_PDF;
                ext = Path.GetExtension((string)inpFiles[i]).ToLower();

                // doc and docx
                if (ext.IndexOf("doc") > 0)
                    direction = SautinSoft.UseOffice.eDirection.DOC_to_PDF;
                else if (ext.IndexOf("rtf") > 0)
                    direction = SautinSoft.UseOffice.eDirection.RTF_to_PDF;
                else if (ext.IndexOf("txt") > 0)
                    direction = SautinSoft.UseOffice.eDirection.TEXT_to_PDF;
                // xls and xlsx
                else if (ext.IndexOf("xls") > 0)
                    direction = SautinSoft.UseOffice.eDirection.XLS_to_PDF;
                else if (ext.IndexOf("csv") > 0)
                    direction = SautinSoft.UseOffice.eDirection.XLS_to_PDF;
                // ppt and pptx
                else if (ext.IndexOf("ppt") > 0)
                    direction = SautinSoft.UseOffice.eDirection.PPT_to_PDF;

                // Save the result into the current directory
                string outFileName = (Path.GetExtension(inpFiles[i]) + "topdf.pdf").TrimStart('.');
                outFilePath = Path.Combine(outDir.FullName, outFileName);

                u.ConvertFile((string)inpFiles[i], outFilePath, direction);

                Console.WriteLine($"{i + 1} of {inpFiles.Count}...");
            }
            Console.WriteLine("Done!");

            u.CloseOffice();

            // Open the folder (current directory) with the results.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outDir.FullName) { UseShellExecute = true });

        }
    }
}

  

posted @ 2025-10-22 23:06  ®Geovin Du Dream Park™  阅读(11)  评论(0)    收藏  举报