We already have the documentation introducing how to convert Word to EPUB. However, you may want to add a cover image to EPUB when creating an EPUB book from a Word document. The following code snippets will demonstrate the same.
Step 1: Create a Document instance and load a sample Word file.
Document doc = new Document(); doc.LoadFromFile("SampleWordFile.docx");
Step 2: Load a picture to DocPicture object.
DocPicture picture = new DocPicture(doc); picture.LoadImage(Image.FromFile("CoverImage.jpg"));
Step 3: Add the picture to EPUB as cover image when creating EPUB from the Word document.
doc.SaveToEpub("output.epub", picture);
Output:
Full Code:
[C#]
using Spire.Doc; using Spire.Doc.Fields; using System.Drawing; namespace DOCTOEPUB { class Program { static void Main(string[] args) { Document doc = new Document(); doc.LoadFromFile("SampleWordFile.docx"); DocPicture picture = new DocPicture(doc); picture.LoadImage(Image.FromFile("CoverImage.jpg")); doc.SaveToEpub("output.epub", picture); } } }
[VB.NET]
Imports Spire.Doc Imports Spire.Doc.Fields Imports System.Drawing Namespace DOCTOEPUB Class Program Private Shared Sub Main(args As String()) Dim doc As New Document() doc.LoadFromFile("SampleWordFile.docx") Dim picture As New DocPicture(doc) picture.LoadImage(Image.FromFile("CoverImage.jpg")) doc.SaveToEpub("output.epub", picture) End Sub End Class End Namespace