Exemple #1
0
        public void UnrecognisedStylesAreStatedInMessages()
        {
            var documentConverter = new DocumentConverter();
            var result            = documentConverter.ConvertToHtml("TestDocuments/unrecognised-paragraph-styles.docx");

            Assert.AreEqual("Unrecognised paragraph style: 'Funky' (Style ID: style20)", result.Messages[0].Value);
        }
        public async Task <string> DocToHTML(int contentId)
        {
            var content = await db.ContentFiles
                          .Include(x => x.FileDocument)
                          .FirstOrDefaultAsync(x => x.Id == contentId);

            if (content == null)
            {
                return("<bold>Error</strong>");
            }

            var fileFullPath = Path.Combine(storageDir, content.FileDocument.FileNameOnStorage);

            try
            {
                var converter = new DocumentConverter();
                var result    = converter.ConvertToHtml(fileFullPath);
                var html      = result.Value; // The generated HTML
                var warnings  = result.Warnings;

                if (String.IsNullOrEmpty(html))
                {
                    return("Error reading the document.");
                }

                return(html);
            }
            catch (Exception e)
            {
                return("Error reading the document.");
            }
        }
Exemple #3
0
        public void SingleWordParagraphIsConvertedToSingleHtmlParagraph()
        {
            var documentConverter = new DocumentConverter();
            var result            = documentConverter.ConvertToHtml("TestDocuments/single-paragraph.docx");

            Assert.AreEqual("<p>Walking on imported air</p>", result.Value);
            Assert.IsEmpty(result.Messages);
        }
Exemple #4
0
        //Convert any doc to text file
        public static string DocToText(string filePath)
        {
            var converter = new DocumentConverter();
            var result    = converter.ConvertToHtml(filePath);
            var html      = result.Value;

            return(html);
        }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "MS Word 2016 (*.docx)|*.docx";
            dialog.Title  = "Выберите документ для загрузки данных";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox1.Text = dialog.FileName;
                var converter = new DocumentConverter();
                var result    = converter.ConvertToHtml(dialog.FileName);
                html = result.Value; // The generated HTML

                string br1 = "<br /><br /><br />";
                string br2 = "<br />\n< br /> ";
                string br3 = "<br /></h2>";
                string br4 = "<br /><br />";
                string br5 = "<br />";
                html = html.Replace("</li>", "</li>\n").Replace("<ul>", "<ul>\n").Replace("<ol>", "<ol>\n").Replace("</p>", "\n\n").Replace("<p>", "").Replace("</ul>", "</ul>\n\n").Replace("</ol>", "</ol>\n\n").Replace("< br />", "").Replace("< br />", "").Replace("тысячей", "тысяч").Replace("привёдшее", "приведшее").Replace("</strong>: <strong>", ": ").Replace("<strong> </strong>", " ");
                if (chIfMfc.Checked == true)
                {
                    html = html.Replace("<strong>", "<h2>").Replace("</strong>", "</h2>\n\n").Replace("</h3>", "</h3>\n\n").Replace("</h1>", "\n\n").Replace("<h1>", "").Replace("</h2>", "</h2>\n\n").Replace("< br />", "");
                }
                else
                {
                    html = html.Replace("<strong>", "<h2>").Replace("</strong>", "</h2>\n\n").Replace(br1, " ").Replace(br4, "\n\n").Replace(br2, "\n\n").Replace(br3, "</h2>").Replace(br5, "");
                }

                html = html.Replace("<strong> </strong>", " ");

                //Блок Ютьюб
                string[] words = html.Split(' ');
                string   s0    = words[1];
                string   sCont = "href";
                bool     b     = s0.Contains(sCont);
                if (b)
                {
                    s0 = s0.Replace("<strong>", "").Replace("</strong>", "");
                }
                else
                {
                    s0 = html.Remove(html.IndexOf("\n"), html.Length - html.IndexOf("\n"));
                }
                //Search.q = html.Remove(html.IndexOf("\n"), html.Length - html.IndexOf("\n"));
                Search.q = s0;
                Search.YTBsearch();


                rtbYTBlist.Text = Search.listUrl;
                YtbZagolovok    = $"<h3 style=\"text-align: center;\">{nazvYtb}</h3>\n";
                html           += YtbZagolovok;
                html           += sborkaYoutube;
            }
        }
        // ONLY TO BE USED FOR CONVERSION  WHEN FILE FIRST TIME UPLOADED
        // THE FILE WILL ALSO BE SENT TO API ONCE SAVED AND AVAILABLE FOR FUTURE USE
        public string DocToHTML(string fileType, string courseId, string fileName)
        {
            var fileFullPath = Path.Combine(storageDir, fileName);

            try
            {
                var converter = new DocumentConverter();
                var result    = converter.ConvertToHtml(fileFullPath);
                var html      = result.Value; // The generated HTML
                var warnings  = result.Warnings;

                if (String.IsNullOrEmpty(html))
                {
                    return("Error reading the document.");
                }

                return(html);
            }
            catch (Exception e)
            {
                return("Error reading the document.");
            }
        }