public void Cosnowego() { var epub = new Document(); // set metadata epub.AddAuthor("Jerome K. Jerome"); epub.AddTitle("Three Men in a Boat (To Say Nothing of the Dog)"); epub.AddLanguage("en"); // embed fonts epub.AddFile("C:\\Fonts\\LiberationSerif-Regular.ttf", "fonts/LiberationSerif-Regular.ttf", "application/octet-stream"); epub.AddFile("C:\\Fonts\\LiberationSerif-Bold.ttf", "fonts/LiberationSerif-Bold.ttf", "application/octet-stream"); epub.AddFile("C:\\Fonts\\LiberationSerif-Italic.ttf", "LiberationSerif-Italic.ttf", "application/octet-stream"); epub.AddFile("C:\\Fonts\\LiberationSerif-BoldItalic.ttf", "fonts/LiberationSerif-BoldItalic.ttf", "application/octet-stream"); // Add stylesheet with @font-face epub.AddStylesheetFile("templates\\style.css", "style.css"); // Add image files (figures) epub.AddImageFile("figures\\fig1.png", "fig1.png"); epub.AddImageFile("figures\\drawing.svg", "drawing.svg"); // add chapters' xhtml and setup TOC entries int navCounter = 1; for (int chapterCounter = 1; chapterCounter < 10; chapterCounter++) { String chapterFile = String.Format("page{0}.xhtml", chapterCounter); String chapterName = String.Format("Chapter {0}", chapterCounter); epub.AddXhtmlFile("tempdir\\" + chapterFile, chapterFile); var chapterTOCEntry = epub.AddNavPoint(chapterName, chapterFile, navCounter++); // add nested TOC entries for (int part = 0; part < 3; part++) { String partName = String.Format("Part {0}", part); String partHref = chapterFile + String.Format("#{0}", part); chapterTOCEntry.AddNavPoint(partName, partHref, navCounter++); } } // Generate resulting epub file epub.Generate("output\\mybook.epub"); }
public override void SaveFileAs(string fileName, FileType type) { parsedEpub = new Document(); foreach (DictionaryEntry chapter in epub.Content) { var chapterContent = (eBdb.EpubReader.ContentData)chapter.Value; parsedEpub.AddXhtmlData(chapterContent.FileName, chapterContent.Content); } foreach (DictionaryEntry extendedData in epub.ExtendedData) { var dataContent = (eBdb.EpubReader.ExtendedData)extendedData.Value; if (dataContent.IsText && dataContent.FileName.EndsWith(".css")) parsedEpub.AddStylesheetData(dataContent.FileName, dataContent.Content); else if (!dataContent.IsText && dataContent.FileName.EndsWith(".jpg") || dataContent.FileName.EndsWith(".png") || dataContent.FileName.EndsWith(".bmp") || dataContent.FileName.EndsWith(".jpeg")) { parsedEpub.AddImageData(dataContent.FileName, Encoding.UTF8.GetBytes(dataContent.Content)); } } foreach (eBdb.EpubReader.NavPoint tocEntry in epub.TOC) { FillTocRecursively(tocEntry, null); } parsedEpub.AddAuthor(epub.Creator.JoinUsing(", ")); parsedEpub.AddBookIdentifier(epub.ID.JoinUsing(", ")); parsedEpub.AddDescription(epub.Description.JoinUsing(", ")); parsedEpub.AddFormat(epub.Format.JoinUsing(", ")); parsedEpub.AddLanguage(epub.Language.JoinUsing(", ")); parsedEpub.AddRelation(epub.Relation.JoinUsing(", ")); parsedEpub.AddRights(epub.Rights.JoinUsing(", ")); parsedEpub.AddSubject(epub.Subject.JoinUsing(", ")); parsedEpub.AddTitle(epub.Title.JoinUsing(", ")); parsedEpub.AddType(epub.Type.JoinUsing(", ")); parsedEpub.Generate(fileName); }