static void Main(string[] args) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\test\tests.txt")) { file.WriteLine(""); file.WriteLine("Scenario Outline: Get ePub title "); file.WriteLine(" Given an ePub file named \"<filename>\" "); file.WriteLine(" When I open the file using ePubReader "); file.WriteLine(" Then the title is \"<title>\" "); file.WriteLine(" "); file.WriteLine("Examples: "); file.WriteLine(" | filename | title |"); foreach (var epubFile in Directory.EnumerateFiles(@"C:\test\", "*.epub")) { try { Epub epub = new Epub(epubFile); file.WriteLine(string.Format("|{0}|{1}|", epubFile, epub.Title[0])); } catch { } } file.WriteLine(""); file.WriteLine("Scenario Outline: Get ePub content"); file.WriteLine(" Given an ePub file named \"<filename>\""); file.WriteLine(" When I open the file using ePubReader"); file.WriteLine(" Then the start of chapter 2 is \"<chapter2>\""); file.WriteLine(""); file.WriteLine("Examples:"); file.WriteLine(" | filename | chapter2 |"); foreach (var epubFile in Directory.EnumerateFiles(@"C:\test\", "*.epub")) { try { Epub epub = new Epub(epubFile); file.WriteLine(string.Format("|{0}|{1}|", epubFile, epub.TOC[1].ContentData.Content .Replace("\n", "") .Replace("\r", "") .Substring(0, 255) .Trim() )); } catch { } } file.WriteLine(""); file.WriteLine("Scenario Outline: Get ePub text content"); file.WriteLine(" Given an ePub file named \"<filename>\""); file.WriteLine(" When I open the file using ePubReader"); file.WriteLine(" Then the start of chapter 2 is \"<chapter2>\""); file.WriteLine(""); file.WriteLine("Examples:"); file.WriteLine(" | filename | chapter2 |"); foreach (var epubFile in Directory.EnumerateFiles(@"C:\test\", "*.epub")) { try { Epub epub = new Epub(epubFile); file.WriteLine(string.Format("|{0}|{1}|", epubFile, epub.TOC[1].ContentData.GetContentAsPlainText() .Replace("\n", "") .Replace("\r", "") .Substring(0, 255) .Trim() )); } catch { } } } }
public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; HttpResponse response = context.Response; //Simple protection from external domain requests. if (request.UrlReferrer != null && !string.Equals(request.Url.Host, request.UrlReferrer.Host, StringComparison.InvariantCultureIgnoreCase)) { response.Write("<html>\r\n"); response.Write("<head><title>Access Denied</title></head>\r\n"); response.Write("<body>\r\n"); response.Write("<h1>Access Denied</h1>\r\n"); response.Write("</body>\r\n"); response.Write("</html>"); return; } if (request.QueryString["epub"] == null || request.QueryString["epub"].Trim() == string.Empty) { throw new FileNotFoundException(); } Epub epub = new Epub(ConfigurationManager.AppSettings["EpubFilesPath"] + request.QueryString["epub"]); ExtendedData extendedData = epub.ExtendedData[request.QueryString["filePath"]] as ExtendedData; if (extendedData == null) { return; } response.ContentType = extendedData.MimeType; response.BinaryWrite(extendedData.GetContentAsBinary()); }
public void WhenIOpenTheFileUsingEPubReader() { string fileName = ScenarioContext.Current .Get<string>("FileName"); Epub epub = new Epub(fileName); ScenarioContext.Current.Add("Epub", epub); }
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; }
public string[] GetWordsFromEpub(int docId) { try { var epub = new Epub(collection[docId].FullName); string plainText = epub.GetContentAsPlainText(); string[] wordsInText = Parse(plainText); return wordsInText; } catch (Exception e) { Console.WriteLine(e.Message); } return new string[0]; }
private void cargarLibro() { // cargo el libro en el navegador para leerlo. Saco de la bdd el texto que indica qué libro es (la imagenPortada) del libro que se selecciono, porque lo // tengo guardado en la carpeta de recursos con el mismo nombre. Una vez optenido, cargo el epub, y lo muestro en el navegador. string select; SqlConnection conexion = BddConection.newConnection(); SqlCommand orden; SqlDataReader datos; select = string.Format("select imagenPortada from libro where titulo = '{0}'", libro); orden = new SqlCommand(select, conexion); datos = orden.ExecuteReader(); if (datos.Read()) epub = new Epub(string.Format("{0}//{1}.epub", Constantes.RUTA_RECURSOS, datos.GetString(0))); datos.Close(); BddConection.closeConnection(conexion); navegador.DocumentText = epub.GetContentAsHtml(); }
public EpubReader(string filePath, string outputDir) { try { _mEpub = new Epub(filePath); } catch (Exception e) { _mEpub = null; Console.WriteLine("Error in EpubReader: _mEpub couldn't be initialized."); Console.WriteLine(e.Message); } _mFilePath = filePath; string epubExtractDir = Directory.Exists(Path.Combine(outputDir, "Epub Extracted Files")) ? Path.Combine(outputDir, "Epub Extracted Files") : Utility.CreateDirectory(Path.Combine(outputDir, "Epub Extracted Files")); _mEpubDir = Utility.CreateDirectory(Utility.NewFolderPath(epubExtractDir, Path.GetFileNameWithoutExtension(filePath))); ZipFile.Read(filePath).ExtractAll(_mEpubDir); _mContentDir = Path.GetDirectoryName(GetOpfFilePath()); }
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; }
public eBook(String filePath) { eStory = new Epub(filePath); }
public ChapteredEPubTextSource(string fileName) { //CurrentEpub = new Epub(@"..\..\..\TestData\pragpub-2013-07.epub"); CurrentEpub = new Epub(fileName); }
public FlatEPubTextSource() { //Epub epub = new Epub(@"C:\Users\eric.potter\Dropbox\ReadingMaterial\pragpub-2013-01.epub"); epub = new Epub(@"H:\Dropbox\ReadingMaterial\pragpub-2013-01.epub"); }
// In order to Open the File with appropriate extension public void Open(string file_name, string file_ext) { switch (file_ext) { case ".txt": { if (txt_sr != null) txt_sr.Close(); txt_sr = new StreamReader(file_name, Encoding.GetEncoding(1251)); opened = OpenType.Txt; ReadTxt(); } break; case ".fb2": { // some code for fb2 //opened = OpenType.Fb2; opened = OpenType.None; } break; case ".epub": { Epub epub = new Epub(file_name); epub_sr = new StringReader(epub.GetContentAsPlainText()); opened = OpenType.Epub; ReadEpub(); } break; default: { opened = OpenType.None; } break; } }
private void BuildInfoPage(Epub pub) { try { var reader = new StreamReader("BookInfoTemplate.txt"); var template = reader.ReadToEnd(); var title = string.Empty; var authors = string.Empty; var publisher = string.Empty; var about = string.Empty; //get title if ((pub.Title.Count > 0) && (!string.IsNullOrEmpty(pub.Title[0]))) { title = pub.Title[0]; } else { title = "<i>No title provided</i>"; } //get authors if (pub.Creator.Count > 0) { foreach (var a in pub.Creator) { authors = a + ", "; } //remove last ", " if (!string.IsNullOrEmpty(authors)) { authors = authors.Substring(0, authors.Length - 3); } } else { authors = "<i>No authors listed</i>"; } //get publisher if ((pub.Publisher.Count > 0) && (!string.IsNullOrEmpty(pub.Publisher[0]))) { publisher = pub.Publisher[0]; } else { publisher = "<i>No publisher listed</i>"; } //get about if ((pub.Description.Count > 0) && (!string.IsNullOrEmpty(pub.Description[0].ToString()))) { about = pub.Description[0]; if (!about.Contains("<p>")) { about = "<p>About: <br />" + about + "</p>"; } else { about = about.Insert(about.IndexOf("<p>") + 3, "About: <br />"); } about = about.Replace("\\u", " "); } else { about = "<i>No description provided</i>"; } //update template template = template.Replace("{title}", title); template = template.Replace("{authors}", authors); template = template.Replace("{publisher}", publisher); template = template.Replace("{about}", about); InfoDocBrowser.NavigateToString(template); } catch (Exception ex) { MessageBox.Show(ex.Message); } }