Skip to content

Commit 502fdbd

Browse files
Merge pull request #16 from SyncfusionExamples/890341
890341: Add sample for HTML to PDF volume 2 feature.
2 parents baeb262 + 691135e commit 502fdbd

File tree

79 files changed

+74901
-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.

79 files changed

+74901
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md
26+
!**/.gitignore
27+
!.git/HEAD
28+
!.git/config
29+
!.git/packed-refs
30+
!.git/refs/heads/**
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.8.34330.188
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTML-to-PDF-Azure-app-service", "HTML-to-PDF-Azure-app-service\HTML-to-PDF-Azure-app-service.csproj", "{63F1F3FE-07AB-4F0A-B7FE-514BC1D27D11}"
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+
{63F1F3FE-07AB-4F0A-B7FE-514BC1D27D11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{63F1F3FE-07AB-4F0A-B7FE-514BC1D27D11}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{63F1F3FE-07AB-4F0A-B7FE-514BC1D27D11}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{63F1F3FE-07AB-4F0A-B7FE-514BC1D27D11}.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 = {F1479F2E-A1B8-4E21-9838-AEF53051A43C}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using HTML_to_PDF_Azure_app_service.Models;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.Diagnostics;
4+
using Syncfusion.HtmlConverter;
5+
using Syncfusion.Pdf;
6+
7+
namespace HTML_to_PDF_Azure_app_service.Controllers
8+
{
9+
public class HomeController : Controller
10+
{
11+
public IActionResult ExportToPDF()
12+
{
13+
//Initialize HTML to PDF converter.
14+
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Cef);
15+
16+
CefConverterSettings cefConverterSettings = new CefConverterSettings();
17+
18+
//Set Blink viewport size.
19+
cefConverterSettings.ViewPortSize = new Syncfusion.Drawing.Size(1280, 0);
20+
21+
//Assign Blink converter settings to HTML converter.
22+
htmlConverter.ConverterSettings = cefConverterSettings;
23+
24+
//Convert URL to PDF document.
25+
PdfDocument document = htmlConverter.Convert("https://www.google.com");
26+
27+
//Create memory stream.
28+
MemoryStream stream = new MemoryStream();
29+
30+
//Save and close the document.
31+
document.Save(stream);
32+
document.Close();
33+
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "HTML-to-PDF.pdf");
34+
}
35+
36+
private readonly ILogger<HomeController> _logger;
37+
38+
public HomeController(ILogger<HomeController> logger)
39+
{
40+
_logger = logger;
41+
}
42+
43+
public IActionResult Index()
44+
{
45+
return View();
46+
}
47+
48+
public IActionResult Privacy()
49+
{
50+
return View();
51+
}
52+
53+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
54+
public IActionResult Error()
55+
{
56+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
57+
}
58+
}
59+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
2+
3+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
4+
USER app
5+
WORKDIR /app
6+
EXPOSE 8080
7+
EXPOSE 8081
8+
9+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
10+
ARG BUILD_CONFIGURATION=Release
11+
WORKDIR /src
12+
COPY ["HTML-to-PDF-Azure-app-service/HTML-to-PDF-Azure-app-service.csproj", "HTML-to-PDF-Azure-app-service/"]
13+
RUN dotnet restore "./HTML-to-PDF-Azure-app-service/./HTML-to-PDF-Azure-app-service.csproj"
14+
COPY . .
15+
WORKDIR "/src/HTML-to-PDF-Azure-app-service"
16+
RUN dotnet build "./HTML-to-PDF-Azure-app-service.csproj" -c $BUILD_CONFIGURATION -o /app/build
17+
18+
FROM build AS publish
19+
ARG BUILD_CONFIGURATION=Release
20+
RUN dotnet publish "./HTML-to-PDF-Azure-app-service.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
21+
22+
FROM base AS final
23+
WORKDIR /app
24+
COPY --from=publish /app/publish .
25+
ENTRYPOINT ["dotnet", "HTML-to-PDF-Azure-app-service.dll"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>HTML_to_PDF_Azure_app_service</RootNamespace>
8+
<UserSecretsId>cd2b32c3-7a82-480c-af0c-685f8f419292</UserSecretsId>
9+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
14+
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Cef.Net.Windows" Version="26.1.35" />
15+
</ItemGroup>
16+
17+
</Project>
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>Docker</ActiveDebugProfile>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace HTML_to_PDF_Azure_app_service.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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"profiles": {
3+
"http": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNETCORE_ENVIRONMENT": "Development"
8+
},
9+
"dotnetRunMessages": true,
10+
"applicationUrl": "http://localhost:5299"
11+
},
12+
"https": {
13+
"commandName": "Project",
14+
"launchBrowser": true,
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
},
18+
"dotnetRunMessages": true,
19+
"applicationUrl": "https://localhost:7046;http://localhost:5299"
20+
},
21+
"IIS Express": {
22+
"commandName": "IISExpress",
23+
"launchBrowser": true,
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
}
27+
},
28+
"Docker": {
29+
"commandName": "Docker",
30+
"launchBrowser": true,
31+
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
32+
"environmentVariables": {
33+
"ASPNETCORE_HTTPS_PORTS": "8081",
34+
"ASPNETCORE_HTTP_PORTS": "8080"
35+
},
36+
"publishAllPorts": true,
37+
"useSSL": true
38+
}
39+
},
40+
"$schema": "http://json.schemastore.org/launchsettings.json",
41+
"iisSettings": {
42+
"windowsAuthentication": false,
43+
"anonymousAuthentication": true,
44+
"iisExpress": {
45+
"applicationUrl": "http://localhost:45582",
46+
"sslPort": 44341
47+
}
48+
}
49+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@{
2+
Html.BeginForm("ExportToPDF", "Home", FormMethod.Get);
3+
{
4+
<div>
5+
<input type="submit" value="Export To PDF" style="width:200px;height:27px" />
6+
</div>
7+
}
8+
Html.EndForm();
9+
}
10+

0 commit comments

Comments
 (0)