I’m trying to replace an image in a PDF document with an image that has a higher resolution. To do so I use the ImagePlacementAbsorber and with it the Replace method of the resulting ImagePlacement object.
My code for retrieving and replacing the current logo looks like this:
ImagePlacementAbsorber imagePlacementAbsorber = new ImagePlacementAbsorber();
document.Pages.Accept(imagePlacementAbsorber);
using (FileStream fs = new FileStream(logoPath, FileMode.Open)) {
imagePlacementAbsorber.ImagePlacements.ToList().ForEach(ip => {
ip.Replace(fs);
});
}
The problem is that in certain cases the replacement image I use doesn’t get displayed correctly in the resulting PDF document. I’ve tried different replacement images. Some of them are displayed correctly, whereas others don’t.
Original PDF document: withHblLogo.pdf (48.6 KB)
Logo contained in the above document which needs to be replaced: img0.jpg (5.4 KB)
I’ve used different image types (bmp, png, jpg) with different sizes and/or resolutions. Some of them get resized and displayed correctly, others don’t. I cannot find out what causes the error.
I checked it on current version which is 24.10, seems that issue was resolved at some point
so you can try to update version and see if issue still present with other files
Thanks for the hint. Due to our subscription that ran out, I was only able to renew to Aspose.PDF 24.8.0, which however correctly renders most of the logos I’ve been testing with.
The only file formats that resulted in unexpected behaviour were EPS and SVG images. It looks like EPS is not supported at all, since I got the following error:
System.ArgumentException: ‘Invalid image stream (Unable to cast object of type
Aspose.Imaging.FileFormats.Eps.EpsImage’ to type ‘Aspose.Imaging.FileFormats.Svg.SvgImage’.)’
Using the following SVG image data I got a black background (even though I cannot see black background within the SVG data). I guess Aspose is generating the black background rectangle, right?
@marc.jansen.finstar.ch
I looked through options, it doesn’t seem to be anything about black backgroung
However, the same code with 24.8 and new SVG file seem to be working fine withHblLogo_SVG_out.pdf (77.0 KB)
Can you provide some details about OS and version of framework you are using?
Hi Ilya
I’m working on Windows 10 Enterprise 64bit OS using .NET Framework 4.8. Unfortunately I’m stuck with .NET Framework and cannot switch to any newer .NET Core version.
Best regards
Marc
@marc.jansen.finstar.ch
I tried to reproduce with Net Framework 4.8.1, it doesn’t seem to work
However I was suggested to offer to try to replace NET Framework dll with Netstandard 2.0
You can find them by following link