コード例 #1
0
ファイル: Class1.cs プロジェクト: sashaMilka/MultiReader
        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");
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: startewho/Html2Epub
        /*
         * 执行按钮
         */
        private void tbGenerateEpub_Click(object sender, EventArgs e)
        {
            if (btnStart.Text.Equals("下一步"))//下一步的命令
            {
                tabControl1.SelectedIndex = 1;//强制跳到第一个

                return;
            }
            tabControl1.SelectedIndex = 2;//切换到进度tab

            if (tbEPubFilePath.Text.Length < 1)//为空时需要选择文件名
            {
                btnSelectEPubFilePath_Click(null, null);//强制弹出按钮
            }

            if (tbEPubFilePath.Text.Length < 1)
            {
                AddLog("未选择保存的epub文件路径");
                return;
            }

            createTemp();//创建临时目录

            _documentOrder = 0;//重新初始化计数
            _folderOrder = 0;
            _playorder = 1;//重新初始化,从1开始,0表示封面的编号

            int docCount = getWizFolderDocumentCount(axWizCategoryTree.SelectedFolder as WizFolder);

            progressBarConver.Maximum = docCount;
            progressBarConver.Value = 0;

            Document epub = new Document();
            //Add metadata
            epub.AddAuthor(tbAuthor.Text);
            epub.AddTitle(tbTitle.Text);
            epub.AddLanguage(tbLanguage.Text);
            epub.AddType(tbSubject.Text);
            epub.AddStylesheetFile(Path.Combine(Application.StartupPath, "style.css"), "style.css");

            if (picCover.Image != null)
            {
                FileInfo imgfile = new FileInfo(picCover.ImageLocation);
                if (imgfile.Exists)
                {
                    string imgname = "cover" + imgfile.Extension.ToLower();
                    epub.AddImageFile(imgfile.FullName, imgname);
                    epub.AddNavPoint("封面", "cover.xhtml", _playorder++);
                    string html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>Cover</title><style type=\"text/css\"> img { max-width: 100%; } </style></head><body><div id=\"cover-image\"><img src=\"" + imgname + "\" alt=\"为知笔记电子书\"/></div></body></html>";
                    epub.AddXhtmlData("cover.xhtml", html);
                }
            }

            ExportWizFolder(_temppath, axWizCategoryTree.SelectedFolder as WizFolder, null, true, epub);

            AddLog("正在生成EPub文件,请稍候...");
            try
            {
                epub.Generate(tbEPubFilePath.Text);
                AddLog("生成EPub完成:" + tbEPubFilePath.Text);
            }
            catch (Exception ex)
            {
                AddLog("失败:" + ex.Message);
            }

            AddLog("正在清理临时文件,请稍候...");

            clearTemp();//清理缓存

            AddLog("完成");
        }
コード例 #3
0
ファイル: EpubParser.cs プロジェクト: sashaMilka/MultiReader
        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);
        }