public void Run() { var name = "testpage3_embcss.html"; var xPath = "//ol/li"; // Upload source file to cloud storage (default is AmazonS3) var srcPath = Path.Combine(CommonSettings.DataFolder, name); if (File.Exists(srcPath)) { SdkBaseRunner.uploadToStorage(name, CommonSettings.DataFolder); } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } IDocumentApi docApi = new DocumentApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); // call the SDK method that returns a query result in the response stream. Stream stream = docApi.GetDocumentFragmentByXPath(name, xPath, "json", null, null); if (stream != null && typeof(FileStream) == stream.GetType()) { string outFile = $"{Path.GetFileNameWithoutExtension(name)}_fragments.json"; string outPath = Path.Combine(CommonSettings.OutDirectory, outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { stream.Position = 0; stream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } }
public void Run() { // setup HTML document name var name = "testpage1.md"; // setup local document path var srcPath = Path.Combine(CommonSettings.LocalDataFolder, name); // setup storage folder where the source document should be present string folder = CommonSettings.StorageDataFolder; // setup storage name (null for default storage) string storage = null; // setup storage folder path where the result file will be uploaded to string outFolder = "/Html/Testout/Conversion"; string outFile = $"{name}_get_to_html_{DateTime.Now.ToString("yyyyMMdd_hhmmss")}.html"; string storagePath = (folder == null) ? name : Path.Combine(folder, name).Replace('\\', '/'); string outPath = Path.Combine(outFolder, outFile).Replace('\\', '/'); if (File.Exists(srcPath)) { SdkBaseRunner.UploadToStorage(storagePath, srcPath); } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } IImportApi impApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath, CommonSettings.AuthPath); AsposeResponse response = impApi.PutImportMarkdownToHtml(name, outPath, folder, storage); if (response != null && response.Status == "OK") { Console.WriteLine(string.Format("\nResult file uploaded to: {0}", outPath)); } }
public void Run() { string name = "testpage5.html.zip"; // storage file name string folder = "/Html/TestData"; // storage folder name string filePath = Path.Combine(CommonSettings.LocalDataFolder, name); string storageFilePath = Path.Combine(folder, name).Replace('\\', '/'); if (File.Exists(filePath)) { SdkBaseRunner.UploadToStorage(storageFilePath, filePath); } else { throw new Exception(string.Format("Error: file {0} not found.", filePath)); } IDocumentApi docApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); // call SDK method that gets a zip archive with all HTML document images var response = docApi.GetDocumentImages(name, null, folder); if (response != null && response.ContentStream != null && response.Status == "OK") { Stream stream = response.ContentStream; string outFile = $"{Path.GetFileNameWithoutExtension(response.FileName)}_images.zip"; string outPath = Path.Combine(CommonSettings.OutDirectory, outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { stream.Position = 0; stream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } }
public void Run() { string name = "testpage5.html.zip"; // storage file name string folder = "HtmlTemp"; // storage folder name string filePath = Path.Combine(CommonSettings.DataFolder, name); if (File.Exists(filePath)) { SdkBaseRunner.uploadToStorage(name, CommonSettings.DataFolder); } else throw new Exception(string.Format("Error: file {0} not found.", filePath)); IDocumentApi docApi = new DocumentApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); // call SDK method that gets a zip archive with all HTML document images Stream stream = docApi.GetDocumentImages(name, null, folder); if (stream != null && typeof(FileStream) == stream.GetType()) { string outFile = $"{Path.GetFileNameWithoutExtension(name)}_images.zip"; string outPath = Path.Combine(CommonSettings.OutDirectory, outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { stream.Position = 0; stream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } }
public void Run() { // setup local path the files are located by var srcDir = CommonSettings.LocalDataFolder; // setup HTML template file name var templateName = "test_template_3_2.html"; // setup data to merge file name var dataFileName = "templ_merge_data_2.xml"; // setup merge options var options = "{'cs_names':false, 'rm_tabhdr':false}"; // setup the storage folder where the files will be uploaded before var folder = CommonSettings.StorageDataFolder; var outFolder = "/Html/Testout"; var mergedName = $"{templateName}_merged_at_{DateTime.Now.ToString("yyyyMMdd-hhmmss")}{Path.GetExtension(templateName)}"; var templatePath = ""; var dataPath = Path.Combine(srcDir, dataFileName); string filePath = Path.Combine(srcDir, templateName); string storagePath = Path.Combine(folder, templateName).Replace('\\', '/'); string outPath = Path.Combine(outFolder, mergedName).Replace('\\', '/'); // template should be uploaded to storage before if (File.Exists(filePath)) { SdkBaseRunner.UploadToStorage(storagePath, filePath); templatePath = storagePath; } else { throw new Exception(string.Format("Error: file {0} not found.", filePath)); } using (Stream dataStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read)) { Stream inStream = new MemoryStream(); dataStream.CopyTo(inStream); inStream.Flush(); inStream.Position = 0; ITemplateMergeApi api = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); var response = api.PostMergeHtmlTemplate(templateName, inStream, outPath, options, folder); if (response != null && response.Status == "OK") { Console.WriteLine($"TemplateMerge: Result file uploaded to {outPath}"); } } }
public void Run() { // setup HTML document name var name = "testpage3_embcss.html"; // setup storage folder path where is the source document var folder = CommonSettings.StorageDataFolder; // setup CSS selector var selector = "ol > li"; // Upload source file to cloud storage var srcPath = Path.Combine(CommonSettings.LocalDataFolder, name); var storagePath = Path.Combine(folder, name).Replace('\\', '/'); if (File.Exists(srcPath)) { SdkBaseRunner.UploadToStorage(storagePath, srcPath); } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } IDocumentApi docApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); // call the SDK method that returns a query result in the response stream. var response = docApi.GetDocumentFragmentByCSSSelector(name, selector, "plain", null, folder); if (response != null && response.ContentStream != null) { if (response.Status == "NoContent") { Console.WriteLine("Operation succeeded but result is empty"); } else if (response.Status == "OK") { Stream stream = response.ContentStream; var outFile = response.FileName; string outPath = Path.Combine(CommonSettings.OutDirectory, outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { stream.Position = 0; stream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } } }
public void Run() { string name = "testpage1.html"; string folder = null; string storage = null; string srcPath = Path.Combine(CommonSettings.DataFolder, name); if (File.Exists(srcPath)) { var storagePath = !string.IsNullOrEmpty(folder) ? string.Format("{0}/{1}", folder, name) : name; bool uploaded = SdkBaseRunner.uploadToStorage(storagePath, CommonSettings.DataFolder); if (uploaded) { TranslationApi transApi = new TranslationApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); Stream stream = transApi.GetTranslateDocument(name, SrcLang, ResLang, folder, storage); if (stream != null && stream.GetType() == typeof(FileStream)) { string outName = ((FileStream)stream).Name; string outPath = Path.Combine(CommonSettings.OutDirectory, Path.GetFileName(outName)); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { stream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("File '{0}' downloaded to: {1}", Path.GetFileName(outName), outPath)); } } stream.Close(); stream.Dispose(); } } else { throw new FileNotFoundException("File not found in the Data folder", name); } }
public void Run() { // setup HTML document name var name = "testpage1.md"; // setup local document path var srcPath = Path.Combine(CommonSettings.LocalDataFolder, name); // setup storage folder where the source document should be present string folder = CommonSettings.StorageDataFolder; // setup storage name (null for default storage) string storage = null; string storagePath = (folder == null) ? name : Path.Combine(folder, name).Replace('\\', '/'); string outFile = $"{name}_get_to_html_{DateTime.Now.ToString("yyyyMMdd_hhmmss")}.html"; if (File.Exists(srcPath)) { SdkBaseRunner.UploadToStorage(storagePath, srcPath); } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } IImportApi impApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath, CommonSettings.AuthPath); StreamResponse response = impApi.GetImportMarkdownToHtml(name, folder, storage); if (response != null && response.ContentStream != null && response.Status == "OK") { var respFileName = response.FileName; Stream outStream = response.ContentStream; string outPath = Path.Combine(CommonSettings.OutDirectory, respFileName ?? outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { outStream.Position = 0; outStream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } }
public void Run() { // setup local path the files are located by var srcDir = CommonSettings.LocalDataFolder; // setup HTML template file name var templateName = "test_template_3_2.html"; // setup data to merge file name var dataFileName = "templ_merge_data_2.xml"; // setup merge options var options = "{'cs_names':false, 'rm_tabhdr':false}"; // setup the storage folder where the files will be uploaded before var folder = CommonSettings.StorageDataFolder; var templatePath = ""; var dataPath = ""; string filePath = Path.Combine(srcDir, templateName); string storagePath = Path.Combine(folder, templateName).Replace('\\', '/'); // template should be uploaded to storage before if (File.Exists(filePath)) { SdkBaseRunner.UploadToStorage(storagePath, filePath); templatePath = storagePath; } else { throw new Exception(string.Format("Error: file {0} not found.", filePath)); } filePath = Path.Combine(srcDir, dataFileName); storagePath = Path.Combine(folder, dataFileName).Replace('\\', '/'); // data file should be uploaded to storage before if (File.Exists(filePath)) { SdkBaseRunner.UploadToStorage(storagePath, filePath); dataPath = storagePath; } else { throw new Exception(string.Format("Error: file {0} not found.", filePath)); } ITemplateMergeApi mergeApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); // call SDK method that gets an HTML template and a data file from the storage // and returns generated HTML document as stream. var response = mergeApi.GetMergeHtmlTemplate(templateName, dataPath, options, folder); Stream stream = response.ContentStream; if (stream != null) { string outFile = $"{Path.GetFileNameWithoutExtension(templateName)}_merged.{Path.GetExtension(templateName)}"; string outPath = Path.Combine(CommonSettings.OutDirectory, outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { stream.Position = 0; stream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } }
public void Run() { // setup HTML document name //var name = "testpage4_embcss.html"; //var name = "testpage_9999.html"; var name = FileName; // setup local document path var srcPath = Path.Combine(CommonSettings.LocalDataFolder, name); // setup storage folder where the source document should be present string folder = CommonSettings.StorageDataFolder; // setup storage name (null for default storage) string storage = null; string storagePath = (folder == null) ? name : Path.Combine(folder, name).Replace('\\', '/'); // setup resulting file parameters int width = 800; int height = 1200; int leftMargin = 15; int rightMargin = 15; int topMargin = 15; int bottomMargin = 15; int resolution = 96; string ext = (Format == "tiff") ? "tif" : ((Format == "jpeg") ? "jpg" : Format); string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted.{ext}"; if (CheckIfStorageFileExists) { if (File.Exists(srcPath)) { SdkBaseRunner.UploadToStorage(storagePath, srcPath); } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } } IConversionApi convApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath, CommonSettings.AuthPath); StreamResponse response = null; // call SDK methods that convert HTML document to supported out format switch (Format) { case "pdf": outFile += ".pdf"; // call the SDK method that returns a query result in the response stream 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 "doc": response = convApi.GetConvertDocumentToDoc( name, width, height, leftMargin, rightMargin, topMargin, bottomMargin, folder, storage); break; case "jpeg": case "bmp": case "png": case "tiff": case "gif": response = convApi.GetConvertDocumentToImage( name, Format, width, height, leftMargin, rightMargin, topMargin, bottomMargin, resolution, folder, storage); break; case "md": response = convApi.GetConvertDocumentToMarkdown(name, false); break; default: throw new ArgumentException($"Unsupported output format: {Format}"); } if (response != null && response.ContentStream != null && response.Status == "OK") { var respFileName = response.FileName; Stream outStream = response.ContentStream; string outPath = Path.Combine(CommonSettings.OutDirectory, respFileName ?? outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { outStream.Position = 0; outStream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } }
public void Run() { var name = FileName; var srcPath = Path.Combine(CommonSettings.LocalDataFolder, name); string folder = CommonSettings.StorageDataFolder; string storage = null; // setup storage folder path where the result file will be uploaded to string outFolder = "/Html/Testout/Conversion"; int width = 800; int height = 1200; int leftMargin = 15; int rightMargin = 15; int topMargin = 15; int bottomMargin = 15; int resolution = 96; string storagePath = (folder == null) ? name : Path.Combine(folder, name).Replace('\\', '/'); string ext = (Format == "tiff") ? "tif" : ((Format == "jpeg") ? "jpg" : Format); string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted_at_{DateTime.Now.ToString("yyyyMMdd_hhmmss")}.{ext}"; string outPath = Path.Combine(outFolder, outFile).Replace('\\', '/'); if (CheckIfStorageFileExists) { if (File.Exists(srcPath)) { SdkBaseRunner.UploadToStorage(storagePath, srcPath); } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } } IConversionApi convApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); AsposeResponse response = null; // call SDK methods that convert HTML document to supported out format switch (Format) { case "pdf": outFile += ".pdf"; response = convApi.PutConvertDocumentToPdf( name, outPath, width, height, leftMargin, rightMargin, topMargin, bottomMargin, folder, storage); break; case "xps": response = convApi.PutConvertDocumentToXps( name, outPath, width, height, leftMargin, rightMargin, topMargin, bottomMargin, folder, storage); break; case "jpeg": case "bmp": case "png": case "tiff": case "gif": response = convApi.PutConvertDocumentToImage( name, Format, outPath, width, height, leftMargin, rightMargin, topMargin, bottomMargin, resolution, folder, storage); break; case "md": response = convApi.PutConvertDocumentToMarkdown(name, outPath, false); break; default: throw new ArgumentException($"Unsupported output format: {Format}"); } if (response != null && response.Status == "OK") { Console.WriteLine(string.Format("\nResult file uploaded to: {0}", outPath)); } }