Dear,
we are converting PDF documents to JPEG files using .NET Core 3.1. There seems to be a memory leak in the JPegDevice.Process() step.
This is the code used:
using (Stream stream = new MemoryStream(document.FileContent))
{
using (Document pdfDocument = new Document(stream))
{
pdfDocument.EnableObjectUnload = true;
// Bind input pdf file
pdfDocument.OptimizeResources(new Aspose.Pdf.Optimization.OptimizationOptions()
{
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
RemoveUnusedStreams = true
});
Resolution resolution = new Resolution(100);
// Create Jpeg device with specified attributes
// Width, Height, Resolution
JpegDevice JpegDevice = new JpegDevice(420, 594, resolution, 100);
JpegDevice.RenderingOptions.UseNewImagingEngine = true;
int imgNumber = 0;
foreach (Page page in pdfDocument.Pages)
{
using (MemoryStream memoryStream = new MemoryStream())
{
JpegDevice.Process(page, memoryStream);
await UploadImagesToBlob(document, memoryStream, imgNumber++.ToString() + ".jpg");
}
page.Dispose();
}
pdfDocument.FreeMemory();
}
This is our dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-focal AS base
WORKDIR /app
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN \
sed -i -e's/ main/ main contrib non-free/g' /etc/apt/sources.list \
&& apt-get -q update \
&& apt-get install -y --quiet ttf-mscorefonts-installer libfontconfig1 libgdiplus
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-focal AS build
WORKDIR /src
COPY ["***.csproj", "***/"]
RUN dotnet restore "***.csproj"
COPY . .
WORKDIR "***"
RUN dotnet build "***" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "***.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "***.dll"]
We are using Aspose.PDF version 21.6.0.
Regards