Skip to content

Commit ebd8e5f

Browse files
Examples Basic Structure
1 parent 08e2b95 commit ebd8e5f

File tree

58 files changed

+2782
-0
lines changed
  • content/english/net
    • advanced-features
      • create-stream-provider-dotnet-aspose-html
      • environment-configuration-dotnet-aspose-html
      • fine-tuning-converters-dotnet-aspose-html
      • generate-encrypted-pdf-by-pdfdevice-dotnet-aspose-html
      • memory-stream-provider-dotnet-aspose-html
      • use-extended-content-property-dotnet-aspose-html
      • using-html-templates-dotnet-aspose-html
      • web-scraping-dotnet-aspose-html
    • barcode-generation-in-html-documents
    • canvas-and-image-manipulation
    • generate-jpg-and-png-images
    • html-document-manipulation
      • creating-a-document-dotnet-aspose-html
      • editing-a-document-dotnet-aspose-html
      • generate-xps-documents-by-xpsdevice-dotnet-aspose-html
      • load-html-doc-asynchronously-dotnet-aspose-html
      • load-html-doc-with-credentials-dotnet-aspose-html
      • load-html-using-remote-server-dotnet-aspose-html
      • load-html-using-url-dotnet-aspose-html
      • merge-html-with-json-dotnet-aspose-html
      • merge-html-with-xml-dotnet-aspose-html
      • saving-a-document-dotnet-aspose-html
    • html-extensions-and-conversions
      • convert-epub-to-image-dotnet-aspose-html
      • convert-epub-to-pdf-dotnet-aspose-html
      • convert-epub-to-xps-dotnet-aspose-html
      • convert-html-to-bmp-dotnet-aspose-html
      • convert-html-to-doc-docx-dotnet-aspose-html
      • convert-html-to-gif-dotnet-aspose-html
      • convert-html-to-jpeg-dotnet-aspose-html
      • convert-html-to-markdown-dotnet-aspose-html
      • convert-html-to-mhtml-dotnet-aspose-html
      • convert-html-to-pdf-dotnet-aspose-html
      • convert-html-to-png-dotnet-aspose-html
      • convert-html-to-tiff-dotnet-aspose-html
      • convert-html-to-xps-dotnet-aspose-html
    • licensing-and-initialization
    • rendering-html-documents
    • table-manipulation-in--html-documents
    • working-with-html-documents

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2782
-0
lines changed

