Free Support Forum -

pdfFileMend addImage coordinates


While trying to get a simple file to generate to the pdf I keep on getting a file Overflow or underflow in the arithmetic operation exception.

Here is the code…

Image myImage = ImageUtils.ScaledSize(bitmap, (int)PDFFingerWidth, (int)PDFFingerHeight);

//Create the streams of input and output PDF files

FileStream inPdfStream = null;

FileStream outputStream = null;

// utility to create read the input and create the output.
FileStreamCreate(out inPdfStream, out outputStream);

if (inPdfStream == null || outputStream == null)

Assert.Fail(“input and output streams still null”);
inPdfStream.Seek(0, SeekOrigin.Begin);

//Instantiate PdfFileMendor object and pass input and output PDF file streams to its constructor
PdfFileMend mendor = new PdfFileMend(inPdfStream, outputStream);

if (mendor == null)
Assert.Fail(“could not create mendor class”);

//Call AddImage method and pass image, page number and (X,Y) axis information

MemoryStream ms = new MemoryStream();
myImage.Save(ms, ImageFormat.Jpeg);
ms.Position = 0;

log.Info(String.Format(“MyImage width {0} height {1}”, myImage.Width, myImage.Height));
Single upperLeftX = 5;
Single upperLeftY = 400;

Single lowerLeftX = 20;
Single lowerLeftY = 200 + PDFFingerHeight + 10;

Single upperRightX = upperLeftX + myImage.Width;
Single upperRightY = lowerLeftY + myImage.Height;

log.Info(String.Format(“Coordinates lowerLeft X {0} UpperRight X {1}”, lowerLeftX, upperRightX));
log.Info(String.Format(“Coordinates lowerLeft Y {0} UpperRight Y {1}”, lowerLeftY, upperRightY));

log.Info(String.Format(“actual params {0} {1} {2} {3}”, lowerLeftX, lowerLeftY, upperRightX, upperRightY));

mendor.AddImage(ms, 1, (float)lowerLeftX, (float)lowerLeftY, (float)upperRightX, (float)upperRightY);

catch(Exception ex)
log.Error("exception was thrown " + ex);

//Close PdfFileMendor object


Hi Andrew,

Thank you very much for considering Aspose.

Please share the PDF file with us, so we could look into the issue in detail at our end and update your accordingly.

We’re looking forward to help you out.

Sent you the pdf form. Please let me know if you need anything else.

Hi Andrew,

I have tested the issue at my end with the file you shared and successfully added image to the PDF file. I have tested the issue with Aspose.Pdf.Kit for .NET 3.7. Please download the latest release and try at your end.

If problem persists then please share a sample project as well. As you are using some custom code to calculate the coordinates and load images, so the sample project will help us understand the cause of this issue.

We’re sorry for the inconvenience.