コード例 #1
0
 /// <summary>
 /// Gets the RTF document content base list.
 /// </summary>
 /// <param name="rtfHtmlNodeList">The RTF HTML node list.</param>
 /// <returns></returns>
 private static RtfDocumentContentBase[] GetRtfDocumentContents(List <RtfHtmlNode> rtfHtmlNodeList)
 {
     RtfDocumentContentBase[] rtfDocumentContents = new RtfDocumentContentBase[rtfHtmlNodeList.Count];
     for (int nodeCount = 0; nodeCount < rtfHtmlNodeList.Count; nodeCount++)
     {
         RtfHtmlNode        rtfHtmlNode        = rtfHtmlNodeList[nodeCount];
         RtfParagraphFormat rtfParagraphFormat = new RtfParagraphFormat(FontSize,
                                                                        string.IsNullOrEmpty(rtfHtmlNode.RtfParagraphFormat)
                 ? RtfTextAlign.Justified
                 : GetRtfTextAlign(rtfHtmlNode.RtfParagraphFormat));
         RtfFormattedParagraph rtfFormattedParagraph = new RtfFormattedParagraph(rtfParagraphFormat);
         foreach (var rtfHtmlItem in rtfHtmlNode.RtfHtmlItem)
         {
             //Add text in paragraph
             if (!string.IsNullOrEmpty(rtfHtmlItem.HtmlText))
             {
                 rtfFormattedParagraph.AppendText(new RtfFormattedText(rtfHtmlItem.HtmlText, rtfHtmlItem.RtfFormattedText));
             }
             //Add image in paragraph
             if (rtfHtmlItem.HtmlImage != null)
             {
                 RtfImage rtfImage = new RtfImage(rtfHtmlItem.HtmlImage, RtfImageFormat.Wmf, rtfHtmlItem.ImageHeight, rtfHtmlItem.ImageWidth);
                 rtfFormattedParagraph.AppendText(rtfImage);
             }
         }
         rtfFormattedParagraph.Formatting.SpaceAfter = TwipConverter.ToTwip(10F, MetricUnit.Point);
         rtfDocumentContents[nodeCount] = rtfFormattedParagraph;
     }
     return(rtfDocumentContents);
 }
コード例 #2
0
        /// <summary>
        /// Gets the RTF HTML node list.
        /// </summary>
        /// <param name="htmlNode">The document node.</param>
        /// <returns></returns>
        private static List <RtfHtmlNode> GetRtfHtmlNodes(HtmlNode htmlNode)
        {
            List <RtfHtmlNode> rtfHtmlNodes = new List <RtfHtmlNode>();

            foreach (var node in htmlNode.ChildNodes)
            {
                IEnumerable <HtmlNode> descendantNodes = node.Descendants();
                RtfHtmlNode            rtfHtmlNode     = new RtfHtmlNode();
                if (node.Attributes.Count > 0)
                {
                    rtfHtmlNode.RtfParagraphFormat = node.Attributes[0].Value;
                }
                RtfHtmlItem rtfHtmlItem = new RtfHtmlItem();
                foreach (var currentNode in descendantNodes)
                {
                    if (currentNode.Name.Equals(RtfImageNodeName) && currentNode.Attributes.Count > 0) //Image
                    {
                        rtfHtmlItem = GetImage(currentNode);
                        rtfHtmlNode.RtfHtmlItem.Add(rtfHtmlItem);
                        rtfHtmlItem = new RtfHtmlItem();
                    }
                    else if (currentNode.Name.Equals(RtfTextNodeName)) //Text
                    {
                        rtfHtmlItem.HtmlText = currentNode.InnerText;
                        rtfHtmlNode.RtfHtmlItem.Add(rtfHtmlItem);
                        rtfHtmlItem = new RtfHtmlItem();
                    }
                    else //Format text
                    {
                        rtfHtmlItem.RtfFormattedText.Add(currentNode.Name);
                    }
                }
                rtfHtmlNodes.Add(rtfHtmlNode);
            }
            return(rtfHtmlNodes);
        }