content/english/net/_index.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Comprehensive Tutorials and Examples of Aspose.HTML for .NET
3+
linktitle: Aspose.HTML for .NET Tutorials
4+
type: docs
5+
weight: 10
6+
url: /net/
7+
description:
8+
is_root: true
9+
---
10+
11+
### [HTML Extensions and Conversions](./html-extensions-and-conversions/)
12+
13+
### [HTML Document Manipulation](./html-document-manipulation/)
14+
15+
### [Canvas and Image Manipulation](./canvas-and-image-manipulation/)
16+
17+
### [Working with HTML Documents](./working-with-html-documents/)
18+
19+
### [Advanced Features](./advanced-features/)
20+
21+
### [Barcode Generation in HTML Documents](./barcode-generation-in-html-documents/)
22+
23+
### [Table Manipulation in HTML Documents](./table-manipulation-in--html-documents/)
24+
25+
### [Licensing and Initialization](./licensing-and-initialization/)
26+
27+
### [Generate JPG and PNG Images](./generate-jpg-and-png-images/)
28+
29+
### [Rendering HTML Documents](./rendering-html-documents/)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Advanced Features
3+
linktitle: Advanced Features
4+
second_title: Aspose.Slides .NET HTML manipulation API
5+
description:
6+
type: docs
7+
weight: 24
8+
url: /net/advanced-features/
9+
---
10+
11+
## Advanced Features Tutorials
12+
### [Environment Configuration in .NET with Aspose.HTML](./environment-configuration-dotnet-aspose-html/)
13+
### [Create Stream Provider in .NET with Aspose.HTML](./create-stream-provider-dotnet-aspose-html/)
14+
### [Memory Stream Provider in .NET with Aspose.HTML](./memory-stream-provider-dotnet-aspose-html/)
15+
### [Web Scraping in .NET with Aspose.HTML](./web-scraping-dotnet-aspose-html/)
16+
### [Use Extended Content Property in .NET with Aspose.HTML](./use-extended-content-property-dotnet-aspose-html/)
17+
### [Generate Encrypted PDF by PdfDevice in .NET with Aspose.HTML](./generate-encrypted-pdf-by-pdfdevice-dotnet-aspose-html/)
18+
### [Fine-Tuning Converters in .NET with Aspose.HTML](./fine-tuning-converters-dotnet-aspose-html/)
19+
### [Using HTML Templates in .NET with Aspose.HTML](./using-html-templates-dotnet-aspose-html/)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Create Stream Provider in .NET with Aspose.HTML
3+
linktitle: Create Stream Provider in .NET with Aspose.HTML
4+
second_title: Aspose.Slides .NET HTML manipulation API
5+
description:
6+
type: docs
7+
weight: 11
8+
url: /net/advanced-features/create-stream-provider-dotnet-aspose-html/
9+
---
10+
11+
## Complete Source Code
12+
```csharp
13+
public static void Run()
14+
{
15+
// ExStart:1
16+
// The path to the documents directory
17+
string dataDir = RunExamples.GetDataDir_Data();
18+
// Create a custom StreamProvider based on ICreateStreamProvider interface
19+
using (MemoryStreamProvider streamProvider = new MemoryStreamProvider())
20+
{
21+
// Create a simple HTML document
22+
using (HTMLDocument document = new HTMLDocument())
23+
{
24+
// Add your first 'hello world' to the document.
25+
document.Body.AppendChild(document.CreateTextNode("Hello world!!!"));
26+
// Convert HTML document to XPS by using the custom StreamProvider
27+
Aspose.Html.Converters.Converter.ConvertHTML(document, new XpsSaveOptions(), streamProvider);
28+
// Get access to the memory stream that contains the result data
29+
var memory = streamProvider.Streams[0];
30+
memory.Seek(0, SeekOrigin.Begin);
31+
// Flush the result data to the output file
32+
using (FileStream fs = File.Create(dataDir + "output.xps"))
33+
{
34+
memory.CopyTo(fs);
35+
}
36+
}
37+
}
38+
// ExEnd:1
39+
}
40+
}
41+
public class MemoryStreamProvider : ICreateStreamProvider
42+
{
43+
// List of MemoryStream objects created during the document rendering
44+
public List<MemoryStream> Streams { get; } = new List<MemoryStream>();
45+
public Stream GetStream(string name, string extension)
46+
{
47+
// This method is called when the only one output stream is required, for instance for XPS, PDF or TIFF formats
48+
MemoryStream result = new MemoryStream();
49+
Streams.Add(result);
50+
return result;
51+
}
52+
public Stream GetStream(string name, string extension, int page)
53+
{
54+
// This method is called when the creation of multiple output streams are required. For instance during the rendering HTML to list of the image files (JPG, PNG, etc.)
55+
MemoryStream result = new MemoryStream();
56+
Streams.Add(result);
57+
return result;
58+
}
59+
public void ReleaseStream(Stream stream)
60+
{
61+
// Here You can release the stream filled with data and, for instance, flush it to the hard-drive
62+
}
63+
public void Dispose()
64+
{
65+
// Releasing resources
66+
foreach (var stream in Streams)
67+
stream.Dispose();
68+
}
69+
```
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
title: Environment Configuration in .NET with Aspose.HTML
3+
linktitle: Environment Configuration in .NET with Aspose.HTML
4+
second_title: Aspose.Slides .NET HTML manipulation API
5+
description:
6+
type: docs
7+
weight: 10
8+
url: /net/advanced-features/environment-configuration-dotnet-aspose-html/
9+
---
10+
11+
## Complete Source Code
12+
```csharp
13+
public static void DisableScriptsExecution()
14+
{
15+
// Prepare an HTML code and save it to the file.
16+
var code = "<span>Hello World!!</span> " +
17+
"<script>document.write('Have a nice day!');</script>";
18+
System.IO.File.WriteAllText("document.html", code);
19+
// Create an instance of Configuration
20+
using (var configuration = new Aspose.Html.Configuration())
21+
{
22+
// Mark 'scripts' as an untrusted resource
23+
configuration.Security |= Aspose.Html.Sandbox.Scripts;
24+
// Initialize an HTML document with specified configuration
25+
using (var document = new Aspose.Html.HTMLDocument("document.html", configuration))
26+
{
27+
// Convert HTML to PDF
28+
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf");
29+
}
30+
}
31+
}
32+
public static void SpecifyUserStyleSheet()
33+
{
34+
// Prepare an HTML code and save it to the file.
35+
var code = @"<span>Hello World!!!</span>";
36+
System.IO.File.WriteAllText("document.html", code);
37+
// Create an instance of Configuration
38+
using (var configuration = new Aspose.Html.Configuration())
39+
{
40+
// Get the IUserAgentService
41+
var userAgent = configuration.GetService<Aspose.Html.Services.IUserAgentService>();
42+
// Set the custom color to the SPAN element
43+
userAgent.UserStyleSheet = "span { color: green; }";
44+
// Initialize an HTML document with specified configuration
45+
using (var document = new Aspose.Html.HTMLDocument("document.html", configuration))
46+
{
47+
// Convert HTML to PDF
48+
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf");
49+
}
50+
}
51+
}
52+
public static void JavaScriptExecutionTimeout()
53+
{
54+
// Prepare an HTML code with endless loop
55+
var code = @"<script>while(true){}</script>";
56+
System.IO.File.WriteAllText("document.html", code);
57+
// Create an instance of Configuration
58+
using (var configuration = new Aspose.Html.Configuration())
59+
{
60+
// Limit JS execution time to 10 seconds
61+
var runtime = configuration.GetService<Aspose.Html.Services.IRuntimeService>();
62+
runtime.JavaScriptTimeout = TimeSpan.FromSeconds(10);
63+
// Initialize an HTML document with specified configuration
64+
using (var document = new Aspose.Html.HTMLDocument("document.html", configuration))
65+
{
66+
// Wait until all scripts are finished/canceled and convert HTML to PNG
67+
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.ImageSaveOptions(), "output.png");
68+
}
69+
}
70+
}
71+
public static void CustomMessageHandler()
72+
{
73+
// Prepare an HTML code with missing image file
74+
var code = @"<img src='missing.jpg'>";
75+
System.IO.File.WriteAllText("document.html", code);
76+
// Create an instance of Configuration
77+
using (var configuration = new Aspose.Html.Configuration())
78+
{
79+
// Add ErrorMessageHandler to the chain of existing message handlers
80+
var network = configuration.GetService<Aspose.Html.Services.INetworkService>();
81+
network.MessageHandlers.Add(new LogMessageHandler());
82+
// Initialize an HTML document with specified configuration
83+
// During the document loading, the application will try to load the image and we will see the result of this operation in the console.
84+
using (var document = new Aspose.Html.HTMLDocument("document.html", configuration))
85+
{
86+
// Convert HTML to PNG
87+
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.ImageSaveOptions(), "output.png");
88+
}
89+
}
90+
}
91+
/// <summary>
92+
/// This message handler logs all failed requests to the console.
93+
/// </summary>
94+
class LogMessageHandler : Aspose.Html.Net.MessageHandler
95+
{
96+
public override void Invoke(Aspose.Html.Net.INetworkOperationContext context)
97+
{
98+
// Check whether response is OK
99+
if (context.Response.StatusCode != System.Net.HttpStatusCode.OK)
100+
{
101+
// Log information to console
102+
System.Console.WriteLine("File Not Found: " + context.Request.RequestUri);
103+
}
104+
// Invoke the next message handler in the chain.
105+
Next(context);
106+
}
107+
}
108+
```

0 commit comments

Comments
 (0)