Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Allow conversion of HTTPS websites with custom SSL certificate validation callbacks to ensure security.

using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;

class Program
{
static void Main()
{
try
{
// Custom SSL certificate validation: accept only if there are no SSL errors.
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
{
return sslPolicyErrors == System.Net.Security.SslPolicyErrors.None;
};

string url = "https://example.com";
string outputPath = "output.pdf";

Aspose.Html.Configuration configuration = new Aspose.Html.Configuration();

using (Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(url, configuration))
{
Aspose.Html.Saving.PdfSaveOptions options = new Aspose.Html.Saving.PdfSaveOptions();
Aspose.Html.Converters.Converter.ConvertHTML(document, options, outputPath);
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Apply a custom CSS stylesheet during conversion to override the default website styling.

using System;
using System.IO;

class Program
{
static void Main()
{
try
{
// Define file paths
string inputHtmlPath = "sample.html";
string cssPath = "custom.css";
string outputPdfPath = "output.pdf";

// Create sample HTML file
if (!File.Exists(inputHtmlPath))
{
File.WriteAllText(inputHtmlPath, "<html><head></head><body><h1>Hello World</h1></body></html>");
}

// Create custom CSS file
if (!File.Exists(cssPath))
{
File.WriteAllText(cssPath, "h1 { color: red; }");
}

// Read CSS content
string cssContent = File.ReadAllText(cssPath);

// Configure Aspose.HTML with custom stylesheet
Aspose.Html.Configuration configuration = new Aspose.Html.Configuration();
Aspose.Html.Services.IUserAgentService userAgent = (Aspose.Html.Services.IUserAgentService)configuration.GetService(typeof(Aspose.Html.Services.IUserAgentService));
userAgent.UserStyleSheet = cssContent;

// Set PDF save options
Aspose.Html.Saving.PdfSaveOptions options = new Aspose.Html.Saving.PdfSaveOptions();

// Convert HTML to PDF applying the custom CSS
Aspose.Html.Converters.Converter.ConvertHTML(
new Aspose.Html.Url(inputHtmlPath),
configuration,
options,
outputPdfPath);

Console.WriteLine("Conversion completed successfully. Output saved to: " + outputPdfPath);
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Apply a custom HTML template to wrap converted content for a consistent page layout.

using System;
using System.IO;

class Program
{
static void Main()
{
try
{
// Define file paths
string sourcePath = "source.html";
string templateDataPath = "template.html";
string resultPath = "result.html";

// Create sample source HTML if it does not exist
if (!File.Exists(sourcePath))
{
File.WriteAllText(sourcePath, "<html><body><h1>Hello, World!</h1></body></html>");
}

// Create sample template HTML if it does not exist
if (!File.Exists(templateDataPath))
{
// The template should contain a placeholder where the source content will be inserted.
// Using {{content}} as a placeholder is typical for Aspose HTML templates.
File.WriteAllText(templateDataPath,
"<html><head><title>Template Page</title></head><body><div class=\"wrapper\">{{content}}</div></body></html>");
}

// Load the source document
using Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(sourcePath, new Aspose.Html.Configuration());

// Prepare template data
Aspose.Html.Converters.TemplateData templateData = new Aspose.Html.Converters.TemplateData(templateDataPath);

// Load template options
Aspose.Html.Loading.TemplateLoadOptions options = new Aspose.Html.Loading.TemplateLoadOptions();

// Convert using the template
Aspose.Html.HTMLDocument resultDocument = Aspose.Html.Converters.Converter.ConvertTemplate(document, templateData, options);

// Save the resulting document
resultDocument.Save(resultPath);

// Dispose the result document
resultDocument.Dispose();

Console.WriteLine($"Template conversion completed successfully. Output saved to '{resultPath}'.");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Configure proxy settings to access websites behind corporate firewalls securely during conversion.

using System;

class Program
{
static void Main()
{
try
{
string url = "https://www.example.com";
string outputPath = "example.pdf";

var config = new Aspose.Html.Configuration();

using (var document = new Aspose.Html.HTMLDocument(url, config))
{
var pdfOptions = new Aspose.Html.Saving.PdfSaveOptions();
Aspose.Html.Converters.Converter.ConvertHTML(document, pdfOptions, outputPath);
}

Console.WriteLine("Conversion completed successfully.");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Convert multiple website URLs in batch mode, storing each result in separate HTML files.

using System;

class Program
{
static void Main()
{
try
{
string outputDir = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "output");
System.IO.Directory.CreateDirectory(outputDir);

string[] urls = new string[] { "https://example.com", "https://example.org" };

for (int i = 0; i < urls.Length; i++)
{
using (var document = new Aspose.Html.HTMLDocument(urls[i]))
{
string outputPath = System.IO.Path.Combine(outputDir, $"page_{i + 1}.html");
document.Save(outputPath);
}
}

System.Console.WriteLine("Conversion completed.");
}
catch (System.Exception ex)
{
System.Console.WriteLine("Error: " + ex.Message);
}
}
}
Loading
Loading