Add a Cover Image when Converting Word to EPUB in C#, VB.NET

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:

Add a Cover Image when Converting Word to EPUB in C#, VB.NET

Full Code:

[C#]
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]
Document doc  =  New Document()
doc.LoadFromFile("SampleWordFile.docx")

Dim picture As DocPicture =  New DocPicture(doc) 
picture.LoadImage(Image.FromFile("CoverImage.jpg"))
doc.SaveToEpub("output.epub", picture)