GroupDocsGists
10/24/2017 - 1:18 PM

Examples-CSharp-GroupDocs.Signature.Examples.CSharp-Utilities-SaveFileWithFormat.cs

// For complete examples and data files, please go to https://github.com/groupdocs-signature/GroupDocs.Signature-for-.NET
try
{
    switch (fileExtension)
    {
        case ".docx":
            if (textSignOptions != null)
            {
                WordsSignTextOptions wordTextSignOptions = (WordsSignTextOptions)textSignOptions;
                //var wordTextSignedPath = handler.Sign<string>(fileName, wordTextSignOptions, new SaveOptions { OutputType = OutputType.String });
                var wordTextSignedPath = handler.Sign<string>(fileName, wordTextSignOptions, new WordsSaveOptions {OutputType = OutputType.String, FileFormat = Domain.WordsSaveFileFormat.Dot});
            }
            else if (textSignOptions == null && imageSignOptions != null)
            {
                WordsSignImageOptions wordImageSignOptions = (WordsSignImageOptions)imageSignOptions;
                var wordImageSignedPath = handler.Sign<string>(fileName, wordImageSignOptions, new WordsSaveOptions { OutputType = OutputType.String, FileFormat = Domain.WordsSaveFileFormat.Dot });
            }
            else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
            {
                WordsSignDigitalOptions wordDigitalSignOptions = (WordsSignDigitalOptions)digitalSignOptions;
                var wordDigitalSignedPath = handler.Sign<string>(fileName, wordDigitalSignOptions, new WordsSaveOptions { OutputType = OutputType.String, FileFormat = Domain.WordsSaveFileFormat.Dotm });
            }

            break;
        case ".pdf":
            if (textSignOptions != null)
            {
                PdfSignTextOptions pdfTextSignOptions = (PdfSignTextOptions)textSignOptions;
                var pdfTextSignedPath = handler.Sign<string>(fileName, pdfTextSignOptions, new PdfSaveOptions { OutputType = OutputType.String, FileFormat = Domain.PdfSaveFileFormat.Doc });
            }
            else if (textSignOptions == null && imageSignOptions != null)
            {
                PdfSignImageOptions pdfImageSignOptions = (PdfSignImageOptions)imageSignOptions;
                var pdfImageSignedPath = handler.Sign<string>(fileName, pdfImageSignOptions, new PdfSaveOptions { OutputType = OutputType.String, FileFormat = Domain.PdfSaveFileFormat.Doc });
            }
            else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
            {
                PdfSignDigitalOptions pdfDigitalSignOptions = (PdfSignDigitalOptions)digitalSignOptions;
                var pdfDigitalSignedPath = handler.Sign<string>(fileName, pdfDigitalSignOptions, new PdfSaveOptions { OutputType = OutputType.String, FileFormat = Domain.PdfSaveFileFormat.Pdf });
            }

            break;
        case ".xlsx":
            if (textSignOptions != null)
            {
                CellsSignTextOptions cellTextSignOptions = (CellsSignTextOptions)textSignOptions;
                var cellTextSignedPath = handler.Sign<string>(fileName, cellTextSignOptions, new CellsSaveOptions { OutputType = OutputType.String, FileFormat = Domain.CellsSaveFileFormat.Xlsm });
            }
            else if (textSignOptions == null && imageSignOptions != null)
            {
                CellsSignImageOptions cellImageSignOptions = (CellsSignImageOptions)imageSignOptions;
                var cellImageSignedPath = handler.Sign<string>(fileName, cellImageSignOptions, new CellsSaveOptions { OutputType = OutputType.String, FileFormat = Domain.CellsSaveFileFormat.Xlsm });
            }
            else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
            {
                CellsSignDigitalOptions cellDigitalSignOptions = (CellsSignDigitalOptions)digitalSignOptions;
                var cellDigitalSignedPath = handler.Sign<string>(fileName, cellDigitalSignOptions, new CellsSaveOptions { OutputType = OutputType.String, FileFormat = Domain.CellsSaveFileFormat.Xlsm });
            }

            break;
        case ".pptx":
            if (textSignOptions != null)
            {
                SlidesSignTextOptions slildeTextSignOptions = (SlidesSignTextOptions)textSignOptions;
                var slideTextSignedPath = handler.Sign<string>(fileName, slildeTextSignOptions, new SlidesSaveOptions { OutputType = OutputType.String, FileFormat = Domain.SlidesSaveFileFormat.Odp });
            }
            else if (textSignOptions == null && imageSignOptions != null)
            {
                SlidesSignImageOptions slideImageSignOptions = (SlidesSignImageOptions)imageSignOptions;
                var slideImageSignedPath = handler.Sign<string>(fileName, slideImageSignOptions, new SlidesSaveOptions { OutputType = OutputType.String, FileFormat = Domain.SlidesSaveFileFormat.Odp });
            }
            else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
            {
                SlidesSignDigitalOptions slideDigitalSignOptions = (SlidesSignDigitalOptions)digitalSignOptions;
                var slideDigitalSignedPath = handler.Sign<string>(fileName, slideDigitalSignOptions, new SlidesSaveOptions { OutputType = OutputType.String });
            }

            break;
    }
}
catch (System.Exception ex)
{
    Console.WriteLine(ex.Message);
}