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)); } } }