Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        // Example Valid JSON configuration for the class
        // {
        // "Parser": "RegExp",
        // "BaseAddress": "http://beyondtheimpossible.org/comic/1-before-the-beginning-2/",
        // "NextButtonSelector": "(?:href=\"(\\S+)\")? class=\"comic-nav-base comic-nav-next\">",
        // "ChapterTitleSelector": "class=\"post-title\">([^<]*)<",
        // "ChapterContentSelector": "<div class=\"entry\">((?:.|\n)*)<div class=\"post-extras\">",
        // "Author": "Ffurla",
        // "Date": "2016-03-18T13:24:36.2855417+01:00",
        // "Title": "Beyond the Impossible",
        // "Description": null
        // },

        protected override void ScrapeWebPage(WebComicEntry entry, EPubDocument ebook, string nextPageUrl = null)
        {
            if (entry.Content != WebComicEntry.ContentType.Text)
            {
                throw new NotSupportedException(
                          $"This parser does not support the following content type {Enum.GetName(typeof(WebComicEntry.ContentType), entry.Content)}");
            }

            do
            {
                string title      = string.Empty;
                string content    = string.Empty;
                var    currentUrl = nextPageUrl ?? entry.BaseAddress;
                try
                {
                    using (var wc = new WebClient()
                    {
                        Encoding = Encoding.UTF8
                    })
                    {
                        var s = WebUtility.HtmlDecode(wc.DownloadString(currentUrl));

                        var m = Regex.Match(s, entry.NextButtonSelector);
                        if (m.Groups[1].Success)
                        {
                            nextPageUrl = m.Groups[1].Value;
                        }
                        else
                        {
                            nextPageUrl = string.Empty;
                        }

                        m = Regex.Match(s, entry.ChapterTitleSelector);
                        if (m.Groups[1].Success)
                        {
                            title   = m.Groups[1].Value;
                            content = $"<h1>{title}</h1>";
                        }

                        m = Regex.Match(s, entry.ChapterContentSelector);
                        if (m.Groups[1].Success)
                        {
                            var v = m.Groups[1].Value;
                            content += v;
                        }

                        this.AddPage(ebook, content, title, currentUrl);
                    }
                }
                catch (WebException ex)
                {
                    if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
                    {
                        return;
                    }
                }
            }while (!nextPageUrl.IsEmpty());
        }
        public static string CreateBiography(string id)
        {
            var projectId = "{B80EB639-5E3E-445C-BE73-B5CA3F4119BA}";
            var projectItem = Database.GetItem(projectId);
            try
            {
                if (projectItem != null)
                {
                    var epubDoc = new Epub.Document();

                    var contentItem = ((ReferenceField)projectItem.Fields["Item Reference"]).InnerField.Item;

                    //Metadata
                    epubDoc.AddAuthor("Weil - Julia Gavrilova");
                    epubDoc.AddTitle("Testing ePub book Generation");
                    epubDoc.AddLanguage("en");

                    //embeded fonts
                    epubDoc.AddFile("D:\\siteroot\\local7cms.weil.com\\Website\\Content\\fontawesome-webfont.ttf", "fonts/fontawesome-webfont.ttf", "application/octet-stream");

                    //add stylesheet with @font-face
                    epubDoc.AddStylesheetFile("D:\\siteroot\\local7cms.weil.com\\Website\\Content\\styles\\screen.css", "screen.css");

                    // Add image files (figures)
                    epubDoc.AddImageFile("D:\\siteroot\\local7cms.weil.com\\Website\\Content\\images\\office-map.png", "office-map.png");
                    epubDoc.AddImageFile("D:\\siteroot\\local7cms.weil.com\\Website\\Content\\images\\icon-select.png", "icon-select.png");

                    // 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);
                        epubDoc.AddXhtmlData("tempdir/" + chapterFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"><head><title> Strict DTD XHTML Example </title></head><html><body>this is content for the chapter</body></html>");
                        var chapterTOCEntry =
                            epubDoc.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
                    //epubDoc.Generate(fileOutputLocation);    
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex, typeof(EpubManager));
            }
            return projectId;
        }
