Do you want to transform a local html file the same as your browser does? Do you need a nice-looking file format for better and convenient viewing? I guess there might be a need to convert a website page from your local hard disc and share with others, especially for your work. Then, what is the file type that is better for viewing and modification? Certainly, Adobe PDF is the right choice. Sometimes, you my prefer to an image format.

An easy way may comes to your mind which is to load the local HTML file to a web browser like Chrome, Safari, Firefox, etc, and then print it to PDF. Forget about it! Why not directly convert local HTML file to PDF or image format. It is more convenient and save you a lot of time.

Then, how to convert local HTML file to PDF document or an image file format? No external dependency is required for C# application development if you use XsHtml .NET HTML to PDF SDK. You neither have to integrate any third-party libraries for your C# application development nor any web browsers on your computer because XsHtml .NET HTML to PDF SDK itself acts as the comprehensive converter and do all things for you. You may choose to load an HTML file in local and convert it to PDF to image file format.


Convert Local HTML File to PDF/Image in C#

The following C# example uses XsHtml .NET HTML to PDF SDK api to convert a local HTML to PDF document. Many advanced features are not shown here, like converting local HTML file to image. Please download the free trial to test more.

// Set html source from local path
string html = @"sample.html";
string savePath = "sample.pdf";

// Create a Html converter instance 
HtmlToPdfConverter converter = new HtmlToPdfConverter();

// Set output PDF size
converter.PageSize = PageSize.A4;
           
// Convert html to PDF
converter.ConvertFromFile(html, savePath);

Notice - If you use the free trial version of .NET HTML to PDF SDK, for HTML to PDF: there is a statement in page footer("This is an XsPDF trial version"), for HTML to image: the image quality is 50% of its original.