Esempio n. 1
0
        public string ConvertFiletoPDF(string FileName)
        {
            string FilePath = "";

            try
            {
                var request = new ConvertToPdfRequest
                {
                    Request = new PdfConversionRequest
                    {
                        SourceFile = new ConversionFileInfo()
                        {
                            Folder = Constants.StorageSourceFolder, Name = FileName, Password = ""
                        },
                        Options = new PdfSaveOptionsDto()
                    }
                };
                var response = ObjConversionApi.ConvertToPdf(request);
                FilePath = response.Href.ToString();
            }
            catch (Exception ex)
            {
            }
            return(FilePath.Substring(FilePath.IndexOf(Constants.StorageConversionFolder) + Constants.StorageConversionFolder.Length));
        }
        /// <summary>
        /// Returns PDF document, result of conversion of the source file, specified by the provided PdfConversionSettings
        /// </summary>
        /// <param name="request">Request. <see cref="ConvertToPdfRequest" /></param>
        /// <returns><see cref="Link"/></returns>
        public Link ConvertToPdf(ConvertToPdfRequest request)
        {
            // create path and map variables
            var resourcePath = this.configuration.GetApiRootUrl() + "/conversion/pdf";

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "outPath", request.OutPath);
            var postBody = SerializationHelper.Serialize(request.Request); // http body (model) parameter
            var response = this.apiInvoker.InvokeApi(
                resourcePath,
                "POST",
                postBody,
                null,
                null);

            if (response != null)
            {
                return((Link)SerializationHelper.Deserialize(response, typeof(Link)));
            }

            return(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 Pdf request
                var request = new ConvertToPdfRequest
                {
                    OutPath = "conversions/ResourceOptimizationPDF",
                    // convert to Pdf settings
                    Request = new PdfConversionRequest
                    {
                        // source file to convert
                        SourceFile = new ConversionFileInfo()
                        {
                            Folder = "conversions", Name = "sample-one-page.docx", Password = ""
                        },
                        // Pdf save options
                        Options = new PdfSaveOptionsDto()
                        {
                            ConvertFileType = GroupDocs.Conversion.Cloud.Sdk.Model.PdfSaveOptionsDto.ConvertFileTypeEnum.Pdf, PdfOptions = new PdfOptionsDto()
                            {
                                OptimizationOptions = new PdfOptimizationOptionsDto()
                                {
                                    LinkDuplicateStreams = true, RemoveUnusedObjects = true, RemoveUnusedStreams = true, CompressImages = true, ImageQuality = 60, UnembedFonts = true
                                }
                            }
                        }
                    }
                };

                // convert to Pdf
                var response = apiInstance.ConvertToPdf(request);
                Console.WriteLine(response.Href.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling ConversionApi: " + e.Message);
            }
        }
Esempio 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 ConvertToPdfRequest
                {
                    OutPath = "conversions/WordBookmarksPDF",
                    // convert to Pdf settings
                    Request = new PdfConversionRequest
                    {
                        // source file to convert
                        SourceFile = new ConversionFileInfo()
                        {
                            Folder = "conversions", Name = "sample-one-page.docx", Password = ""
                        },
                        // Pdf save options
                        Options = new PdfSaveOptionsDto()
                        {
                            ConvertFileType = GroupDocs.Conversion.Cloud.Sdk.Model.PdfSaveOptionsDto.ConvertFileTypeEnum.Pdf, WordBookmarksOptions = new WordBookmarksOptionsDto()
                            {
                                BookmarksOutlineLevel = 4, HeadingsOutlineLevels = 1, ExpandedOutlineLevels = 9
                            }, PdfOptions = new PdfOptionsDto()
                        }
                    }
                };

                // convert to Pdf
                var response = apiInstance.ConvertToPdf(request);
                Console.WriteLine(response.Href.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling ConversionApi: " + e.Message);
            }
        }
Esempio n. 5
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 ConvertToPdfRequest
                {
                    OutPath = "conversions/CellsOptionsPDF",
                    // convert to Pdf settings
                    Request = new PdfConversionRequest
                    {
                        // source file to convert
                        SourceFile = new ConversionFileInfo()
                        {
                            Folder = "conversions", Name = "three-sheets.xlsx", Password = ""
                        },
                        // Pdf save options
                        Options = new PdfSaveOptionsDto()
                        {
                            ConvertFileType = GroupDocs.Conversion.Cloud.Sdk.Model.PdfSaveOptionsDto.ConvertFileTypeEnum.Pdf, CellsOptions = new CellsOptionsDto()
                            {
                                ShowGridLines = true, ShowHiddenSheets = false, OnePagePerSheet = false, OptimizePdfSize = true, ConvertRange = "", SkipEmptyRowsAndColumns = true
                            }, PdfOptions = new PdfOptionsDto()
                        }
                    }
                };

                // convert to Pdf
                var response = apiInstance.ConvertToPdf(request);
                Console.WriteLine(response.Href.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling ConversionApi: " + e.Message);
            }
        }
        public void ConvertToPdf()
        {
            var file = TestFiles.OnePageDocx;

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

            var response = ConversionApi.ConvertToPdf(request);

            Assert.IsNotNull(response);
            Assert.That(() => response.Href.EndsWith(".pdf"));
        }
Esempio n. 7
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 ConvertToPdfRequest
                {
                    // 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.ConvertToPdf(request);
                Console.WriteLine(response.Href.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling ConversionApi.ConvertToPdf: " + e.Message);
            }
        }