EPUB is a standard file format for publishing eBooks or other electronic documents. The content in an EPUB file is reflowable, which means that the content automatically adjusts itself to fit the screen it is being displayed on. People who want to publish their eBooks may need to convert their works stored in Word documents to EPUB files. In this article, you will learn how to programmatically achieve this task using Spire.Doc for .NET.
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Convert Word to EPUB
The detailed steps are as follows:
- Create a Document instance.
- Load a sample Word document using Document.LoadFromFile() method.
- Save the document to EPUB using Document.SaveToFile() method.
- C#
- VB.NET
using Spire.Doc; namespace WordtoEPUB { class Epub { static void Main(string[] args) { //Create a Document instance Document document = new Document(); //Load a sample Word document document.LoadFromFile("demo.docx"); //Convert the Word document to EPUB document.SaveToFile("ToEpub.epub", FileFormat.EPub); } } }
Convert Word to EPUB with a Cover Image
The detailed steps are as follows.
- Create a Document instance.
- Load a sample Word document using Document.LoadFromFile() method.
- Create a DocPicture instance, and then load an image using DocPicture.LoadImage() method.
- Save the Word document to EPUB with cover image using Document.SaveToEpub(String, DocPicture) method.
- C#
- VB.NET
using Spire.Doc; using Spire.Doc.Fields; using System.Drawing; namespace ConvertWordToEpubWithCoverImage { class Program { static void Main(string[] args) { //Create a Document instance Document doc = new Document(); //Load a sample Word document doc.LoadFromFile("demo.docx"); //Create a DocPicture instance DocPicture picture = new DocPicture(doc); //Load an image picture.LoadImage(Image.FromFile("CoverImage.png")); //Save the Word document to EPUB with cover image doc.SaveToEpub("ToEpubWithCoverImage.epub", picture); } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.