public static void Run() { var configuration = new Configuration { AppSid = Common.MyAppSid, AppKey = Common.MyAppKey }; var apiInstance = new ConversionApi(configuration); try { var request = new GetAllPossibleConversionsRequest(); // Get supported file formats var response = apiInstance.GetAllPossibleConversions(request); foreach (var entry in response.Conversions) { Console.WriteLine(string.Format("{0}: {1}", entry.SourceFileType, string.Join(",", entry.PossibleConversions))); } } catch (Exception e) { Console.WriteLine("Exception when calling ConversionApi.GetAllPossibleConversions: " + e.Message); } }
public static void Run() { var configuration = new Configuration { AppSid = Common.MyAppSid, AppKey = Common.MyAppKey }; var apiInstance = new ConversionApi(configuration); try { var request = new GetPossibleConversionsForFileTypeRequest { Extension = "docx" }; // Get supported file formats for specified file extension var response = apiInstance.GetPossibleConversionsForFileType(request); Console.WriteLine(string.Format("{0}: {1}", response.SourceFileType, string.Join(",", response.PossibleConversions))); } catch (Exception e) { Console.WriteLine("Exception when calling ConversionApi.GetPossibleConversionsForFileType: " + e.Message); } }
public static void Run() { var configuration = new Configuration { AppSid = Common.MyAppSid, AppKey = Common.MyAppKey }; var apiInstance = new ConversionApi(configuration); try { var request = new PossibleConversionsForDocumentRequest { File = Convert_To_Cells_Stream.Run() }; // Get supported file formats for specified document type var response = apiInstance.PossibleConversionsForDocument(request); Console.WriteLine(string.Format("{0}: {1}", response.SourceFileType, string.Join(",", response.PossibleConversions))); } catch (Exception e) { Console.WriteLine("Exception when calling ConversionApi.PossibleConversionsForDocument: " + e.Message); } }
public void GetSupportedFileFormatsTest() { var request = new GetAllPossibleConversionsRequest(); var response = ConversionApi.GetAllPossibleConversions(request); Assert.IsTrue(response.Count > 0); foreach (var entry in response) { Assert.IsNotEmpty(entry.SourceFileType); Assert.IsNotEmpty(entry.PossibleConversions); } }
public void GetSupportedFileFormatsForSpecificFileTypeTest() { var request = new GetPossibleConversionsForFileTypeRequest("docx"); var response = ConversionApi.GetPossibleConversionsForFileType(request); Assert.IsTrue(response.PossibleConversions.Count > 0); Assert.AreEqual("docx", response.SourceFileType); foreach (var entry in response.PossibleConversions) { Assert.IsNotEmpty(entry); } }
public void PossibleConversionsForDocumentTest() { var stream = GetTestFileStream(TestFiles.OnePageDocx); var request = new PossibleConversionsForDocumentRequest(stream); var response = ConversionApi.PossibleConversionsForDocument(request); Assert.IsTrue(response.PossibleConversions.Count > 0); Assert.AreEqual("stream", response.SourceFileType); foreach (var entry in response.PossibleConversions) { Assert.IsNotEmpty(entry); } stream.Dispose(); }
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); } }
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); } }
public void Run() { FileUrl = @"https://www.le.ac.uk/oerresources/bdra/html/page_01.htm"; //FileUrl = @"https://docs.gitlab.com/ee/README.html"; string name = "page_01.htm"; string ext = (Format == "tiff") ? "tif" : ((Format == "jpeg") ? "jpg" : Format); string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted.{ext}"; string outPath = Path.Combine(CommonSettings.OutDirectory, outFile); IConversionApi convApi = new ConversionApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); Stream response = null; // call SDK methods that convert HTML document to supported out format switch (Format) { case "pdf": response = convApi.GetConvertDocumentToPdfByUrl(FileUrl, 1200, 800); break; case "xps": response = convApi.GetConvertDocumentToXps(FileUrl, 1200, 800); break; case "jpeg": case "bmp": case "png": case "tiff": response = convApi.GetConvertDocumentToImage(Format, FileUrl, 800, 1200); break; default: throw new ArgumentException($"Unsupported output format: {Format}"); } if (response != null && typeof(FileStream) == response.GetType()) { using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { response.Position = 0; response.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } }
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 ConvertToHtmlStream() { var file = TestFiles.OnePageDocx; var request = new ConvertToHtmlStreamRequest { Request = new HtmlConversionRequest { SourceFile = ToConversionFileInfo(file), Options = new HtmlSaveOptionsDto() } }; var response = ConversionApi.ConvertToHtmlStream(request); Assert.IsNotNull(response); Assert.Greater(response.Length, 0); }
public void QuickConvertToStream() { var file = TestFiles.OnePageDocx; var request = new QuickConvertToStreamRequest { Settings = new QuickConversionSettings { SourceFile = ToConversionFileInfo(file), Format = "jpg" } }; var response = ConversionApi.QuickConvertToStream(request); Assert.IsNotNull(response); Assert.Greater(response.Length, 0); }
public void ConvertToHtml() { var file = TestFiles.OnePageDocx; var request = new ConvertToHtmlRequest { Request = new HtmlConversionRequest { SourceFile = ToConversionFileInfo(file), Options = new HtmlSaveOptionsDto() } }; var response = ConversionApi.ConvertToHtml(request); Assert.IsNotNull(response); Assert.IsTrue(response.Href.EndsWith(".html")); }
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")); }
public void QuickConvert() { var file = TestFiles.OnePageDocx; var request = new QuickConvertRequest { Settings = new QuickConversionSettings { SourceFile = ToConversionFileInfo(file), Format = "jpg" } }; var response = ConversionApi.QuickConvert(request); Assert.IsNotNull(response); Assert.That(() => response.Href.EndsWith(".jpg")); }
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); } }
public void ConvertToWords() { var file = TestFiles.OnePageDocx; var request = new ConvertToWordsRequest { Request = new WordsConversionRequest() { SourceFile = ToConversionFileInfo(file), Options = new WordsSaveOptionsDto { ConvertFileType = WordsSaveOptionsDto.ConvertFileTypeEnum.Doc } } }; var response = ConversionApi.ConvertToWords(request); Assert.IsNotNull(response); Assert.IsTrue(response.Href.EndsWith(".doc")); }
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 Words request var request = new ConvertToWordsRequest { // convert to Words Request Request = new WordsConversionRequest { // source file to convert SourceFile = new ConversionFileInfo() { Folder = "conversions", Name = "sample.docx", Password = "" }, // Words save options Options = new WordsSaveOptionsDto { ConvertFileType = WordsSaveOptionsDto.ConvertFileTypeEnum.Doc } } }; // convert to Words var response = apiInstance.ConvertToWords(request); Console.WriteLine(response.Href.ToString()); } catch (Exception e) { Console.WriteLine("Exception when calling ConversionApi.ConvertToWords: " + e.Message); } }
public static Stream Run() { var configuration = new Configuration { AppSid = Common.MyAppSid, AppKey = Common.MyAppKey }; // Initiate api instance var apiInstance = new ConversionApi(configuration); try { // convert to cells request var request = new ConvertToCellsStreamRequest { // convert to cells Request Request = new CellsConversionRequest { // source file to convert SourceFile = new ConversionFileInfo() { Folder = "conversions", Name = "sample.docx", Password = "" }, // cells save options Options = new CellsSaveOptionsDto() } }; // convert to cells var response = apiInstance.ConvertToCellsStream(request); Console.WriteLine(response.Length.ToString()); return(response); } catch (Exception e) { Console.WriteLine("Exception when calling ConversionApi.ConvertToCellsStream: " + e.Message); } return(null); }
public void BeforeEachTest() { var conversionConfig = new Configuration { AuthType = AuthType.OAuth2, AppSid = _appSid, AppKey = _appKey, ApiBaseUrl = _apiBaseUrl }; ConversionApi = new ConversionApi(conversionConfig); var storageConfig = new Configuration { AuthType = AuthType.OAuth2, AppSid = _appSid, AppKey = _appKey, ApiBaseUrl = _apiBaseUrl }; StorageApi = new StorageApi(storageConfig); }
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 any format (quick convert) request var request = new QuickConvertToStreamRequest { // convert to cells request Request = new QuickConversionRequest { // source file to convert SourceFile = new ConversionFileInfo() { Folder = "conversions", Name = "sample.pdf", Password = "" }, // quick convert format Format = "doc" } }; // convert to specified format var response = apiInstance.QuickConvertToStream(request); Console.WriteLine(response.Length.ToString()); } catch (Exception e) { Console.WriteLine("Exception when calling ConversionApi.QuickConvertToStream: " + e.Message); } }
public void Run() { string name = "testpage4_embcss.html"; string path = Path.Combine(CommonSettings.DataFolder, name); if (!File.Exists(path)) { throw new FileNotFoundException("File not found in the Data folder", name); } string folder = null; string storage = null; int width = 800; int height = 1200; int leftMargin = 15; int rightMargin = 15; int topMargin = 15; int bottomMargin = 15; int xResolution = 96; int yResolution = 96; string ext = (Format == "tiff") ? "tif" : ((Format == "jpeg") ? "jpg" : Format); string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted.{ext}"; using (Stream srcStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { IConversionApi convApi = new ConversionApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); NativeRestResponse response = null; // call SDK methods that convert HTML document to supported out format switch (Format) { case "pdf": outFile += ".pdf"; response = convApi.PutConvertDocumentToPdf( srcStream, outFile, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage); break; case "xps": response = convApi.PutConvertDocumentToXps( srcStream, outFile, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage); break; case "jpeg": case "bmp": case "png": case "tiff": response = convApi.PutConvertDocumentToImage( srcStream, Format, outFile, width, height, leftMargin, rightMargin, topMargin, bottomMargin, xResolution, yResolution, storage); break; default: throw new ArgumentException($"Unsupported output format: {Format}"); } if (response != null && (string)response.Content == "storage" && response.ContentType == NativeRestResponse.RespContentType.FileName) { // get the result file name from response object string outFileName = response.ContentName; StorageApi storageApi = new StorageApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); FileExistResponse resp2 = storageApi.GetIsExist(outFileName, null, null); if (resp2.FileExist.IsExist) { // if result file exists in the storage, try to downloa it to the local file system var resp3 = storageApi.GetDownload(outFileName, null, null); if (resp3.ResponseStream != null) { string outPath = Path.Combine(CommonSettings.OutDirectory, outFileName); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { fstr.Write(resp3.ResponseStream, 0, resp3.ResponseStream.Length); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } } else { Console.WriteLine("Error: result file wasn't saved to storage."); } } } }
public void Run() { string name = "testpage4_embcss.html"; string path = Path.Combine(CommonSettings.DataFolder, name); if (!File.Exists(path)) { throw new FileNotFoundException("File not found in the Data folder", name); } string folder = null; string storage = null; int width = 800; int height = 1200; int leftMargin = 15; int rightMargin = 15; int topMargin = 15; int bottomMargin = 15; int xResolution = 96; int yResolution = 96; string ext = (Format == "tiff") ? "tif" : ((Format == "jpeg") ? "jpg" : Format); string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted.{ext}"; using (Stream srcStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { IConversionApi convApi = new ConversionApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); Stream response = null; // call SDK methods that convert HTML document to supported out format switch (Format) { case "pdf": outFile += ".pdf"; response = convApi.GetConvertDocumentToPdf( name, width, height, leftMargin, rightMargin, topMargin, bottomMargin, folder, storage); break; case "xps": response = convApi.GetConvertDocumentToXps( name, width, height, leftMargin, rightMargin, topMargin, bottomMargin, folder, storage); break; case "jpeg": case "bmp": case "png": case "tiff": response = convApi.GetConvertDocumentToImage( name, Format, width, height, leftMargin, rightMargin, topMargin, bottomMargin, xResolution, yResolution, folder, storage); break; default: throw new ArgumentException($"Unsupported output format: {Format}"); } if (response != null && response is FileStream) { string outPath = Path.Combine(CommonSettings.OutDirectory, outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { response.Position = 0; response.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } } }