public void TestOpenSavePresentationWithOptions()
        {
            // Load
            var testFile    = TestFiles.PresentationWithHiddenSlide;
            var loadOptions = new PresentationLoadOptions
            {
                FileInfo         = testFile.ToFileInfo(),
                OutputPath       = DefaultOutputPath,
                ShowHiddenSlides = true,
                SlideNumber      = 0
            };

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

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

            // Save
            var saveOptions = new PresentationSaveOptions
            {
                FileInfo      = testFile.ToFileInfo(),
                HtmlPath      = loadResult.HtmlPath,
                ResourcesPath = loadResult.ResourcesPath,
                OutputPath    = $"{DefaultOutputPath}/{testFile.FileName}",
                Password      = "******"
            };

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

            Assert.AreEqual(saveOptions.OutputPath, saveResult.Path);
        }
Esempio n. 2
0
        /// <summary>
        /// Sign presentation and save it to different output type
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # SaveSignedPresentationWithDifferentOutputFileType : Sign presentation and save it to different output type\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_PRESENTATION;
            string fileName = Path.GetFileName(filePath);

            string outputFilePath = Path.Combine(Constants.OutputPath, "SaveSignedOutputType", "Sample_PptxToTiff.tiff");

            using (Signature signature = new Signature(filePath))
            {
                // create QRCode option with predefined QRCode text
                QrCodeSignOptions signOptions = new QrCodeSignOptions("JohnSmith")
                {
                    // setup QRCode encoding type
                    EncodeType = QrCodeTypes.QR,
                    // set signature position
                    Left = 100,
                    Top  = 100
                };

                PresentationSaveOptions saveOptions = new PresentationSaveOptions()
                {
                    FileFormat             = PresentationSaveFileFormat.Tiff,
                    OverwriteExistingFiles = true
                };
                // sign document to file
                SignResult result = signature.Sign(outputFilePath, signOptions, saveOptions);
                Console.WriteLine($"\nSource document signed successfully with {result.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}.");
            }
        }
        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 PresentationLoadOptions
                {
                    FileInfo = new FileInfo
                    {
                        FilePath = "Presentation/with-notes.pptx"
                    },
                    OutputPath  = "output",
                    SlideNumber = 0
                };

                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("Slide sub-heading", "Hello world!");

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

                // Save html back to pptx
                var saveOptions = new PresentationSaveOptions
                {
                    FileInfo      = loadOptions.FileInfo,
                    OutputPath    = "output/edited.pptx",
                    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 ISaveOptions GetSaveOptions(string guid)
        {
            string       extension = Path.GetExtension(guid).Replace(".", "").ToLowerInvariant();
            ISaveOptions options   = null;

            if (extension.ToLowerInvariant().Equals("txt"))
            {
                options = new TextSaveOptions();
            }
            else
            {
                foreach (var item in typeof(WordProcessingFormats).GetFields())
                {
                    if (item.Name.ToLowerInvariant().Equals("auto"))
                    {
                        continue;
                    }
                    if (item.Name.ToLowerInvariant().Equals(extension))
                    {
                        WordProcessingFormats format = WordProcessingFormats.FromExtension(extension);
                        options = new WordProcessingSaveOptions(format);
                        break;
                    }
                }

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

                    if (item.Name.ToLowerInvariant().Equals(extension))
                    {
                        PresentationFormats format = PresentationFormats.FromExtension(extension);
                        options = new PresentationSaveOptions(format);
                        break;
                    }
                }

                if (options == null)
                {
                    SpreadsheetFormats format = SpreadsheetFormats.FromExtension(extension);
                    options = new SpreadsheetSaveOptions(format);
                }
            }

            return(options);
        }