Free Support Forum - aspose.com

Problem with adding an image using PdfFileMend and .AddImage

here is my code to place a basic image on a pdf:



PdfFileMend mendor;
mendor = new PdfFileMend(“bpmpe004.pdf”, “new.pdf”);
mendor.AddImage(“TOLOGO.jpg”, 1, 116, 707, 299, 759);
mendor.Close();


Here is the overload I am using:
public bool AddImage(string imageName, int pageNum, float lowerLeftX, float lowerLeftY, float upperRightX, float upperRightY);


It seems no matter what I put for the upperRightX or upperRightY , it does not change anything. Only the lowerLeftX and lowerLeftY really affect the placement of the image.

I’ve run many tests other than the above code.

This was working fine in version 3.5.0, but I had to upgrade to 4.1.0 after I bought a license.

After some more testing, I was able to get the Licensing and AddImage to work with version 3.8.0.1, but AddImage does not work on subsequent versions.


Also after 3.8.0.1 using streams with AddImage does not work either:

using (FileStream inImgStream = new FileStream(TOLOGO.jpg”, FileMode.Open))
{
PdfFileMend mendor;
mendor = new PdfFileMend(“bpmpe004.pdf”, “new.pdf”);
mendor.AddImage(inImgStream, 1, 116, 707, 299, 759);
mendor.Close();
inImgStream.Close();
}

If you run this you get the:
Object reference not set to an instance of an object”

Hi Zen,

I have tested these problems at my end and reproduced both of these issues. These issues have been logged in our issue tracking system as under:

PDFKITNET-14635 - Image is not placed properly
PDFKITNET-14637 - Problem adding image from a Stream

Our team will look into these issues and you’ll be updated via this forum thread once the issues are resolved.

We’re sorry for the inconvenience.
Regards,



The issues you have found earlier (filed as 14635;14637) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi Shahzad,


We just tried updating the aspose.pdf.kit from 4.0.0 to 4.2.0.
After testing we notice the above error, when adding a .png image from a MemoryStream.

When modifying our code to the above sample we keep getting a System.ArgumentException with the message: ‘Parameter is not valid.’. (also on the Stream, int, float, float, float, float overload)
Our code was confirmed to work in 3.5.0 and 4.0.0, after updating it throws the above exception.

It seems that PDFKITNET-14637 is not yet solved?
Can you confirm this error or maybe a solution this problem?


Sincerely,
Freddy

Hi Freddy,

I have tested this issue using Aspose.Pdf.Kit for .NET 4.2.0, MemoryStram and a PNG image, but I couldn’t see any problem. Can you please make sure that the reference to the latest DLL was added successfully? If you still find any problem then please share your sample files (PDF and PNG) along with the code snippet, so we would be able to test the issue using your particular scenario.

We’re sorry for the inconvenience.
Regards,

This is the code snippet we use:

This fails: (System.ArgumentException with message = 'Parameter is not valid.')

PdfFileInfo fileInfo = new PdfFileInfo(pdffile);
float height = fileInfo.GetPageHeight(pageIndex);
float width = fileInfo.GetPageWidth(pageIndex);

using (FileStream inImgStream = new FileStream("d:\\barcode.png", FileMode.Open))
{
PdfFileMend mendor = new PdfFileMend(pdffile, output);
mendor.AddImage(inImgStream, 1, 0, 0, width, height);
mendor.Close();
inImgStream.Close();
}

This works:
PdfFileMend mendor = new PdfFileMend(pdffile, output);
mendor.AddImage("d:\\barcode.png", 1, 0, 0, width, height);
mendor.Close();


(please note that with these files the transparency ends up as black in the output file.)


Sincerely,
Freddy

Hi Freddy,

I have reproduced this problem at my end and logged it as PDFKITNET-15314 in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,

The issues you have found earlier (filed as 15314) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hello,

It seems that the above fix breaks the transparent png functionality. (transparent png from stream into pdf) See the attached files (one made with 4.0.0 and one made with 4.3.0)

The 4.3.0 version gives black pages, the 4.0.0 works as it should.

We really need to get the latest version running because of the memory usage related errors in pre-4.2.0, but we keep running into problems. If we cannot get the problem fixed, we are forced by our customer to find a solution with other components..

Is it possible to do a quick-fix so we can start using the new version? (would within a few days be reasonable?)

Sincerely,
Fred

Hi Fred,

We’ll try to provide you a hotfix for this issue tomorrow.

We’re sorry for the inconvenience and appreciate your patience.
Regards,

Thank you, i hope this solves our problems.

Sincerely,
Fred

Hi Fred,

Please find a hotfix attached with this post.

I hope this helps. If you have any questions, please do let us know.
Regards,

The issues you have found earlier (filed as 15565) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.