Skip to content

Commit 710c96e

Browse files
committed
Added the samples SVG to PDF/Image and performance testing sample
1 parent 18202bf commit 710c96e

File tree

89 files changed

+174047
-0
lines changed

Some content is hidden

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

89 files changed

+174047
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Syncfusion.HtmlConverter;
3+
using Syncfusion.Pdf;
4+
using Syncfusion_HTMLtoPDF.Models;
5+
using System.Diagnostics;
6+
using System.IO;
7+
8+
namespace Syncfusion_HTMLtoPDF.Controllers
9+
{
10+
public class HomeController : Controller
11+
{
12+
private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment;
13+
public HomeController(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment)
14+
{
15+
_hostingEnvironment = hostingEnvironment;
16+
}
17+
public IActionResult Index()
18+
{
19+
return View();
20+
}
21+
public IActionResult ConvertToPdf()
22+
{
23+
24+
string fileName = "HtmlSample_Thousand";
25+
//string fileName = "HtmlSample";
26+
//string fileName = "HtmlSample_FiveHundred";
27+
//string fileName = "HtmlSample_Hundred";
28+
double totalTime = 0;
29+
string ConsoleLog = "";
30+
MemoryStream stream = null;
31+
for (int i = 0; i < 5; i++)
32+
{
33+
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
34+
BlinkConverterSettings settings = new BlinkConverterSettings();
35+
settings.AdditionalDelay = 0;
36+
settings.Margin.All = 0;
37+
settings.Scale = 1.0f;
38+
htmlConverter.ConverterSettings = settings;
39+
string htmlFilePath = Path.Combine(_hostingEnvironment.WebRootPath,"Data", fileName + ".html");
40+
Stopwatch watch = new Stopwatch();
41+
watch.Start();
42+
//Convert URL to PDF
43+
PdfDocument document = htmlConverter.Convert(htmlFilePath);
44+
watch.Stop();
45+
totalTime += watch.Elapsed.TotalSeconds;
46+
ConsoleLog+=(i + 1) + " conversion time:" + watch.Elapsed.TotalSeconds+"\n";
47+
48+
if (i == 0)
49+
{
50+
using (stream = new MemoryStream())
51+
{
52+
document.Save(stream);
53+
document.Close(true);
54+
}
55+
}
56+
}
57+
double averageTime = totalTime / 5;
58+
ConsoleLog+="Average conversion time:" + averageTime+"\n";
59+
System.IO.File.WriteAllText(Path.Combine(_hostingEnvironment.WebRootPath, "Data", fileName + ".txt"), ConsoleLog);
60+
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "HTML-to-PDF.pdf");
61+
}
62+
63+
public IActionResult Privacy()
64+
{
65+
return View();
66+
}
67+
68+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
69+
public IActionResult Error()
70+
{
71+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
72+
}
73+
}
74+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Syncfusion_HTMLtoPDF.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
builder.Services.AddControllersWithViews();
5+
6+
var app = builder.Build();
7+
8+
// Configure the HTTP request pipeline.
9+
if (!app.Environment.IsDevelopment())
10+
{
11+
app.UseExceptionHandler("/Home/Error");
12+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
13+
app.UseHsts();
14+
}
15+
16+
app.UseHttpsRedirection();
17+
app.UseStaticFiles();
18+
19+
app.UseRouting();
20+
21+
app.UseAuthorization();
22+
23+
app.MapControllerRoute(
24+
name: "default",
25+
pattern: "{controller=Home}/{action=Index}/{id?}");
26+
27+
app.Run();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:65381",
8+
"sslPort": 44317
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5083",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7010;http://localhost:5083",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Windows" Version="*" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>https</ActiveDebugProfile>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.10.34916.146
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Syncfusion_HTMLtoPDF", "Syncfusion_HTMLtoPDF.csproj", "{02031B6D-6142-4AE3-BB08-E111536F1131}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{02031B6D-6142-4AE3-BB08-E111536F1131}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{02031B6D-6142-4AE3-BB08-E111536F1131}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{02031B6D-6142-4AE3-BB08-E111536F1131}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{02031B6D-6142-4AE3-BB08-E111536F1131}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {75287BD0-75CD-42F6-A03B-9F7B108D23D0}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
@{
6+
Html.BeginForm("ConvertToPdf", "Home", FormMethod.Post);
7+
{
8+
<div>
9+
<input type="submit" value="Convert HTML to PDF" />
10+
</div>
11+
}
12+
Html.EndForm();
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>

0 commit comments

Comments
 (0)