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() { // setup HTML document URL var url = "http://www.sukidog.com/jpierre/strings/basics.htm"; var name = Path.GetFileName(url); // setup XPath query to select fragments var xpath = "//p"; 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.GetDocumentFragmentByXPathByUrl(url, xpath, "plain"); 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; string fname = response.FileName; string outFile = (string.IsNullOrEmpty(fname)) ? $"{Path.GetFileNameWithoutExtension(name)}_fragments.txt" : fname; 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 Test_GetDocumentImagesByUrl_1() { var url = testUrls[2]; var response = HtmlApi.GetDocumentImagesByUrl(url); checkGetMethodResponse(response, "Document", "_url_images"); }
public void Test_GetDocumentFragmentByCSSByUrl_1() { var url = testUrls[0]; var csssel = "div.container"; var response = HtmlApi.GetDocumentFragmentByXPathByUrl(url, csssel, "plain"); checkGetMethodResponseOkOrNoresult(response, "Document", "_url_css_div_class"); }
public void Test_GetDocumentFragmentByCSSByUrl_2() { var url = testUrls[3]; var csssel = "p"; var response = HtmlApi.GetDocumentFragmentByXPathByUrl(url, csssel, "plain"); checkGetMethodResponseOkOrNoresult(response, "Document", "_url_xpath_p"); }
public void Test_GetDocumentImages() { string name = "testpage5.html.zip"; string folder = StorageTestDataPath; var response = HtmlApi.GetDocumentImages(name, null, folder); checkGetMethodResponse(response, "Document", "_images"); }
public void Test_GetDocumentFragmentByXPathByUrl_1() { var url = testUrls[0]; var xpath = ".//div[@class=\"container\"]"; var response = HtmlApi.GetDocumentFragmentByXPathByUrl(url, xpath, "plain"); checkGetMethodResponseOkOrNoresult(response, "Document", "_url_xpath_div_class"); }
public void Test_GetImportMarkdownToHtml_StorageFileToResponse_1() { var name = "testpage1.md"; string folder = StorageTestDataPath; string storage = null; var response = HtmlApi.GetImportMarkdownToHtml(name, folder, storage); checkGetMethodResponse(response, "Conversion", "_md_to_html"); }
public void Test_GetDocumentFragmentByCSS_2() { string name = "testpage1.html"; string csssel = "ol>li"; string folder = StorageTestDataPath; var response = HtmlApi.GetDocumentFragmentByCSSSelector(name, csssel, "plain", null, folder); checkGetMethodResponseOkOrNoresult(response, "Document", "_css_ol_li"); }
public void Test_GetDocumentFragmentByXPath_1() { string name = "testpage5.html.zip"; string xpath = ".//p"; string folder = StorageTestDataPath; var response = HtmlApi.GetDocumentFragmentByXPath(name, xpath, "plain", null, folder); checkGetMethodResponse(response, "Document", "_xpath_p"); }
public void Test_GetDocumentFragmentByXPath_2() { string name = "testpage1.html"; string xpath = ".//ol/li"; string folder = StorageTestDataPath; var response = HtmlApi.GetDocumentFragmentByXPath(name, xpath, "json", null, folder); checkGetMethodResponseOkOrNoresult(response, "Document", "_xpath_ol_li"); }
public void Test_MergeTemplate_Get_1() { string templateName = templates[1]; string folder = StorageTestDataPath; string dataFile = dataFiles[1]; string dataPath = Path.Combine(folder, dataFile).Replace('\\', '/'); string options = null; var response = HtmlApi.GetMergeHtmlTemplate( templateName, dataPath, options, folder); checkGetMethodResponse(response, "TemplateMerge"); }
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 == "mhtml") ? "mht" : Format)); string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted.{ext}"; IConversionApi convApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); StreamResponse 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.GetConvertDocumentToXpsByUrl(FileUrl, 1200, 800); break; case "jpeg": case "bmp": case "png": case "tiff": case "gif": response = convApi.GetConvertDocumentToImageByUrl(FileUrl, Format, 800, 1200); break; case "mhtml": response = convApi.GetConvertDocumentToMHTMLByUrl(FileUrl); break; default: throw new ArgumentException($"Unsupported output format: {Format}"); } if (response != null && response.ContentStream != null && response.Status == "OK") { string respFileName = response.FileName; string outPath = Path.Combine(CommonSettings.OutDirectory, respFileName ?? outFile); Stream stream = response.ContentStream; 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() { // 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() { var url = "http://www.sukidog.com/jpierre/strings/basics.htm"; var name = "basics.htm"; 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.GetDocumentImagesByUrl(url); if (response != null && response.ContentStream != null && response.Status == "OK") { Stream stream = response.ContentStream; string fname = response.FileName; string outFile = fname ?? $"{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 SampleController(IHostingEnvironment hostingEnvironment, IHttpContextAccessor httpContextAccessor) { _hostingEnvironment = hostingEnvironment; _httpContextAccessor = httpContextAccessor; string token = _httpContextAccessor.HttpContext.Request.Headers["Authorization"]; string bearerToken = string.Empty; Regex regexp = new Regex(@"Bearer\s+(?<token>\S+)", RegexOptions.IgnoreCase); Match match = regexp.Match(token); if (match.Success) { bearerToken = match.Groups["token"].Value; } _barCodeApi = new BarCodeApi(bearerToken); _pdfApi = new PdfApi(bearerToken); _htmlApi = new HtmlApi(new Aspose.Html.Cloud.Sdk.Client.Authentication.JwtToken { Token = bearerToken, IssuedOn = DateTime.Today, ExpiresInSeconds = 86400 }, basePath); //System.IdentityModel.Tokens.Jwt WTF?? }
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() { 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)); } }
public void Run() { string name = "testpage4_embcss.html"; string path = Path.Combine(CommonSettings.LocalDataFolder, name); if (!File.Exists(path)) { throw new FileNotFoundException("File not found in the Data folder", name); } string folder = "/Html/Testout/Conversion"; string storage = null; 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_at_{DateTime.Now.ToString("yyyyMMdd_hhmmss")}.{ext}"; string outPath = Path.Combine(folder, outFile).Replace('\\', '/'); using (Stream srcStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { IConversionApi convApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); IStorageApi storageApi = new StorageApi((ApiBase)convApi); if (!storageApi.FileOrFolderExists(folder, storage)) { ((IStorageFolderApi)storageApi).CreateFolder(folder, storage); } AsposeResponse response = null; string dataType = Path.GetExtension(name).Replace(".", ""); // call SDK methods that convert HTML document to supported out format switch (Format) { case "pdf": outFile += ".pdf"; response = convApi.PostConvertDocumentToPdf( srcStream, outPath, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage); break; case "xps": response = convApi.PostConvertDocumentToXps( srcStream, outPath, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage); break; case "jpeg": case "bmp": case "png": case "tiff": case "gif": response = convApi.PostConvertDocumentToImage( srcStream, Format, outPath, width, height, leftMargin, rightMargin, topMargin, bottomMargin, resolution, storage); break; default: throw new ArgumentException($"Unsupported output format: {Format}"); } if (response != null && response.Status == "OK") { storageApi = new StorageApi((ApiBase)convApi); if (storageApi.FileOrFolderExists(outPath)) { Console.WriteLine(string.Format("\nResult file uploaded to: {0}", outPath)); } } } }
public void Init() { instance = new HtmlApi(); }
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)); } } }