Download and Process file - C#
PDF To HTML SDK sample in C# demonstrating ‘Download and Process file’
Program.cs
using System;
using System.Diagnostics;
using System.IO;
using Bytescout.PDF2HTML;
namespace ExtractHTMLFromPage
{
class Program
{
static void Main(string[] args)
{
// Create Bytescout.PDF2HTML.HTMLExtractor instance
HTMLExtractor extractor = new HTMLExtractor();
extractor.RegistrationName = "demo";
extractor.RegistrationKey = "demo";
// Set HTML with CSS extraction mode
extractor.ExtractionMode = HTMLExtractionMode.HTMLWithCSS;
// Input file Url
var inputUrl = @"https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-to-text/sample.pdf";
// Get Input Stream
var inpStream = GetStreamFromUrl(inputUrl);
// Load sample PDF document
extractor.LoadDocumentFromStream(inpStream);
// Convert 1-st page to HTML and save it to file
extractor.SaveHtmlPageToFile(0, "output.html");
// Cleanup
extractor.Dispose();
// Open result document in default associated application (for demo purpose)
ProcessStartInfo processStartInfo = new ProcessStartInfo("output.html");
processStartInfo.UseShellExecute = true;
Process.Start(processStartInfo);
}
/// <summary>
/// Get stream from Url
/// </summary>
private static Stream GetStreamFromUrl(string url)
{
byte[] oData = null;
using (var wc = new System.Net.WebClient())
oData = wc.DownloadData(url);
return new MemoryStream(oData);
}
}
}