How to Convert HTML to Image

Spire.Doc can help users use C#/VB.NET to convert HTML to Image. This solution enables users to read HTML at anytime and anywhere with their portable devices such as cell phones, MP4 players, PSP, iPad, iTouch, etc. Follow the simple steps below to use C#/VB.NET to convert HTM to image. Download Spire.Doc Here

Friendly Reminder: Please make sure Spire.Doc and Visual Studio are correctly installed on system.

Step 1: 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.

Step 2: Add a "Button" to Form1. Double click the button, add the following codes in the top of file.

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)
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Drawing
Imports System.Drawing.Imaging
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace HTML2Image
	Class Program
		Private Shared Sub Main(args As String())
		End Sub
	End Class
End Namespace

Step 3: Use the code below to load HTML file which we will convert to image.

            Document document = new Document();
            document.LoadFromFile(@"D:\test.html", FileFormat.Html, XHTMLValidationType.None);
Dim document As New Document()
document.LoadFromFile("D:\test.html", FileFormat.Html, XHTMLValidationType.None)

Step 4: Spire.Doc presents an easy solution to convert HTML to image. The following code can help users easily convert HTML to image. Spire.Doc enables users to convert HTMl to BMP, JPEG, PNG, GIF, Tiff,etc.

            Image image = document.SaveToImages(0, ImageType.Bitmap);
            image.Save("Sample.png", ImageFormat.Png);
Dim image As Image = document.SaveToImages(0, ImageType.Bitmap)
image.Save("Sample.png", ImageFormat.Png)

HTML to Image

Press F5 to start the project and we can find the image in the project folder, bin → debug.

Spire.Doc can convert HTML to most of popular file formats. It can convert HTML to PDF, Word, XML, RTF, Text, ePub, etc. Click to learn more