diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/.dockerignore b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Controllers/PdfController.cs b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Controllers/PdfController.cs new file mode 100644 index 0000000..729422f --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Controllers/PdfController.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Syncfusion.HtmlConverter; +using Syncfusion.Drawing; +using Syncfusion.Pdf; + +namespace HTMLtoPDF_Wolfi_Docker.Controllers +{ + [Route("[controller]")] + [ApiController] + public class PdfController : ControllerBase + { + + public IActionResult ConvertPDF() + { + try + { + //Initialize the HTML to PDF converter. + HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + + BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); + blinkConverterSettings.CommandLineArguments.Add("--disable-gpu"); + blinkConverterSettings.BlinkPath = "/usr/lib/chromium"; + //Assign Blink converter settings to HTML converter + htmlConverter.ConverterSettings = blinkConverterSettings; + + //Convert URL to PDF + PdfDocument document = htmlConverter.Convert("https://www.google.com"); + MemoryStream fileStream = new MemoryStream(); + //Save and close the PDF document. + document.Save(fileStream); + document.Close(true); + fileStream.Position = 0; + return new FileStreamResult(fileStream, "application/pdf") {FileDownloadName="HtmlToPdf_Output.pdf" }; + } + catch (Exception ex) + { + return Content(ex.Message.ToString()); + } + } + } +} diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Controllers/WeatherForecastController.cs b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..db3c062 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace HTMLtoPDF_Wolfi_Docker.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Dockerfile b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Dockerfile new file mode 100644 index 0000000..af1eeda --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Dockerfile @@ -0,0 +1,37 @@ +# 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. + +# This stage is used when running from VS in fast mode (Default for Debug configuration) +FROM cgr.dev/chainguard/aspnet-runtime:latest-dev AS base +USER root + +RUN apk update && \ + apk upgrade && \ + apk add --update ca-certificates && \ + apk add chromium --update-cache --repository http://nl.alpinelinux.org/alpine/edge/community \ + rm -rf /var/cache/apk/* +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + + +# This stage is used to build the service project +FROM cgr.dev/chainguard/dotnet-sdk:latest-dev AS build +USER root +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["HTMLtoPDF_Wolfi_Docker.csproj", "."] +RUN dotnet restore "./HTMLtoPDF_Wolfi_Docker.csproj" +COPY . . +WORKDIR "/src/." +RUN dotnet build "./HTMLtoPDF_Wolfi_Docker.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# This stage is used to publish the service project to be copied to the final stage +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./HTMLtoPDF_Wolfi_Docker.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "HTMLtoPDF_Wolfi_Docker.dll"] \ No newline at end of file diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.csproj b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.csproj new file mode 100644 index 0000000..4f13220 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.csproj @@ -0,0 +1,17 @@ + + + + net9.0 + enable + enable + 1f4eb02c-222e-412a-8b02-7b438a5b3550 + Linux + . + + + + + + + + diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.csproj.user b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.csproj.user new file mode 100644 index 0000000..999c9d8 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.csproj.user @@ -0,0 +1,8 @@ + + + + Container (Dockerfile) + ApiControllerEmptyScaffolder + root/Common/Api + + \ No newline at end of file diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.http b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.http new file mode 100644 index 0000000..bb54bc7 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.http @@ -0,0 +1,6 @@ +@HTMLtoPDF_Wolfi_Docker_HostAddress = http://localhost:5235 + +GET {{HTMLtoPDF_Wolfi_Docker_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.sln b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.sln new file mode 100644 index 0000000..22a7337 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36429.23 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTMLtoPDF_Wolfi_Docker", "HTMLtoPDF_Wolfi_Docker.csproj", "{F9F4204B-A007-4790-BA53-4E96F3B241C3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F9F4204B-A007-4790-BA53-4E96F3B241C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F9F4204B-A007-4790-BA53-4E96F3B241C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F9F4204B-A007-4790-BA53-4E96F3B241C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F9F4204B-A007-4790-BA53-4E96F3B241C3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {46981BBE-DD89-4B09-BC15-F2D0F6065DFA} + EndGlobalSection +EndGlobal diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Program.cs b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Program.cs new file mode 100644 index 0000000..de2e6b8 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Program.cs @@ -0,0 +1,27 @@ +namespace HTMLtoPDF_Wolfi_Docker +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + + builder.Services.AddControllers(); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + + app.UseHttpsRedirection(); + + app.UseAuthorization(); + + + app.MapControllers(); + + app.Run(); + } + } +} diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Properties/launchSettings.json b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Properties/launchSettings.json new file mode 100644 index 0000000..df030c3 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5235" + }, + "https": { + "commandName": "Project", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7267;http://localhost:5235" + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "environmentVariables": { + "ASPNETCORE_HTTPS_PORTS": "8081", + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json" +} \ No newline at end of file diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/WeatherForecast.cs b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/WeatherForecast.cs new file mode 100644 index 0000000..18e9e56 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace HTMLtoPDF_Wolfi_Docker +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/appsettings.Development.json b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/appsettings.json b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/deployment.yaml b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/deployment.yaml new file mode 100644 index 0000000..03c1020 --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: clusterhtml-deployment +spec: + replicas: 2 # Adjust the number of replicas if needed + selector: + matchLabels: + app: clusterhtml-api + template: + metadata: + labels: + app: clusterhtml-api + spec: + containers: + - name: clusterhtml-api + image: karmegamsf3701120/htmltopdfconversion:v4 + ports: + - containerPort: 8080 \ No newline at end of file diff --git a/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/service.yaml b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/service.yaml new file mode 100644 index 0000000..60d9b3c --- /dev/null +++ b/Wolfi_Linux/HTMLtoPDF_Wolfi_Docker/HTMLtoPDF_Wolfi_Docker/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: clusterhtml-service +spec: + selector: + app: clusterhtml-api + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + type: LoadBalancer \ No newline at end of file