diff --git a/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Input.pdf b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Input.pdf new file mode 100644 index 00000000..d635b9f7 Binary files /dev/null and b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Input.pdf differ diff --git a/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker.sln b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker.sln new file mode 100644 index 00000000..2c352568 --- /dev/null +++ b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29025.244 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Linux-Based-PDF-Compression-Using-Docker", "Linux-Based-PDF-Compression-Using-Docker\Linux-Based-PDF-Compression-Using-Docker.csproj", "{8E602293-DA16-41FE-AB74-00AAD6C496B6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8E602293-DA16-41FE-AB74-00AAD6C496B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E602293-DA16-41FE-AB74-00AAD6C496B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E602293-DA16-41FE-AB74-00AAD6C496B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E602293-DA16-41FE-AB74-00AAD6C496B6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2B291216-3FD5-4017-BFA8-874021F734CF} + EndGlobalSection +EndGlobal diff --git a/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Dockerfile b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Dockerfile new file mode 100644 index 00000000..8acb1811 --- /dev/null +++ b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Dockerfile @@ -0,0 +1,36 @@ +# 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 mcr.microsoft.com/dotnet/runtime:9.0 AS base +RUN mkdir -p /app/input +RUN apt-get update && \ + apt-get install -y libfontconfig1 && \ + rm -rf /var/lib/apt/lists/* +COPY "jQuery_Succinctly.pdf" /app/input/ +RUN chmod -R 755 /app/input/ +USER $APP_UID +WORKDIR /app + +#docker cp "jQuery_Succinctly.pdf" + + +# This stage is used to build the service project +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["PDFCompression/PDFCompression.csproj", "PDFCompression/"] +RUN dotnet restore "./PDFCompression/PDFCompression.csproj" +COPY . . +WORKDIR "/src/PDFCompression" +RUN dotnet build "./PDFCompression.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 "./PDFCompression.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", "PDFCompression.dll"] \ No newline at end of file diff --git a/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Linux-Based-PDF-Compression-Using-Docker.csproj b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Linux-Based-PDF-Compression-Using-Docker.csproj new file mode 100644 index 00000000..7743867a --- /dev/null +++ b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Linux-Based-PDF-Compression-Using-Docker.csproj @@ -0,0 +1,32 @@ + + + + Exe + net8.0 + b67e9578-acf6-4e63-bb4a-4f5359ec7803 + Linux + + + + + + + + + + + + + + + PreserveNewest + + + + + + Always + + + + diff --git a/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Linux-Based-PDF-Compression-Using-Docker.csproj.user b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Linux-Based-PDF-Compression-Using-Docker.csproj.user new file mode 100644 index 00000000..99a3c455 --- /dev/null +++ b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Linux-Based-PDF-Compression-Using-Docker.csproj.user @@ -0,0 +1,9 @@ + + + + ProjectDebugger + + + Container (Dockerfile) + + \ No newline at end of file diff --git a/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Program.cs b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Program.cs new file mode 100644 index 00000000..dfe0cf6e --- /dev/null +++ b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Program.cs @@ -0,0 +1,60 @@ +using System; +using System.Diagnostics; +using System.IO; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf; + +namespace PDFCompression; + +public class Program +{ + public static void Main(string[] args) + { + CompressPdf(); + } + + public static void CompressPdf() + { + string path = Path.GetFullPath(@"Input.pdf"); + Console.WriteLine($"'{path}' pdf compression started."); + + Stopwatch stopwatch = Stopwatch.StartNew(); + FileStream inputDocument = new FileStream(path, FileMode.Open, FileAccess.Read); + Console.WriteLine($"Original file size: {inputDocument.Length:N0}"); + + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputDocument); + + // Create a new compression option. + PdfCompressionOptions options = new PdfCompressionOptions + { + // Enable image compression. + CompressImages = true, + // Set the image quality. + ImageQuality = 30, + // Optimize fonts in the PDF document. + OptimizeFont = true, + // Optimize page contents. + OptimizePageContents = true, + // Remove metadata from the PDF document. + RemoveMetadata = true + }; + + // Compress the PDF document. + loadedDocument.Compress(options); + + // Save the PDF document. + MemoryStream outputDocument = new MemoryStream(); + + // Save the PDF document to memory stream. + loadedDocument.Save(outputDocument); + + stopwatch.Stop(); + Console.WriteLine($"Compressed file size: {outputDocument.Length:N0}"); + Console.WriteLine($"Time elapsed: {stopwatch.Elapsed}"); + + // Clean up resources. + outputDocument.Close(); + loadedDocument.Close(true); + inputDocument.Close(); + } +} \ No newline at end of file diff --git a/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Properties/launchSettings.json b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Properties/launchSettings.json new file mode 100644 index 00000000..e04a1c98 --- /dev/null +++ b/Compression/Linux-Based-PDF-Compression-Using-Docker/.NET/Linux-Based-PDF-Compression-Using-Docker/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "PDFCompression": { + "commandName": "Project" + }, + "Container (Dockerfile)": { + "commandName": "Docker" + } + } +} \ No newline at end of file