Advertisement
andruhovski

Aspose Demo 01

Aug 21st, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using Aspose.Html;
  3.  
  4. namespace AsposeDemo01
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             //Create an instance of HTMLDocument
  11.             var document = new Aspose.Html.HTMLDocument();
  12.             // Add image
  13.             HTMLImageElement img = document.CreateElement("img") as HTMLImageElement;
  14.             if (img != null)
  15.             {
  16.                 img.Src = "http://via.placeholder.com/400x200";
  17.                 img.Alt = "Placeholder 400x200";
  18.                 img.Title = "Placeholder image";
  19.                 document.Body.AppendChild(img);
  20.             }
  21.            
  22.             // Add ordered list
  23.             HTMLOListElement orderedListElement = document.CreateElement("ol") as HTMLOListElement;
  24.             for (int i = 0; i < 10; i++)
  25.             {
  26.                 HTMLLIElement listItem = document.CreateElement("li") as HTMLLIElement;
  27.                 listItem.TextContent = $" List Item {i + 1}";
  28.                 orderedListElement.AppendChild(listItem);
  29.             }
  30.             document.Body.AppendChild(orderedListElement);
  31.             // Adding simple table 3x3
  32.             HTMLTableElement table = document.CreateElement("table") as HTMLTableElement;
  33.             HTMLTableSectionElement tBody = document.CreateElement("tbody") as HTMLTableSectionElement;
  34.             for (var i = 0; i < 3; i++)
  35.             {
  36.                 HTMLTableRowElement row = document.CreateElement("tr") as HTMLTableRowElement;
  37.                 row.Id = "trow_" + i;
  38.                 for (var j = 0; j < 3; j++)
  39.                 {
  40.                     HTMLTableCellElement cell = document.CreateElement("td") as HTMLTableCellElement;
  41.                     cell.Id = $"cell{i}_{j}";
  42.                     cell.TextContent = "Cell " + j;
  43.                     row.AppendChild(cell);
  44.                 }
  45.                 tBody.AppendChild(row);
  46.             }
  47.  
  48.             table.AppendChild(tBody);
  49.             document.Body.AppendChild(table);
  50.  
  51.             //Store document to disk                        
  52.             document.Save(@"c:\asposedemo\files\demo01.html");
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement