aspose.PDF docker System.OutOfMemoryException

Hi,
I’m using Aspose.PDF with docker and kubernetes. While it is working, on my local computer, it is not working in the docker environment.

This is the exception that i get:

System.OutOfMemoryException: Out of memory.
at System.Drawing.Region.Intersect(Region region)
at #=zAbz9RfH2SqWs2D0By3_ulAH$y5Rpl5vjDg==.#=zyduQj_GSA8SN0BtI0FYGvUs=.#=z891Stee20i8G(#=zRjwBU9H_ZYXbZTMDnm9An_4= #=zrLhKiOUEHFER)
at #=zRjwBU9H_ZYXbZTMDnm9An_4=.#=zQ6etXjw=(#=zPRASOHbQKu0IuIBPFzk_qyV2frCT #=z9aVQwhs=)
at #=zJV6jc$5CJS7ZSHyBT79rxVooyOR5.#=zQ6etXjw=(#=zPRASOHbQKu0IuIBPFzk_qyV2frCT #=z9aVQwhs=)
at #=zRjwBU9H_ZYXbZTMDnm9An_4=.#=zQ6etXjw=(#=zPRASOHbQKu0IuIBPFzk_qyV2frCT #=z9aVQwhs=)
at #=zJV6jc$5CJS7ZSHyBT79rxVooyOR5.#=zQ6etXjw=(#=zPRASOHbQKu0IuIBPFzk_qyV2frCT #=z9aVQwhs=)
at #=zRjwBU9H_ZYXbZTMDnm9An_4=.#=zQ6etXjw=(#=zPRASOHbQKu0IuIBPFzk_qyV2frCT #=z9aVQwhs=)
at #=zJV6jc$5CJS7ZSHyBT79rxVooyOR5.#=zQ6etXjw=(#=zPRASOHbQKu0IuIBPFzk_qyV2frCT #=z9aVQwhs=)
at #=zPLrvCqICSRFOMDNtO2RE2x4=.#=zQ6etXjw=(#=zPRASOHbQKu0IuIBPFzk_qyV2frCT #=z9aVQwhs=)
at #=zJV6jc$5CJS7ZSHyBT79rxVooyOR5.#=zQ6etXjw=(#=zPRASOHbQKu0IuIBPFzk_qyV2frCT #=z9aVQwhs=)
at #=zHi1fNKl8qEOiZ0RtmJFP8PM=.#=zQ6etXjw=(#=zPRASOHbQKu0IuIBPFzk_qyV2frCT #=z9aVQwhs=)
at #=zAbz9RfH2SqWs2D0By3_ulAH$y5Rpl5vjDg==.#=z1SeRLN8=(#=zJV6jc$5CJS7ZSHyBT79rxVooyOR5 #=zZScjOFA=, Single #=zBwQ64FY5MFig, #=zX3RSFK_uU7DjJ2Ly0k3JkRlwAQzZQUbB6g== #=zb6ItOOA=, Boolean #=z$GOuVXTSLZ8q)
at #=zX3RSFK_uU7DjJ2Ly0k3JkRlwAQzZQUbB6g==.#=z5thh5fU4J$DgmrmFkg==(#=zr4DBeOUKqZshag1VaSDFmHY= #=zGcWEbHU=, Single #=zBwQ64FY5MFig, Single #=zt6cpAn4CniEY, #=zEESI_1VynEuVc4liysZtHJIzHMbT2MuFHp60QcY= #=zfVRNZzk=, Boolean #=z$xRO29NLmsi$_z7FmcE$gb9r30RsDax9AA==, Boolean #=zNK1WG3baeQ7FxV6PsA==, #=zX3RSFK_uU7DjJ2Ly0k3JkRlwAQzZQUbB6g== #=zb6ItOOA=)
at #=zX3RSFK_uU7DjJ2Ly0k3JkRlwAQzZQUbB6g==.#=z5thh5fU4J$DgmrmFkg==(#=zr4DBeOUKqZshag1VaSDFmHY= #=zGcWEbHU=, Single #=zBwQ64FY5MFig, Single #=zt6cpAn4CniEY, #=zX3RSFK_uU7DjJ2Ly0k3JkRlwAQzZQUbB6g== #=zb6ItOOA=)
at #=zX3RSFK_uU7DjJ2Ly0k3JkRlwAQzZQUbB6g==.#=z4KQ1rGdwcZoYxzo4GHnGCFs=(#=zr4DBeOUKqZshag1VaSDFmHY= #=zGcWEbHU=, SizeF #=zDWwlrj0=)
at #=zu86u54INMH$QE0XFmvQxDUunphaus$4oZjMkFoU=.#=zG1Xhb2g=(IList1 #=zwelGTHaK7fxI, #=zG3VbYvmSfA9a0dNpCKHhM2BROYaUjCwVqA== #=zgtIc6$M=, #=ziwcqKTXx0UCyUuoS_jLIsHlOLBbCBN85wbAAmRc= #=zRFkXoHU=) at #=zESdNBQwAZfZz2s$2xC7oKDeyARtW.#=zG1Xhb2g=(String #=zAQMWvQ0KaxJo, #=z2Iu2RoWHBIhfE8ATXWJC5u1Lm_NHlzQBQA== #=zRFkXoHU=, IList1 #=zwelGTHaK7fxI, #=zePNTpMFrnX0iLG3gJ3mFbobSktcXi1MNkOtFdDc= #=zOx33iu4=, #=zTWU6QJhDXWFK5t$pGLj45F6wVIx3 #=zOw86GLmfb1wp)
at #=zYm80fjiM9IPi7zPRSxzQc$I=.#=zT_QeTPQ=(Document #=zKuSjrQQ=, String #=zRGc1ZzfY3CuUwpT2vQ==, Stream #=z7B1CBbhpaww3, HtmlSaveOptions #=zRFkXoHU=)
at Aspose.Pdf.Document.#=zf69xgfS16u1o(String #=zAQMWvQ0KaxJo, SaveOptions #=zRFkXoHU=)
at Aspose.Pdf.Document.Save(String outputFileName, SaveOptions options)
at documents_ms.Controllers.AposePdfController.ConvertToHtml() in /app/Controllers/AposePdfController.cs:line 74
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at System.Threading.Tasks.ValueTask1.get_Result() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)

