/// <summary>
        /// Returns PDF stream, result of conversion of the source file, specified by the provided PdfConversionSettings
        /// </summary>
        /// <param name="request">Request. <see cref="ConvertToPdfStreamRequest" /></param>
        /// <returns><see cref="System.IO.Stream"/></returns>
        public System.IO.Stream ConvertToPdfStream(ConvertToPdfStreamRequest request)
        {
            // create path and map variables
            var resourcePath = this.configuration.GetApiRootUrl() + "/conversion/pdf/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 void ConvertToPdfStream()
        {
            var file = TestFiles.OnePageDocx;

            var request = new ConvertToPdfStreamRequest
            {
                Settings = new PdfConversionSettings
                {
                    SourceFile = ToConversionFileInfo(file),
                    Options    = new PdfSaveOptionsDto()
                }
            };

            var response = ConversionApi.ConvertToPdfStream(request);

            Assert.IsNotNull(response);
            Assert.Greater(response.Length, 0);
        }
Exemplo n.º 3
0
    public static void ConvertToPdfStream(string fileName)
    {
        var configuration = new Configuration
        {
            AppSid = Common.MyAppSid,
            AppKey = Common.MyAppKey
        };

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

        try
        {
            // convert to Pdf request
            var request = new ConvertToPdfStreamRequest
            {
                // convert to Pdf Request
                Request = new PdfConversionRequest
                {
                    // source file to convert
                    SourceFile = new ConversionFileInfo()
                    {
                        Folder = "input_dir", Name = fileName, Password = ""
                    },
                    // Pdf save options
                    Options = new PdfSaveOptionsDto()
                }
            };

            // convert to Pdf
            Stream response = apiInstance.ConvertToPdfStream(request);

            using (System.IO.FileStream output = new System.IO.FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"../Data/output_dir/") + Path.GetFileNameWithoutExtension(fileName) + ".pdf", FileMode.Create))
            {
                response.CopyTo(output);
            }

            Console.WriteLine(response.Length.ToString());
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception when calling ConversionApi.ConvertToPdfStream: " + e.Message);
        }
    }
Exemplo n.º 4
0
        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 Pdf request
                var request = new ConvertToPdfStreamRequest
                {
                    // convert to Pdf Request
                    Request = new PdfConversionRequest
                    {
                        // source file to convert
                        SourceFile = new ConversionFileInfo()
                        {
                            Folder = "conversions", Name = "sample.docx", Password = ""
                        },
                        // Pdf save options
                        Options = new PdfSaveOptionsDto()
                    }
                };

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