I am converting images to PDFs. When using specific settings, like a 2cm Margin this causes the call of Aspose.PDF.Document.Save or Aspose.PDF.Document.ProcessParagraphs to process infinitely, until the program crashes when running out of memory. This is the simplest code example where the error occurs:
using Aspose.Pdf;
using System.Reflection;
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
const double POINTS_PER_CENTIMETER = 28.3465;
var margins = 2 * POINTS_PER_CENTIMETER;
var document = new Document();
var page = document.Pages.Add();
page.PageInfo.Margin = new MarginInfo(
margins,
margins,
margins,
margins
);
var image = new Image
{
ImageStream = File.OpenRead(Path.Combine(directory, "test.png")),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
var width = image.BitmapSize.Width;
var height = image.BitmapSize.Height;
page.SetPageSize(width + 2 * margins, height + 2 * margins);
page.Paragraphs.Add(image);
document.Save(Path.Combine(directory, "test.pdf"));
I am pretty sure this happens due to the margins and irrespective of the used image. Setting POINTS_PER_CENTIMETER to 25, for example, does not cause the problem. I am relying on this precision, however, to get proper DIN A4 page sizes.
Well this is not an issue for me, adding a point tolerance to the margins makes the issue not occur. I simply wanted to report the issue.