/// <summary>
        /// Converts binary to blob pointer
        /// </summary>
        /// <param name="category">The file category.</param>
        /// <param name="data">The data.</param>
        /// <param name="name">The name.</param>
        /// <returns>Blob Pointer</returns>
        public static string ConvertToFile(string category, string name, byte[] data)
        {
            if (data == null)
            {
                return null;
            }

            using (Stream stream = new MemoryStream(data))
            {
                // convert doc, xls -> docx, xlsx
                Stream streamToSave = new MemoryStream();
                if (FileTypeDetector.IsDoc(data))
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(stream);
                    doc.RemoveMacros();
                    doc.Save(streamToSave, Aspose.Words.SaveFormat.Docx);
                }
                else if (FileTypeDetector.IsXls(data))
                {
                    Aspose.Cells.Workbook xls = new Aspose.Cells.Workbook(stream);
                    xls.RemoveMacro();
                    xls.Save(streamToSave, Aspose.Cells.SaveFormat.Xlsx);
                }
                else
                {
                    streamToSave = stream;
                }

                // save to file
                streamToSave.Position = 0;
                string result = BlobStoreProvider.Instance.PutBlob(category, name, streamToSave);

                return result;
            }
        }
        /// <summary>
        /// Converts binary to blob pointer
        /// </summary>
        /// <param name="category">The file category.</param>
        /// <param name="data">The data.</param>
        /// <param name="name">The name.</param>
        /// <returns>Blob Pointer</returns>
        public static string ConvertToFile(string category, string name, byte[] data)
        {
            if (data == null)
            {
                return(null);
            }

            using (Stream stream = new MemoryStream(data))
            {
                // convert doc, xls -> docx, xlsx
                Stream streamToSave = new MemoryStream();
                if (FileTypeDetector.IsDoc(data))
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(stream);
                    doc.RemoveMacros();
                    doc.Save(streamToSave, Aspose.Words.SaveFormat.Docx);
                }
                else if (FileTypeDetector.IsXls(data))
                {
                    Aspose.Cells.Workbook xls = new Aspose.Cells.Workbook(stream);
                    xls.RemoveMacro();
                    xls.Save(streamToSave, Aspose.Cells.SaveFormat.Xlsx);
                }
                else
                {
                    streamToSave = stream;
                }

                // save to file
                streamToSave.Position = 0;
                string result = BlobStoreProvider.Instance.PutBlob(category, name, streamToSave);

                return(result);
            }
        }
Пример #3
0
        public string ConvertFile2TempDocX(string filename)
        {
            if (filename.EndsWith("pdf"))
            {
                if (DeclaratorConversionServerUrl != "")
                {
                    try
                    {
                        return(DowloadFromConvertedStorage(filename));
                    }
                    catch (Exception exp)
                    {
                        var t = exp.GetType();
                        Logger.Debug("the file cannot be found in conversion server db, try to process this file in place");
                    }
                }
                else
                {
                    Logger.Error("no url for declarator conversion server specified!");
                }
            }
            string docXPath = filename + ".converted.docx";

            if (filename.EndsWith(".html") || filename.EndsWith(".htm"))
            {
                return(ConvertWithSoffice(filename));
            }
            var saveCulture = Thread.CurrentThread.CurrentCulture;

            // Aspose.Words cannot work well, see 7007_10.html in regression tests
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            var doc = new Aspose.Words.Document(filename);

            doc.RemoveMacros();
            doc.Save(docXPath, Aspose.Words.SaveFormat.Docx);
            Thread.CurrentThread.CurrentCulture = saveCulture;
            doc = null;
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            return(docXPath);
        }