@asifefer

Would you kindly provide your docker environment details along with sample source PDF and complete sample code snippet. We will test the scenario in our environment and address it accordingly.

This is the problematic PDF:

failurepdf (2).pdf (84.3 KB)

And this is the docker file:


http://sendanywhe.re/487NLNLH


@asifefer

Would you please also share the code snippet that you are using. Please make sure to use latest version of the API as well before sharing the code snippet with us.

The code works for most of the PDF files. But for some of them i got this error message. So, this is the code snippet that i’m using. Pay attention that the function is getting the pdf as base64:

    [HttpPost]
    [Route("ConvertToHtml")]
    public async Task<ActionResult<object>> ConvertToHtml()
    {
        Console.WriteLine("****: Start PDF ConvertToHtml()");
        Stopwatch sw = new Stopwatch();
        sw.Start();

        string tmpFileDataBase64 = string.Empty;
        using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
        {
            tmpFileDataBase64 = await reader.ReadToEndAsync();
        }
        string fileDataBase64 = tmpFileDataBase64.Trim(new char[] {'\"'});

        byte[] fileData = Convert.FromBase64String(fileDataBase64);

        MemoryStream stream = new MemoryStream(fileData);
        var wrdf = new Aspose.Pdf.Document(stream);

        HtmlSaveOptions saveOptions = new HtmlSaveOptions(HtmlDocumentType.Html5);
        saveOptions.FixedLayout = false;
        saveOptions.HtmlMarkupGenerationMode = HtmlSaveOptions.HtmlMarkupGenerationModes.WriteAllHtml;
        saveOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.DontSave;
        saveOptions.SplitIntoPages = false;
        saveOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
        saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
        saveOptions.FlowLayoutParagraphFullWidth = true;
        saveOptions.LettersPositioningMethod = HtmlSaveOptions.LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
        saveOptions.RemoveEmptyAreasOnTopAndBottom = true;
        saveOptions.TryMergeAdjacentSameBackgroundImages = true;
        saveOptions.TrySaveTextUnderliningAndStrikeoutingInCss = true;
        saveOptions.CustomHtmlSavingStrategy = new HtmlSaveOptions.HtmlPageMarkupSavingStrategy(SavingToStream);

        saveOptions.AntialiasingProcessing = HtmlSaveOptions.AntialiasingProcessingType.TryCorrectResultHtml;
        saveOptions.DocumentType = HtmlDocumentType.Html5;

        using (MemoryStream htmlStream = new MemoryStream())
        {
            wrdf.Save(@"stam.html", saveOptions);
            stream.Close();
        }

        this.HtmlData = Regex.Replace(this.HtmlData, @"<img [\s\S]+? />", "");
        this.HtmlData = Regex.Replace(this.HtmlData, @"font-family:'[\s\S]+?';*", "font-family:'Ariel';");

        var response = new
        {
            statusCode = 200,
            data = this.HtmlData,
        };

        sw.Stop();
        Console.WriteLine("****: End DOCX ConvertToHtml(). Total Running Time = " + sw.ElapsedMilliseconds + " (milisec)");

        return Ok(response);
    }
    private void SavingToStream(HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlSavingInfo)
    {
        byte[] resultHtmlAsBytes = new byte[htmlSavingInfo.ContentStream.Length];
        htmlSavingInfo.ContentStream.Read(resultHtmlAsBytes, 0, resultHtmlAsBytes.Length);
        this.HtmlData = Encoding.UTF8.GetString(resultHtmlAsBytes);
    }

@asifefer

It seems like the issue is related to specific PDF document and we need to investigate it in details. We have logged an investigation ticket as PDFNET-48452 in our issue tracking system for the purpose. We will further look into its details and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hello,

Any news regarding the bug with the PDF?

Thanks,
Asi.

@asifefer

We are afraid that earlier logged ticket is not yet resolved. Please note that it was logged under free support model and will be investigated/resolved on first come first serve basis. We will surely inform you as soon as we have some certain news about its rectification. Please give us some time.

We are sorry for the inconvenience.