Cannot allocate so many bytes. Use LoadPartialPixels instead

Hi,
I am trying to convert image into pdf but it is throwing an exception - “Cannot allocate so many bytes. Use LoadPartialPixels instead.”

  int height = 200;
  int width = 200;
  string filePath = @"C:\2023-07-12117A-ED_F1_specs_postprocessed.jpg";
  string pdfFile = @"C:\2023-07-12117A-ED_F1_specs_postprocessed.pdf";
  
  using (var img = Aspose.Imaging.Image.Load(filePath))
  {
    height += img.Height;
    width += img.Width;
  }

  var pdf = new Document();
  var pdfImageSection = pdf.Pages.Add();
  pdfImageSection.PageInfo.Width = width;
  pdfImageSection.PageInfo.Height = height;
  pdfImageSection.PageInfo.Margin.Bottom = 50;
  pdfImageSection.PageInfo.Margin.Top = 50;
  pdfImageSection.PageInfo.Margin.Right = 50;
  pdfImageSection.PageInfo.Margin.Left = 50;

  FileStream stream = new FileStream(filePath, FileMode.Open);
  var image = new Image { ImageStream = stream };

  pdfImageSection.Paragraphs.Add(image);

  pdf.Save(pdfFile);

Aspose versions -

  • Aspose.PDF (23.4.0)
  • Aspose Imaging (23.3.0)

@amolm

While testing the scenario using 23.10 version of the API, we could not notice such an exception. Can you please try to test with the latest version and let us know in case you still notice any issues.

Hi @asad.ali
Thanks for quick response.

There is no issue while executing on windows, but its on linux environment. Can you please check.

Thanks,

@amolm

Can you please try using Aspose.Pdf.Drawing instead of Aspose.PDF for .NET? Please uninstall existing Aspose.PDF package from your project and install Aspose.Pdf.Drawing instead from NuGet Package Manager. You would not need to change anything in the code. If issue still persists, please share complete environment details with us. We will log an investigation ticket and share the ID with you.

Hi @asad.ali

I tried with Aspose.Pdf.Drawing (23.4.0) instead of Apose.Pdf, but still facing same issue. Below are the environment details -

Stack - cflinuxfs4
Version - Ubuntu 22.04

Thanks,

@amolm

We request you please try the latest available version. In case your license is not valid for the latest version, please obtain a temporary license which will allow you to use the latest version and evaluate it. We will continue logging the ticket in case issue still happens with the latest version. We are sorry for the trouble.

Hi @asad.ali

I tried with Aspose.Pdf.Drawing (23.10.1) with latest version, but still facing same issue.

@amolm

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-55876

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thank you @asad.ali