Word document can be converted to various formats, such as convert word to EPUB, PDF, RTF, TIFF Image, XML, HTML and image. All the other six formats converting from word document have been talked before. So this article aims at introducing a simple method to finish converting word file to image format with C#, VB.NET.
Two Necessary Tools:Spire.Doc and Visual Studio.
Spire.Doc is an MS Word Component which allows developers to directly operate word document and can perform a wide range of tasks without Microsoft Office installed in the computer. Besides, it can convert word document to different commonly used formats to meet the customer need, the following procedure helps you easily and quickly convert word to image.
Freely Download Spire.Doc
Two Necessary Tools:Spire.Doc and Visual Studio.
Spire.Doc is an MS Word Component which allows developers to directly operate word document and can perform a wide range of tasks without Microsoft Office installed in the computer. Besides, it can convert word document to different commonly used formats to meet the customer need, the following procedure helps you easily and quickly convert word to image.
Freely Download Spire.Doc
Procedure:
First, create a new project in Visual Studio.
Please choose the Windows Forms Application, then, set .NET Framework 4 to be the Target framework.
Second, add a button in Form1,choose Spire.Doc dll as reference, and then, add using at the top of the method.
Third, add the following code to the method body.
C# Code:
private void button1_Click(object sender, EventArgs e)
{
//Create word document
Document document = new Document();
document.LoadFromFile(@"C:\Program Files\e-iceblue\Spire.Doc\Demos\Data\E-iceblue.doc");
//Save doc file.
Image img = document.SaveToImages(0, ImageType.Bitmap);
img.Save("sample.bmp");
//Launching the image file.
WordDocViewer("sample.bmp");
}
private void WordDocViewer(string fileName)
{
try
{
System.Diagnostics.Process.Start(fileName);
}
catch { }
}
}
}
First, create a new project in Visual Studio.
Please choose the Windows Forms Application, then, set .NET Framework 4 to be the Target framework.
Second, add a button in Form1,choose Spire.Doc dll as reference, and then, add using at the top of the method.
Third, add the following code to the method body.
C# Code:
private void button1_Click(object sender, EventArgs e)
{
//Create word document
Document document = new Document();
document.LoadFromFile(@"C:\Program Files\e-iceblue\Spire.Doc\Demos\Data\E-iceblue.doc");
//Save doc file.
Image img = document.SaveToImages(0, ImageType.Bitmap);
img.Save("sample.bmp");
//Launching the image file.
WordDocViewer("sample.bmp");
}
private void WordDocViewer(string fileName)
{
try
{
System.Diagnostics.Process.Start(fileName);
}
catch { }
}
}
}
VB.NET Code:
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
'Create word document
Dim document_Renamed As New Document()
document_Renamed.LoadFromFile (C:\Program Files\e-iceblue\Spire.Doc\Demos\Data\E-iceblue.doc ")
'Save doc file.
Dim img As Image = document_Renamed.SaveToImages(0, ImageType.Bitmap)
img.Save("sample.bmp")
'Launching the image file.
WordDocViewer("sample.bmp")
End Sub
Private Sub WordDocViewer(ByVal fileName As String)
Try
Process.Start(fileName)
Catch
End Try
End Sub
Finally, press F5, then click button1 to run the project and preview the effect.
Preview
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
'Create word document
Dim document_Renamed As New Document()
document_Renamed.LoadFromFile (C:\Program Files\e-iceblue\Spire.Doc\Demos\Data\E-iceblue.doc ")
'Save doc file.
Dim img As Image = document_Renamed.SaveToImages(0, ImageType.Bitmap)
img.Save("sample.bmp")
'Launching the image file.
WordDocViewer("sample.bmp")
End Sub
Private Sub WordDocViewer(ByVal fileName As String)
Try
Process.Start(fileName)
Catch
End Try
End Sub
Finally, press F5, then click button1 to run the project and preview the effect.
Preview
Word can be converted to many image formats, such as png, bmp, jpg and so on. So Spire.Doc is a good choice to convert your word documeny to many other formats without costing time and money to buy conversion software.
More Word Conversion
More Word Conversion