I am trying to replace an image at the top of a PDF document. The image I am trying to replace is a PNG image. I can see and edit the image in both Adobe and Foxit. However, in C#.Net, when I look for any images in the PDF document (e.g. pdfPage.Resources.Images.Count), I am getting a count of zero. I can place an image over the image, but the image is still there (under the new image). Why would Apsose.PDF not be able to detect the image?
CDARUPST-Q00006002.pdf (14.5 KB)
@BradJTyler
We are investigating your question.
pdfPage.Resources.Images.Count is zero because the image in the attached file is not contained in the page resources, but is located directly in the page context (BI operator)
@BradJTyler
The following code should solve your problem, but it didn’t work for me - I’ll create a corresponding task for the development team.
using var pdfDocument = new Document(dataDir + "CDARUPST-Q00006002.pdf");
Page page = pdfDocument.Pages[1];
var newImageStream = new FileStream(dataDir + "new_image.png", FileMode.Open);
var imageAbsorber = new ImagePlacementAbsorber();
imageAbsorber.Visit(page);
foreach (ImagePlacement ip in imageAbsorber.ImagePlacements)
// ip.Replace(newImageStream); // works with page.Resources.Images only
ip.Hide(); // resulting documernt is incorrect
pdfDocument.Save(dataDir + "CDARUPST-Q00006002_out.pdf");
@BradJTyler
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-58994
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.
Hi Sergei,
If your dev team can fix this as soon as possible that would be great. I am currently trialing Aspose.PDF, but I need this to work. We will purchase the software if the image can be replace. We are also willing to obtain paid support services. How do I get paid support services?
Thanks
Brad
@BradJTyler
Yes, it is very annoying that the library does not work properly. As a temporary workaround, it is possible to determine the position of the existing image (ip.Rectangle) and insert a replacement image with the calculation that it covers the existing one.
You can see it here