Example #1
0
        public void ConvertToImageStream()
        {
            var file = TestFiles.OnePageDocx;

            var request = new ConvertToImageStreamRequest
            {
                Settings = new ImageConversionSettings
                {
                    SourceFile = ToConversionFileInfo(file),
                    Options    = new ImageSaveOptionsDto()
                }
            };

            var response = ConversionApi.ConvertToImageStream(request);

            Assert.IsNotNull(response);
            Assert.Greater(response.Length, 0);
        }
        /// <summary>
        /// Returns IMAGE stream, result of conversion of the source file, specified by the provided ImageConversionSettings
        /// </summary>
        /// <param name="request">Request. <see cref="ConvertToImageStreamRequest" /></param>
        /// <returns><see cref="System.IO.Stream"/></returns>
        public System.IO.Stream ConvertToImageStream(ConvertToImageStreamRequest request)
        {
            // create path and map variables
            var resourcePath = this.configuration.GetApiRootUrl() + "/conversion/image/stream";

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            var postBody = SerializationHelper.Serialize(request.Request); // http body (model) parameter

            return(this.apiInvoker.InvokeBinaryApi(
                       resourcePath,
                       "POST",
                       postBody,
                       null,
                       null));
        }
        public static void Run()
        {
            var configuration = new Configuration
            {
                AppSid = Common.MyAppSid,
                AppKey = Common.MyAppKey
            };

            // Initiate api instance
            var apiInstance = new ConversionApi(configuration);

            try
            {
                // convert to Image request
                var request = new ConvertToImageStreamRequest
                {
                    // convert to Image Request
                    Request = new ImageConversionRequest
                    {
                        // source file to convert
                        SourceFile = new ConversionFileInfo()
                        {
                            Folder = "conversions", Name = "sample-one-page.docx", Password = ""
                        },
                        // Image save options
                        Options = new ImageSaveOptionsDto()
                    }
                };

                // convert to Image
                var response = apiInstance.ConvertToImageStream(request);
                Console.WriteLine(response.Length.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling ConversionApi.ConvertToImageStream: " + e.Message);
            }
        }