protected void Page_Load(object sender, EventArgs e) { Epub epub = new Epub(ConfigurationManager.AppSettings["EpubFilesPath"] + "LoLasartan.epub"); Response.Clear(); Response.Write(epub.GetContentAsHtml()); Response.End(); }
public void readFile(string filename) { Epub epub = new Epub(@filename); epubExtract(@filename); string title = epub.Title[0]; string author = epub.Creator[0]; string htmlText = epub.GetContentAsHtml(); string plainText = epub.GetContentAsPlainText(); lblEpubDetail.Text = title + " - "+author; using (FileStream filestream = new FileStream("temp.html", FileMode.Create)) { using (StreamWriter write = new StreamWriter(filestream, Encoding.UTF8)) { write.Write(htmlText); //webViewer.Navigate("temp.html"); string curDir = Directory.GetCurrentDirectory(); webViewer.Url = new Uri(String.Format("file:///{0}/temp.html", curDir)); } } string publisher = epub.Publisher[0]; //string id = epub.ID; lblgauthor.Text = author; lblgpub.Text = publisher; //lblid.Text = id; }
static void Main(string[] argv) { if (argv.Length == 0) return; try { var path = argv[0]; var html = Path.ChangeExtension(path, "html"); var epub = new Epub(argv[0]); if (!epub.Title.Any()) { epub.Title.Add(Path.GetFileNameWithoutExtension(path)); } File.WriteAllText(html, epub.GetContentAsHtml()); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
public void readFile(string filename) { Epub epub = new Epub(@filename); epubExtract(@filename); string title = epub.Title[0]; string author = epub.Creator[0]; string htmlText = epub.GetContentAsHtml(); string plainText = epub.GetContentAsPlainText(); lblEpubDetail.Text = title + " - "+author; using (FileStream filestream = new FileStream("temp.html", FileMode.Create)) { using (StreamWriter write = new StreamWriter(filestream, Encoding.UTF8)) { write.Write(htmlText); //webViewer.Navigate("temp.html"); string curDir = Directory.GetCurrentDirectory(); webViewer.Url = new Uri(String.Format("file:///{0}/temp.html", curDir)); } } string publisher = epub.Publisher[0]; //string id = epub.ID; lblgauthor.Text = author; lblgpub.Text = publisher; //lblid.Text = id; List<NavPoint> navPoint = epub.TOC; var topNode = new TreeNode(title); treeView1.Nodes.Add(topNode); var treeNodes = new List<TreeNode>(); var childNodes = new List<TreeNode>(); foreach (Object obj in navPoint) { if (treeNodes.Count > 0) treeNodes.Add(new TreeNode(obj.ToString())); } treeView1.Nodes[0].Nodes.AddRange(childNodes.ToArray()); }
private void MenuFileOpen_Click(object sender, RoutedEventArgs e) { try { Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.DefaultExt = "epub"; ofd.Filter = "EPub (*.epub)|*.epub|All Files (*.*)|*.*"; Nullable<bool> results = ofd.ShowDialog(); if (results == true) { //instantiate epub _epub = new Epub(ofd.FileName); //retrieve document BookDocBrowser.NavigateToString(_epub.GetContentAsHtml()); //build info page BuildInfoPage(_epub); //build table of contents foreach (var i in _epub.TOC) { foreach (var u in i.Children) { Console.WriteLine(u.Title); } } BookDocBrowser.Visibility = System.Windows.Visibility.Visible; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static Book ExtractBook(string filePath) { Book book = new Book(); book.SourcePath = filePath; Epub EpubFile = new Epub(System.Web.Hosting.HostingEnvironment.MapPath(filePath)); book.Title = EpubFile.Title[0]; book.Author = EpubFile.Creator[0]; book.Language = EpubFile.Language[0]; string bookHtml = EpubFile.GetContentAsHtml(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(bookHtml); string newPath = "~/App_Data/HtmlBooks/book_" + DateTime.Now.Ticks + ".html"; book.Path = newPath; doc.Save(System.Web.Hosting.HostingEnvironment.MapPath(newPath)); return book; }