Background of HTML to Image Conversion
Most of web pages are created from HTML files. When we read web page information through internet we can freely enjoy different content. But when we go out and without internet, HTML files become not as convenient as we want. However, most of portable multimedia devices such as iPad, iTouch, PSP, Zune, Cell Phone and many MP4 players enable users to read image content. So, we can convert HTML to image so that when we go out we can continue reading the HTML content.
How to Use C# Convert HTML to Image
There are some file format converter can convert files from HTML to Image. However, this post will show you convert HTML with C#/VB.NET. And with Spire.Doc, a professional .NET Word component, we can do this with a few simple steps.
Download Spire.Doc Here (or Spire.Office)
Friendly Reminder: Please make sure Spire.Doc and Visual Studio are correctly installed on system.
Step 1 Create Project
Create a C#/VB.NET project in visual studio add Spire.Doc.dll as reference. The default setting of Spire.Doc.dll is placed under “C:\Program Files\e-iceblue\Spire.Doc\Bin”. Select assembly Spire.Doc.dll and click OK to add it to the project.
Most of web pages are created from HTML files. When we read web page information through internet we can freely enjoy different content. But when we go out and without internet, HTML files become not as convenient as we want. However, most of portable multimedia devices such as iPad, iTouch, PSP, Zune, Cell Phone and many MP4 players enable users to read image content. So, we can convert HTML to image so that when we go out we can continue reading the HTML content.
How to Use C# Convert HTML to Image
There are some file format converter can convert files from HTML to Image. However, this post will show you convert HTML with C#/VB.NET. And with Spire.Doc, a professional .NET Word component, we can do this with a few simple steps.
Download Spire.Doc Here (or Spire.Office)
Friendly Reminder: Please make sure Spire.Doc and Visual Studio are correctly installed on system.
Step 1 Create Project
Create a C#/VB.NET project in visual studio add Spire.Doc.dll as reference. The default setting of Spire.Doc.dll is placed under “C:\Program Files\e-iceblue\Spire.Doc\Bin”. Select assembly Spire.Doc.dll and click OK to add it to the project.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Drawing.Imaging; using Spire.Doc; using Spire.Doc.Documents; namespace HTML2Image { class Program { static void Main(string[] args) { } } }
Step 2 Load HTML File
We need load the HTML which we want to convert to image. The code below can help us do it effortlessly.
We need load the HTML which we want to convert to image. The code below can help us do it effortlessly.
Document document = new Document(); document.LoadFromFile(@"D:\test.html", FileFormat.Html, XHTMLValidationType.None);
Step 3 Convert HTML to Image with C#/VB.NET
Spire.Doc presents the easiest way to convert HTML to image. The following code can help users easily save HTML files to image format. Spire.Doc enables users to convert HTML to BMP, JPEG, PNG, GIF, Tiff and other popular image format.
Spire.Doc presents the easiest way to convert HTML to image. The following code can help users easily save HTML files to image format. Spire.Doc enables users to convert HTML to BMP, JPEG, PNG, GIF, Tiff and other popular image format.
Image image = document.SaveToImages(0, ImageType.Bitmap); image.Save("Sample.png", ImageFormat.Png);
Press F5 to start the project and we can find the image in the project folder, bin ->debug.
More about Spire.Doc
Spire.Doc for .NET is an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight. Click to learn more…
Recommend Component:
Spire.Office for .NET is a compilation of every .NET component offered by e-iceblue. It includes Spire.Doc, Spire.PDFViewer, Spire.XLS, Spire.PDF and Spire.DataExport. Spire.Office contains the most up-to-date versions of the components above. Using Spire.Office for .NET developers can create a wide range of applications.
Spire.Doc for .NET is an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight. Click to learn more…
Recommend Component:
Spire.Office for .NET is a compilation of every .NET component offered by e-iceblue. It includes Spire.Doc, Spire.PDFViewer, Spire.XLS, Spire.PDF and Spire.DataExport. Spire.Office contains the most up-to-date versions of the components above. Using Spire.Office for .NET developers can create a wide range of applications.