Skip to content

Commit aec962b

Browse files
committed
Uploading the project to the repository
1 parent 1c76be7 commit aec962b

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

+39860
-0
lines changed

.dockerignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
**/.dockerignore
2+
**/.env
3+
**/.git
4+
**/.gitignore
5+
**/.vs
6+
**/.vscode
7+
**/*.*proj.user
8+
**/azds.yaml
9+
**/charts
10+
**/bin
11+
**/obj
12+
**/Dockerfile
13+
**/Dockerfile.develop
14+
**/docker-compose.yml
15+
**/docker-compose.*.yml
16+
**/*.dbmdl
17+
**/*.jfm
18+
**/secrets.dev.yaml
19+
**/values.dev.yaml
20+
**/.toolstarget

PDFCompression.sln

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 16
4+
VisualStudioVersion = 16.0.29025.244
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFCompression", "PDFCompression\PDFCompression.csproj", "{8E602293-DA16-41FE-AB74-00AAD6C496B6}"
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+
{8E602293-DA16-41FE-AB74-00AAD6C496B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8E602293-DA16-41FE-AB74-00AAD6C496B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8E602293-DA16-41FE-AB74-00AAD6C496B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8E602293-DA16-41FE-AB74-00AAD6C496B6}.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 = {2B291216-3FD5-4017-BFA8-874021F734CF}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+

2+
using System.Diagnostics;
3+
using System.IO;
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Mvc;
6+
using PDFCompression.Models;
7+
using Syncfusion.Pdf;
8+
using Syncfusion.Pdf.Parsing;
9+
10+
namespace PDFCompression.Controllers
11+
{
12+
public class HomeController : Controller
13+
{
14+
private readonly IWebHostEnvironment _hostingEnvironment;
15+
16+
public HomeController(IWebHostEnvironment hostingEnvironment)
17+
{
18+
_hostingEnvironment = hostingEnvironment;
19+
}
20+
21+
public IActionResult Index()
22+
{
23+
return View();
24+
}
25+
26+
public IActionResult Privacy()
27+
{
28+
return View();
29+
}
30+
31+
32+
public IActionResult CompressPDF()
33+
{
34+
string path = Path.Combine(_hostingEnvironment.ContentRootPath, "Data", "PDF_succinctly.pdf");
35+
36+
FileStream inputDocument = new FileStream(path, FileMode.Open);
37+
38+
//Load an existing PDF document
39+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputDocument);
40+
41+
//Create a new compression option.
42+
PdfCompressionOptions options = new PdfCompressionOptions();
43+
44+
//Enable the compress image.
45+
options.CompressImages = true;
46+
47+
//Set the image quality.
48+
options.ImageQuality = 30;
49+
50+
//Optimize the font in the PDF document
51+
options.OptimizeFont = true;
52+
53+
//Optimize page contents
54+
options.OptimizePageContents = true;
55+
56+
//Remove metadata from the PDF document
57+
options.RemoveMetadata = true;
58+
59+
//Flatted form fields in the PDF document
60+
if (loadedDocument.Form != null)
61+
loadedDocument.Form.Flatten = true;
62+
63+
//Flatten all the annotation in PDF document
64+
foreach (PdfPageBase page in loadedDocument.Pages)
65+
{
66+
if (page.Annotations != null)
67+
page.Annotations.Flatten = true;
68+
}
69+
70+
//Assign the compression option and compress the PDF document
71+
loadedDocument.Compress(options);
72+
73+
//Save the PDF document.
74+
MemoryStream outputDocument = new MemoryStream();
75+
76+
//Save the PDF document
77+
loadedDocument.Save(outputDocument);
78+
outputDocument.Position = 0;
79+
80+
//Close the document
81+
loadedDocument.Close(true);
82+
83+
84+
//Download the PDF document in the browser.
85+
FileStreamResult fileStreamResult = new FileStreamResult(outputDocument, "application/pdf");
86+
fileStreamResult.FileDownloadName = "Compressed_PDF_document.pdf";
87+
88+
return fileStreamResult;
89+
}
90+
91+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
92+
public IActionResult Error()
93+
{
94+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
95+
}
96+
}
97+
}
467 KB
Binary file not shown.

PDFCompression/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
2+
WORKDIR /app
3+
EXPOSE 80
4+
EXPOSE 443
5+
6+
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
7+
WORKDIR /src
8+
COPY ["PDFCompression/PDFCompression.csproj", "PDFCompression/"]
9+
RUN dotnet restore "PDFCompression/PDFCompression.csproj"
10+
COPY . .
11+
WORKDIR "/src/PDFCompression"
12+
RUN dotnet build "PDFCompression.csproj" -c Release -o /app
13+
14+
FROM build AS publish
15+
RUN dotnet publish "PDFCompression.csproj" -c Release -o /app
16+
17+
FROM base AS final
18+
WORKDIR /app
19+
COPY --from=publish /app .
20+
ENTRYPOINT ["dotnet", "PDFCompression.dll"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace PDFCompression.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<UserSecretsId>b67e9578-acf6-4e63-bb4a-4f5359ec7803</UserSecretsId>
6+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.9" />
11+
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="18.2.0.44" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<None Update="Data\PDF_succinctly.pdf">
16+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17+
</None>
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
5+
</PropertyGroup>
6+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
7+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
8+
</PropertyGroup>
9+
</Project>

PDFCompression/Program.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace PDFCompression
11+
{
12+
public class Program
13+
{
14+
public static void Main(string[] args)
15+
{
16+
CreateHostBuilder(args).Build().Run();
17+
}
18+
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.ConfigureWebHostDefaults(webBuilder =>
22+
{
23+
webBuilder.UseStartup<Startup>();
24+
});
25+
}
26+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:60601",
7+
"sslPort": 44347
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"PDFCompression": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
25+
},
26+
"Docker": {
27+
"commandName": "Docker",
28+
"launchBrowser": true,
29+
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
30+
"environmentVariables": {
31+
"ASPNETCORE_URLS": "https://+:443;http://+:80",
32+
"ASPNETCORE_HTTPS_PORT": "44348"
33+
},
34+
"httpPort": 60602,
35+
"useSSL": true,
36+
"sslPort": 44348
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)