public void TestOpenSaveDocxWithOptions()
        {
            // Load
            var testFile    = TestFiles.PasswordProtectedDocx;
            var loadOptions = new WordProcessingLoadOptions
            {
                FileInfo         = testFile.ToFileInfo(),
                OutputPath       = DefaultOutputPath,
                EnablePagination = true,
                FontExtraction   = WordProcessingLoadOptions.FontExtractionEnum.ExtractAll
            };

            var loadResult = EditApi.Load(new LoadRequest(loadOptions));

            Assert.IsNotEmpty(loadResult.HtmlPath);
            Assert.IsNotEmpty(loadResult.ResourcesPath);

            // Save
            var saveOptions = new WordProcessingSaveOptions
            {
                FileInfo           = testFile.ToFileInfo(),
                HtmlPath           = loadResult.HtmlPath,
                ResourcesPath      = loadResult.ResourcesPath,
                OutputPath         = $"{DefaultOutputPath}/{testFile.FileName}",
                EnablePagination   = true,
                Format             = "Docx",
                Password           = testFile.Password,
                ProtectionPassword = testFile.Password,
                ProtectionType     = WordProcessingSaveOptions.ProtectionTypeEnum.AllowOnlyComments
            };

            var saveResult = EditApi.Save(new SaveRequest(saveOptions));

            Assert.AreEqual(saveOptions.OutputPath, saveResult.Path);
        }
        public static void Run()
        {
            try
            {
                // Create necessary API instances
                var apiInstance = new ConvertApi(Constants.GetConfig());

                // Prepare convert settings
                var loadOptions = new WordProcessingLoadOptions
                {
                    HideWordTrackedChanges = true
                };

                var settings = new ConvertSettings
                {
                    StorageName = Constants.MyStorage,
                    FilePath    = "WordProcessing/with_tracked_changes.docx",
                    Format      = "pdf",
                    LoadOptions = loadOptions,
                    OutputPath  = "converted"
                };

                // Convert to specified format
                var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
                Console.WriteLine("Document converted successfully: " + response[0].Url);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
        public static void Run()
        {
            try
            {
                // Create necessary API instances
                var editApi = new EditApi(Common.GetConfig());
                var fileApi = new FileApi(Common.GetConfig());

                // The document already uploaded into the storage.
                // Load it into editable state
                var loadOptions = new WordProcessingLoadOptions
                {
                    FileInfo = new FileInfo
                    {
                        FilePath = "WordProcessing/password-protected.docx",
                        Password = "******"
                    },
                    OutputPath = "output"
                };

                var loadResult = editApi.Load(new LoadRequest(loadOptions));

                // Download html document
                var stream     = fileApi.DownloadFile(new DownloadFileRequest(loadResult.HtmlPath));
                var htmlString = new StreamReader(stream, Encoding.UTF8).ReadToEnd();

                // Edit something...
                htmlString = htmlString.Replace("Sample test text", "Hello world");

                // Upload html back to storage
                fileApi.UploadFile(new UploadFileRequest(loadResult.HtmlPath,
                                                         new MemoryStream(Encoding.UTF8.GetBytes(htmlString))));

                // Save html back to docx
                var saveOptions = new WordProcessingSaveOptions
                {
                    FileInfo      = loadOptions.FileInfo,
                    OutputPath    = "output/edited.docx",
                    HtmlPath      = loadResult.HtmlPath,
                    ResourcesPath = loadResult.ResourcesPath
                };

                var saveResult = editApi.Save(new SaveRequest(saveOptions));

                // Done.
                Console.WriteLine("Document edited: " + saveResult.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
        private static ILoadOptions GetLoadOptions(string guid)
        {
            string       extension = Path.GetExtension(guid).Replace(".", "").ToLowerInvariant();
            ILoadOptions options   = null;

            foreach (var item in typeof(WordProcessingFormats).GetFields())
            {
                if (item.Name.ToLowerInvariant().Equals("auto"))
                {
                    continue;
                }

                if (item.Name.ToLowerInvariant().Equals(extension))
                {
                    options = new WordProcessingLoadOptions();
                    break;
                }
            }

            foreach (var item in typeof(PresentationFormats).GetFields())
            {
                if (item.Name.ToLowerInvariant().Equals("auto"))
                {
                    continue;
                }

                if (item.Name.ToLowerInvariant().Equals(extension))
                {
                    options = new PresentationLoadOptions();
                    break;
                }
            }

            foreach (var item in typeof(SpreadsheetFormats).GetFields())
            {
                if (item.Name.ToLowerInvariant().Equals("auto"))
                {
                    continue;
                }

                if (item.Name.ToLowerInvariant().Equals(extension))
                {
                    options = new SpreadsheetLoadOptions();
                    break;
                }
            }

            return(options);
        }
Beispiel #5
0
        public static void Run()
        {
            try
            {
                // Create necessary API instances
                var apiInstance = new ConvertApi(Constants.GetConfig());

                // Prepare convert settings
                var loadOptions = new WordProcessingLoadOptions
                {
                    AutoFontSubstitution = false,
                    DefaultFont          = "Helvetica",
                    FontSubstitutes      = new Dictionary <string, string>
                    {
                        { "Tahoma", "Arial" }, { "Times New Roman", "Arial" }
                    }
                };

                var settings = new ConvertSettings
                {
                    StorageName = Constants.MyStorage,
                    FilePath    = "WordProcessing/with_tracked_changes.docx",
                    Format      = "pdf",
                    LoadOptions = loadOptions,
                    OutputPath  = "converted"
                };

                // Convert to specified format
                var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
                Console.WriteLine("Document converted successfully: " + response[0].Url);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }