示例#1
0
        private void ShowDocumentAsList(IInputHandler argsHandler)
        {
            try
            {
                _out.WriteLine($"Title: {_document.GetTitle()}");
                for (var i = 0; i < _document.GetItemsCount(); ++i)
                {
                    var          info      = $"{i}. ";
                    DocumentItem item      = _document.GetItem(i);
                    IImage       image     = item.Image;
                    IParagraph   paragraph = item.Paragraph;

                    if (image != null)
                    {
                        info += $"Image: { image.Width } { image.Height }  { image.Path }";
                    }
                    else if (paragraph != null)
                    {
                        info += $"Paragraph: { paragraph.GetParagraphText() }";
                    }

                    _out.WriteLine(info);
                }

                _out.WriteLine();
            }
            catch (Exception ex)
            {
                _out.WriteLine(ex.Message);
            }
        }
示例#2
0
        public HTMLDocumentSaver(string path, List <DocumentItem> items, string title)
        {
            if (File.Exists(path))
            {
                Console.WriteLine($"File {path} already exist and will be deleted");
                File.Delete(path);
            }

            using (StreamWriter sW = new StreamWriter(path))
            {
                sW.WriteLine("<!DOCTYPE html>");
                sW.WriteLine("<head>");
                sW.WriteLine($"  <title>{ HttpUtility.HtmlEncode(title) } </title>");
                sW.WriteLine("</head>");
                sW.WriteLine("<body>");

                foreach (DocumentItem item in items)
                {
                    IParagraph paragraph = item.Paragraph;
                    IImage     image     = item.Image;
                    if (paragraph != null)
                    {
                        sW.WriteLine($"<p>{ HttpUtility.HtmlEncode(paragraph.GetParagraphText()) }</p>");
                    }
                    else if (image != null)
                    {
                        var relativePath = Path.GetRelativePath(Directory.GetCurrentDirectory(), image.Path);
                        Console.WriteLine(relativePath);
                        relativePath = relativePath.Replace("\\", "/");
                        sW.WriteLine($"<img src=\"{ HttpUtility.HtmlEncode(relativePath) }\" width=\"{ image.Width }\" height=\"{ image.Height }\"/>");
                    }
                }

                sW.WriteLine("</body>");
                sW.WriteLine("</html>");
                sW.Close();
            }
        }