Exemplo n.º 4
0
        public string Start()
        {
            try
            {
                logger.Info("开始工作...");
                var date = DownLoadHtml.Start();
                var dir  = WorkContext.Config.TempDir + date + "/";

                var epub = new Epub.Document();
                // set metadata
                epub.AddAuthor("xiangwan");

                epub.AddTitle("zhihu-daily-" + date);
                epub.AddLanguage("zh");

                // Add image files
                var images = Directory.GetFiles(dir + "image");
                foreach (var image in images)
                {
                    epub.AddImageFile(image, "image\\" + Path.GetFileName(image));
                }

                // add chapters' xhtml and setup TOC entries
                int navCounter = 1;
                var htmls      = Directory.GetFiles(dir, "*.html");
                foreach (var html in htmls)
                {
                    var name = Path.GetFileName(html);
                    epub.AddXhtmlFile(html, name);
                    string text  = File.ReadAllText(html);
                    string title = Regex.Match(text, "<title>\\s*.*\\s*</title>").Value;
                    title = Regex.Match(title, ">\\s*.*\\s*<").Value.Trim('>', '<', ' ', '\t', '\n');

                    epub.AddNavPoint(title, name, navCounter++);
                }

                var saveDir = WorkContext.Config.SaveDir;
                if (!Directory.Exists(saveDir))
                {
                    Directory.CreateDirectory(saveDir);
                }
                // Generate resulting epub file
                epub.Generate(saveDir + "zhihu-daily-" + date + ".epub");
            }
            catch (Exception e)
            {
                logger.Error(e);
            }
            return("ok");
        }
