예제 #1
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            DbManage manage  = new DbManage();
            var      catalog = manage.GetCataLogByName(txtNovel.Text);

            var epub = new EPubDocument();

            epub.AddTitle(txtNovel.Text);

            epub.AddLanguage("zh-cn");

            String css = CrawelNovel.Properties.Resources.style;

            css += "\nbody { font-family: LiberationSerif; }\n";
            css += "@font-face { font-family : LiberationSerif; font-weight : normal; font-style: normal; src : url(LiberationSerif-Regular.ttf); }\n";
            css += "@font-face { font-family : LiberationSerif; font-weight : normal; font-style: italic; src : url(LiberationSerif-Italic.ttf); }\n";
            css += "@font-face { font-family : LiberationSerif; font-weight : bold; font-style: normal; src : url(LiberationSerif-Bold.ttf); }\n";
            css += "@font-face { font-family : LiberationSerif; font-weight : bold; font-style: italic; src : url(LiberationSerif-BoldItalic.ttf); }\n";

            epub.AddData("LiberationSerif-Regular.ttf", CrawelNovel.Properties.Resources.LiberationSerif_Regular, "application/octet-stream");
            epub.AddData("LiberationSerif-Bold.ttf", CrawelNovel.Properties.Resources.LiberationSerif_Bold, "application/octet-stream");
            epub.AddData("LiberationSerif-Italic.ttf", CrawelNovel.Properties.Resources.LiberationSerif_Italic, "application/octet-stream");
            epub.AddData("LiberationSerif-BoldItalic.ttf", CrawelNovel.Properties.Resources.LiberationSerif_BoldItalic, "application/octet-stream");

            epub.AddStylesheetData("style.css", css);

            String coverId = epub.AddImageData("cover.png", catalog.Img);

            epub.AddMetaItem("cover", coverId);


            String page_template = Encoding.UTF8.GetString(CrawelNovel.Properties.Resources.page);

            int navCounter  = 1;
            int pageCounter = 1;

            var chaps = manage.GetChapterList(catalog.Id);

            foreach (var chap in chaps)
            {
                String page     = page_template.Replace("%%CONTENT%%", chap.ChapterName + "<br />" + chap.ChapterContent.Replace("\r\n", "<br />")).Replace("<br /><br />", "");
                String pageName = String.Format("page{0}.xhtml", pageCounter);
                epub.AddXhtmlData(pageName, page);
                epub.AddNavPoint(chap.ChapterName, pageName, navCounter++);
                pageCounter++;
            }
            SaveFileDialog saveFileDialog = new SaveFileDialog();


            saveFileDialog.Filter           = "epub files (*.epub)|*.epub|All files (*.*)|*.*";
            saveFileDialog.FilterIndex      = 1;
            saveFileDialog.RestoreDirectory = true;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                epub.Generate(saveFileDialog.FileName);
            }
        }
예제 #2
0
        private bool CheckIfExitNovelName(string Name)
        {
            DbManage manage = new DbManage();

            return(manage.GetCataLogByName(Name) != null);
        }