andruhovski icon

Aspose Demo 01

andruhovski | PRO | 08/21/17 08:12:30 AM UTC | 0 ⭐ | 629 👁️ | Never ⏰ | []
C# |

2.12 KB

|

None

|

0 👍

/

0 👎

using System;
using Aspose.Html;
 
namespace AsposeDemo01
{
    class Program
    {
        static void Main()
        {
            //Create an instance of HTMLDocument
            var document = new Aspose.Html.HTMLDocument();
            // Add image
            HTMLImageElement img = document.CreateElement("img") as HTMLImageElement;
            if (img != null)
            {
                img.Src = "http://via.placeholder.com/400x200";
                img.Alt = "Placeholder 400x200";
                img.Title = "Placeholder image";
                document.Body.AppendChild(img);
            }
            
            // Add ordered list
            HTMLOListElement orderedListElement = document.CreateElement("ol") as HTMLOListElement;
            for (int i = 0; i < 10; i++)
            {
                HTMLLIElement listItem = document.CreateElement("li") as HTMLLIElement;
                listItem.TextContent = $" List Item {i + 1}";
                orderedListElement.AppendChild(listItem);
            }
            document.Body.AppendChild(orderedListElement);
            // Adding simple table 3x3 
            HTMLTableElement table = document.CreateElement("table") as HTMLTableElement;
            HTMLTableSectionElement tBody = document.CreateElement("tbody") as HTMLTableSectionElement;
            for (var i = 0; i < 3; i++)
            {
                HTMLTableRowElement row = document.CreateElement("tr") as HTMLTableRowElement;
                row.Id = "trow_" + i;
                for (var j = 0; j < 3; j++)
                {
                    HTMLTableCellElement cell = document.CreateElement("td") as HTMLTableCellElement;
                    cell.Id = $"cell{i}_{j}";
                    cell.TextContent = "Cell " + j;
                    row.AppendChild(cell);
                }
                tBody.AppendChild(row);
            }
 
            table.AppendChild(tBody);
            document.Body.AppendChild(table);
 
            //Store document to disk                        
            document.Save(@"c:\asposedemo\files\demo01.html");
        }
    }
}

Comments