Save a small jpg file to PDF consuming tons of memory

Hi Aspose support, having an issue with convert a small (10kb) jpg file (attached) to save as PDF, it is consuming tons of memory.

Is there a known issue?

Here is the code, memory issue occurred on the Save:

   Public Shared Sub ConvertToPdf(inputStream As Stream, outputStream As Stream, type As String)
        Dim pdfDoc As New Aspose.Pdf.Document()
        Dim page As Aspose.Pdf.Page = pdfDoc.Pages.Add()
        Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(inputStream)

        'Create an image object in the section
        Dim image1 As Aspose.Pdf.Image = New Aspose.Pdf.Image()

        'Set margins so image will fit, etc.
        page.PageInfo.Width = image.Width + 100
        page.PageInfo.Height = image.Height + 100

        'Add image object into the Paragraphs collection of the section
        page.Paragraphs.Add(image1)
        image1.ImageStream = inputStream

        'Save the Pdf
        **pdfDoc.Save(outputStream)**
    End Sub

Thanks
steing.jpg (7.7 KB)

@jcsupport88,

I am not part of the dev team but from the support team but I havent hear of any issues with that.

Also, what is a lot of memory? which line in particular? or is a disposing of memory objects the problems?

Hi Carlos,

Thanks for the response.

Attached is a zipped IISMemory.zip (5.7 MB)
recording of the issue that my client shared with us, but I am seeing the same issue on my computer as well.

I traced the issue to the call to save: pdfDoc.Save(outputStream), memory just spikes and seems to just hang.

@jcsupport88,

The video is very clear about how much memory is consumed. But if I submit a ticket, I will be asked what other code is triggered besides the one in the snippet.

Anything else, you want to add before I create a ticket?

There are other codes in the application before getting to the ConvertToPdf, but none of them affected memory usage. Attached a sample of much larger image file (21MB) that has no issue, here is the link:

Please go ahead and submit a ticket.

Thanks

@jcsupport88,

Thanks again for all the help you have provided. I need a bit of extra information.

Can you tell us which version of the API you are using?

We required the information from the machine where this happens, but in your video, you provided all this information already(that is helpful)

we are using of version 20.4 of Aspose.PDF.dll

@jcsupport88,

That version is three years old. Can you do the same test using the latest API version?

You can request a trial version for free here: Temporary License - Purchase - aspose.com

Do I need to get new license file?

@jcsupport88,

If your current license allows you to use the latest version, 23.4, then no. I just want you to try to replicate this issue with the newest code,

I am not the person involved with keeping track of the license, but since we are using 20.4, I assume we can’t use 23.4. Basically I am getting an error when using using the SetLicense method with our existing license file.

@jcsupport88,

That it is why it is important to see if the issue has been solved already.

Fixed are not implemented in old code, only in the current version.

I was not able to replicate the issue like the one you showed in your machine. But if the video recorded is from code that is using the latest API version, I can submit that.

Otherwise it will be a waste of time for you because the first response will be to update to the latest API.

EDIT: Also, keep in mind you can use that you can use the code without a valid license, but it will inject some stamps that will take even more memory and time, so for the purpose of this analisys is not the optimal path to follow.

Remember that the code you are using is behind multiple minor releases and 3 major ones.

I was able to use the latest version now, but now it returns an error “Page have not room to place a paragraphs” saving the small image file. Attached are links to the saved PDF for the much larger file I shared earlier:
20.4:

23.4

Hi @carlos.molina any feedback on the error when using the latest version?

Thanks

@jcsupport88,

EDIT:

Can you remove this lines from your coded?

page.PageInfo.Width = image.Width + 100
page.PageInfo.Height = image.Height + 100

I tried without those lines and it works fine

Thanks.

Removing the 2 lines of code works, even with version 20.4, but we had those 2 lines of codes for a long time and it only encounter the issue with this particular images. Will your developer be able to determine the actual cause?

Is there issue with the width to height ratio of the image file. I took a HD (6110x3680) photo, NGTAPRIL16_NB23.jpg that I shared in the earlier thread and cropped it to 456x42 (see attached) NGTAPRIL16_NB23-Edited.jpg (7.1 KB)
and it has the same memory issue.

Simple test with images created from Paint:
455x41.jpg (1.3 KB)
500x50.jpg (3.7 KB)
455x41 has issue, 500x50 works fine.

@jcsupport88,

With what version of the API are you seen this? I used both and I do not see the memory problem.

Sorry for delayed response, have been tied up with other works. Were your tests with or without the following lines?

page.PageInfo.Width = image.Width + 100
page.PageInfo.Height = image.Height + 100