Exemplo n.º 5
0
        private void testButton_Click(object sender, EventArgs e)
        {
            var epub = new EPubDocument();

            epub.AddAuthor(textboxAuthor.Text);
            epub.AddTitle(textboxTitle.Text);
            epub.AddLanguage("en");

            String css = EPUBTest.Properties.Resources.style;

            if (checkBoxFonts.Checked)
            {
                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", EPUBTest.Properties.Resources.LiberationSerif_Regular, "application/octet-stream");
                epub.AddData("LiberationSerif-Bold.ttf", EPUBTest.Properties.Resources.LiberationSerif_Bold, "application/octet-stream");
                epub.AddData("LiberationSerif-Italic.ttf", EPUBTest.Properties.Resources.LiberationSerif_Italic, "application/octet-stream");
                epub.AddData("LiberationSerif-BoldItalic.ttf", EPUBTest.Properties.Resources.LiberationSerif_BoldItalic, "application/octet-stream");
            }

            epub.AddStylesheetData("style.css", css);
            Bitmap coverImg = EPUBTest.Properties.Resources.pngSample;
            MemoryStream coverData = new MemoryStream();
            coverImg.Save(coverData, ImageFormat.Png);
            String coverId = epub.AddImageData("cover.png", coverData.GetBuffer());
            epub.AddMetaItem("cover", coverId);

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

            int navCounter = 1;
            int pageCounter = 1;

            string content = "<h1>Header 1</h1>";
            content += "<h2>Header 2</h2>";
            content += "<h3>Header 3</h3>";
            content += "<h4>Regular paragraph</h4>";
            content += "<p>" + EPUBTest.Properties.Resources.lorem + "<a href=\"notes.xhtml#n1\">[1]</a></p>";

            content += "<h4>Bold paragraph</h4>";
            content += "<p class=\"bold\">" + EPUBTest.Properties.Resources.lorem + "</p>";

            content += "<h4>Italic paragraph</h4>";
            content += "<p class=\"italic\">" + EPUBTest.Properties.Resources.lorem + "</p>";

            content += "<h4>Bold+Italic paragraph</h4>";
            content += "<p class=\"bolditalic\">" + EPUBTest.Properties.Resources.lorem + "</p>";

            String page = page_template.Replace("%%CONTENT%%", content);

            String pageName = String.Format("page{0}.xhtml", pageCounter);
            epub.AddXhtmlData(pageName, page);
            epub.AddNavPoint("Lorem ipsum", pageName, navCounter++);
            pageCounter++;
            pageName = String.Format("page{0}.xhtml", pageCounter);
            if (checkBoxGif.Checked || checkBoxPng.Checked || checkBoxJpeg.Checked || checkBoxSvg.Checked)
            {

                var navImageTests = epub.AddNavPoint("Image tests", pageName, navCounter);

                if (checkBoxPng.Checked)
                {
                    Bitmap img = EPUBTest.Properties.Resources.pngSample;
                    MemoryStream memImg = new MemoryStream();
                    img.Save(memImg, ImageFormat.Png);
                    epub.AddImageData("sample.png", memImg.GetBuffer());
                    page = page_template.Replace("%%CONTENT%%", "<img src=\"sample.png\" alt=\"\"/>");
                    epub.AddXhtmlData(pageName, page);
                    navImageTests.AddNavPoint("PNG Test", pageName, navCounter++);
                    pageCounter++;
                    pageName = String.Format("page{0}.xhtml", pageCounter);
                }

                if (checkBoxJpeg.Checked)
                {
                    Bitmap img = EPUBTest.Properties.Resources.jpegSample;
                    MemoryStream memImg = new MemoryStream();
                    img.Save(memImg, ImageFormat.Jpeg);
                    epub.AddImageData("sample.jpg", memImg.GetBuffer());
                    page = page_template.Replace("%%CONTENT%%", "<img src=\"sample.jpg\" alt=\"\"/>");
                    epub.AddXhtmlData(pageName, page);
                    navImageTests.AddNavPoint("JPEG Test", pageName, navCounter++);
                    pageCounter++;
                    pageName = String.Format("page{0}.xhtml", pageCounter);
                }

                if (checkBoxGif.Checked)
                {
                    Bitmap img = EPUBTest.Properties.Resources.gifSample;
                    MemoryStream memImg = new MemoryStream();
                    img.Save(memImg, ImageFormat.Gif);
                    epub.AddImageData("sample.gif", memImg.GetBuffer());
                    page = page_template.Replace("%%CONTENT%%", "<img src=\"sample.gif\" alt=\"\"/>");
                    epub.AddXhtmlData(pageName, page);
                    navImageTests.AddNavPoint("GIF Test", pageName, navCounter++);
                    pageCounter++;
                    pageName = String.Format("page{0}.xhtml", pageCounter);
                }

                if (checkBoxSvg.Checked)
                {
                    byte[] svg = EPUBTest.Properties.Resources.svgSample;

                    epub.AddImageData("sample.svg", svg);
                    page = page_template.Replace("%%CONTENT%%", "<img width=\"500\" height=\"500\" src=\"sample.svg\" alt=\"\"/>");
                    epub.AddXhtmlData(pageName, page);
                    navImageTests.AddNavPoint("SVG Test", pageName, navCounter++);
                    pageCounter++;
                    pageName = String.Format("page{0}.xhtml", pageCounter);
                }
            }

            page = page_template.Replace("%%CONTENT%%", richtextSampleContent.Text);

            epub.AddXhtmlData(pageName, page);
            epub.AddNavPoint("Your sample content", pageName, navCounter++);
            pageCounter++;
            pageName = String.Format("page{0}.xhtml", pageCounter);

            page = page_template.Replace("%%CONTENT%%", "<h1>Notes</h1><a id=\"n1\">1</a> Just note sample");

            epub.AddXhtmlData("notes.xhtml", page);
            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);
            }
        }
 /// <summary>
 /// Renders the epub document.
 /// </summary>
 /// <returns></returns>
 public Epub.Document RenderEpubDocument(Epub.NavPoint parentEndPoint)
 {
     Epub.Document output = new Epub.Document();
     this.Render(this.PrintContext, output, parentEndPoint);
     return output;
 }
        /// <summary>
        /// Creates the html.
        /// </summary>
        /// <returns></returns>
        public static string CreateDocument(Controller controller)
        {
            var fileOutputLocation = @"\\\\JCSHP10DEV14\\Public\\ePubBooks\\testEPubBook.epub";

            var projectId = "{B80EB639-5E3E-445C-BE73-B5CA3F4119BA}";
            var projectItem = Database.GetItem(projectId);
            try
            {
                if (projectItem != null)
                {
                    var documentItem = projectItem.Children.FirstOrDefault(itm => itm.TemplateID.Equals(ID.Parse("{E3261481-32CE-4D68-B5D1-79E7CB9C1CB9}")));
                    if (documentItem != null)
                    {
                        var epubDoc = new Epub.Document();

                        var contentItem = ((ReferenceField)documentItem.Fields["Item Reference"]).TargetItem;

                        //Metadata
                        epubDoc.AddAuthor(documentItem["Author"]);
                        epubDoc.AddTitle(documentItem["Title"]);
                        epubDoc.AddLanguage(documentItem["Language"]);

                        //embeded fonts
                        foreach (var fontId in ((MultilistField)documentItem.Fields["Fonts"]).TargetIDs)
                        {
                            var font = Database.GetItem(fontId);
                            if (font != null)
                            {
                                epubDoc.AddFile(font["Path Base"] + font["File Name"], font["ePub File Base"] + font["ePub File Name"], "application/octet-stream");
                            }
                        }

                        //add stylesheet with @font-face
                        foreach (var cssId in ((MultilistField)documentItem.Fields["StyleSheets"]).TargetIDs)
                        {
                            var css = Database.GetItem(cssId);
                            if (css != null)
                            {
                                epubDoc.AddStylesheetFile(css["Path Base"] + css["File Name"], css["ePub File Base"] + css["ePub File Name"]);
                            }
                        }

                        // Add image files (figures)
                        //epubDoc.AddImageFile("D:\\siteroot\\local7cms.weil.com\\Website\\Content\\images\\office-map.png", "office-map.png");
                        //epubDoc.AddImageFile("D:\\siteroot\\local7cms.weil.com\\Website\\Content\\images\\icon-select.png", "icon-select.png");

                        // add chapters' xhtml and setup TOC entries
                        int navCounter = 0;
                        for (int chapterCounter = 0; chapterCounter < documentItem.Children.Count; chapterCounter++)
                        {
                            var chapter = documentItem.Children[chapterCounter];
                            String chapterFile = String.Format("{0}.xhtml", chapter["Title"]);
                            String chapterName = chapter["Title"];

                            var xpath = chapter["Item Selector"];
                            if (!string.IsNullOrEmpty(xpath))
                            {
                                Item selectorDataItem = contentItem.Axes.SelectSingleItem(xpath);
                                if (selectorDataItem != null)
                                {
                                    epubDoc.AddXhtmlData(chapterFile, GenerateXhtml(selectorDataItem, controller));
                                }
                            }
                            else
                            {
                                epubDoc.AddXhtmlData(chapterFile, GenerateXhtml(contentItem, controller));
                            }

                            var chapterTOCEntry =
                                epubDoc.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
                        epubDoc.Generate(fileOutputLocation);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex, typeof(EpubManager));
            }
            return projectId;
        }
Exemplo n.º 8
0
        private void testButton_Click(object sender, EventArgs e)
        {
            var epub = new EPubDocument();

            epub.AddAuthor(textboxAuthor.Text);
            epub.AddTitle(textboxTitle.Text);
            epub.AddLanguage("en");

            String css = EPUBTest.Properties.Resources.style;

            if (checkBoxFonts.Checked)
            {
                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", EPUBTest.Properties.Resources.LiberationSerif_Regular, "application/octet-stream");
                epub.AddData("LiberationSerif-Bold.ttf", EPUBTest.Properties.Resources.LiberationSerif_Bold, "application/octet-stream");
                epub.AddData("LiberationSerif-Italic.ttf", EPUBTest.Properties.Resources.LiberationSerif_Italic, "application/octet-stream");
                epub.AddData("LiberationSerif-BoldItalic.ttf", EPUBTest.Properties.Resources.LiberationSerif_BoldItalic, "application/octet-stream");
            }

            epub.AddStylesheetData("style.css", css);
            Bitmap       coverImg  = EPUBTest.Properties.Resources.pngSample;
            MemoryStream coverData = new MemoryStream();

            coverImg.Save(coverData, ImageFormat.Png);
            String coverId = epub.AddImageData("cover.png", coverData.GetBuffer());

            epub.AddMetaItem("cover", coverId);

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

            int navCounter  = 1;
            int pageCounter = 1;

            string content = "<h1>Header 1</h1>";

            content += "<h2>Header 2</h2>";
            content += "<h3>Header 3</h3>";
            content += "<h4>Regular paragraph</h4>";
            content += "<p>" + EPUBTest.Properties.Resources.lorem + "<a href=\"notes.xhtml#n1\">[1]</a></p>";

            content += "<h4>Bold paragraph</h4>";
            content += "<p class=\"bold\">" + EPUBTest.Properties.Resources.lorem + "</p>";

            content += "<h4>Italic paragraph</h4>";
            content += "<p class=\"italic\">" + EPUBTest.Properties.Resources.lorem + "</p>";

            content += "<h4>Bold+Italic paragraph</h4>";
            content += "<p class=\"bolditalic\">" + EPUBTest.Properties.Resources.lorem + "</p>";

            String page = page_template.Replace("%%CONTENT%%", content);

            String pageName = String.Format("page{0}.xhtml", pageCounter);

            epub.AddXhtmlData(pageName, page);
            epub.AddNavPoint("Lorem ipsum", pageName, navCounter++);
            pageCounter++;
            pageName = String.Format("page{0}.xhtml", pageCounter);
            if (checkBoxGif.Checked || checkBoxPng.Checked || checkBoxJpeg.Checked || checkBoxSvg.Checked)
            {
                var navImageTests = epub.AddNavPoint("Image tests", pageName, navCounter);

                if (checkBoxPng.Checked)
                {
                    Bitmap       img    = EPUBTest.Properties.Resources.pngSample;
                    MemoryStream memImg = new MemoryStream();
                    img.Save(memImg, ImageFormat.Png);
                    epub.AddImageData("sample.png", memImg.GetBuffer());
                    page = page_template.Replace("%%CONTENT%%", "<img src=\"sample.png\" alt=\"\"/>");
                    epub.AddXhtmlData(pageName, page);
                    navImageTests.AddNavPoint("PNG Test", pageName, navCounter++);
                    pageCounter++;
                    pageName = String.Format("page{0}.xhtml", pageCounter);
                }

                if (checkBoxJpeg.Checked)
                {
                    Bitmap       img    = EPUBTest.Properties.Resources.jpegSample;
                    MemoryStream memImg = new MemoryStream();
                    img.Save(memImg, ImageFormat.Jpeg);
                    epub.AddImageData("sample.jpg", memImg.GetBuffer());
                    page = page_template.Replace("%%CONTENT%%", "<img src=\"sample.jpg\" alt=\"\"/>");
                    epub.AddXhtmlData(pageName, page);
                    navImageTests.AddNavPoint("JPEG Test", pageName, navCounter++);
                    pageCounter++;
                    pageName = String.Format("page{0}.xhtml", pageCounter);
                }

                if (checkBoxGif.Checked)
                {
                    Bitmap       img    = EPUBTest.Properties.Resources.gifSample;
                    MemoryStream memImg = new MemoryStream();
                    img.Save(memImg, ImageFormat.Gif);
                    epub.AddImageData("sample.gif", memImg.GetBuffer());
                    page = page_template.Replace("%%CONTENT%%", "<img src=\"sample.gif\" alt=\"\"/>");
                    epub.AddXhtmlData(pageName, page);
                    navImageTests.AddNavPoint("GIF Test", pageName, navCounter++);
                    pageCounter++;
                    pageName = String.Format("page{0}.xhtml", pageCounter);
                }

                if (checkBoxSvg.Checked)
                {
                    byte[] svg = EPUBTest.Properties.Resources.svgSample;

                    epub.AddImageData("sample.svg", svg);
                    page = page_template.Replace("%%CONTENT%%", "<img width=\"500\" height=\"500\" src=\"sample.svg\" alt=\"\"/>");
                    epub.AddXhtmlData(pageName, page);
                    navImageTests.AddNavPoint("SVG Test", pageName, navCounter++);
                    pageCounter++;
                    pageName = String.Format("page{0}.xhtml", pageCounter);
                }
            }

            page = page_template.Replace("%%CONTENT%%", richtextSampleContent.Text);

            epub.AddXhtmlData(pageName, page);
            epub.AddNavPoint("Your sample content", pageName, navCounter++);
            pageCounter++;
            pageName = String.Format("page{0}.xhtml", pageCounter);

            page = page_template.Replace("%%CONTENT%%", "<h1>Notes</h1><a id=\"n1\">1</a> Just note sample");

            epub.AddXhtmlData("notes.xhtml", page);
            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);
            }
        }