Esempio n. 1
0
        public string Test()
        {
            SautinSoft.UseOffice u = new SautinSoft.UseOffice();
            var res = u.InitOffice();

            return(res.ToString());
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Convert DOCX to PDF in memory.
            // If you need more information about UseOffice .Net email us at:
            // [email protected].

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

            // We need files to read data from it and demostrate the result of conversion.
            string inpFile = Path.GetFullPath(@"..\..\..\..\..\Testing files\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.
            byte[] docxBytes = File.ReadAllBytes(inpFile);
            byte[] pdfBytes  = null;

            // If you are making the conversion on a server, please specify this temporary
            // directory and set read/write permissions on it.
            // You may set any path.
            u.TemporaryDirectory = Path.GetTempPath();
            pdfBytes             = u.ConvertBytes(docxBytes, 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 (pdfBytes != null)
            {
                // Open the result.
                File.WriteAllBytes(outFile, pdfBytes);
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                {
                    UseShellExecute = true
                });
            }
            else
            {
                Console.WriteLine("Error! Please contact with SautinSoft support: [email protected].");
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // Convert DOC file to PDF file.
            // If you need more information about UseOffice .Net email us at:
            // [email protected].

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

            string inpFile = Path.GetFullPath(@"..\..\..\..\..\Testing files\example.doc");
            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;
            }
            // Specify A3 page size
            u.PageStyle.PageSize.A3();
            // Set 30 mm as left margin
            u.PageStyle.PageMarginLeft.mm(30f);

            // Perform the conversion.
            ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.DOC_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: [email protected].");
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // Convert PPTX file to JPG file
            // If you need more information about UseOffice .Net email us at:
            // [email protected].
            SautinSoft.UseOffice u = new SautinSoft.UseOffice();

            string inpFile   = Path.GetFullPath(@"..\..\..\..\..\Testing files\example.pptx");
            string outFolder = Path.GetFullPath(@"Result");

            // 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, outFolder, SautinSoft.UseOffice.eDirection.PPTX_to_JPG);

            // 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(outFolder)
                {
                    UseShellExecute = true
                });
            }
            else
            {
                Console.WriteLine("Error! Please contact with SautinSoft support: [email protected].");
            }
        }
Esempio n. 5
0
        public static int Word_To_PDF(string Word_In_File, string PDF_Out_File)
        {
            SautinSoft.UseOffice u = new SautinSoft.UseOffice();

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

            u.Serial = "10006108851";

            //Return values:
            //0 - Loading successfully
            //1 - Can't load MS Word® library in memory (returned as 4)

            if (ret == 1)
            {
                return(4);
            }

            if (Word_In_File.ToUpper().IndexOf(".DOCX") > 0)
            {
                //Converting
                ret = u.ConvertFile(Word_In_File, PDF_Out_File, SautinSoft.UseOffice.eDirection.DOCX_to_PDF);
            }
            else
            {
                //Converting
                ret = u.ConvertFile(Word_In_File, PDF_Out_File, SautinSoft.UseOffice.eDirection.DOC_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 or 2010
            return(ret);
        }
        public static int Word_To_PDF( string Word_In_File, string PDF_Out_File )
        {
            SautinSoft.UseOffice u = new SautinSoft.UseOffice();

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

            //Return values:
            //0 - Loading successfully
            //1 - Can't load MS Word® library in memory (returned as 4)

            if (ret == 1)
                return 4;

            if (Word_In_File.ToUpper().IndexOf(".DOCX") > 0)
            {
                //Converting
                ret = u.ConvertFile(Word_In_File, PDF_Out_File, SautinSoft.UseOffice.eDirection.DOCX_to_PDF);
            }
            else
            {
                //Converting
                ret = u.ConvertFile(Word_In_File, PDF_Out_File, SautinSoft.UseOffice.eDirection.DOC_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 or 2010
            return ret;
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            // Convert Word Excel PowerPoint documents to PDF format.
            // If you need more information about UseOffice .Net email us at:
            // [email protected].
            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(@"..\..\..\..\..\Testing files\");

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