Replacing image in a pdf

Is there a way to replace an existing image inside a pdf with an image created on memorystream?
I’ve found a method called ReplaceImage in PdfContentEditor class but it can only replace an existing image with a file system image

@Raito,

You can use Replace method of the XImageCollection. Please refer to this code example: Replace Image in Existing PDF File

I’m having the same problem, since images are not shown in Resources.Images but are found by ImagePlacementAbsorber:

Any way to replace image without using Resources.Images.ReplaceImage ?

@eitan,

Our fellow worker Tilal has already logged your source PDF and scenario details under the ticket ID PDFNET-35208 in our bug tracking system. We will let you know once a significant progress has been made in this regard.

@eitan

In the attached source document, the image is not stored in the page’s resources but in the form’s resources within the page. To extract this image, use one of the following code snippets:

var input = "input.pdf";
var outputJpg = "output.jpg";
Document pdfDocument = new Document(input);
var page = pdfDocument.Pages[1];
var formResources = page.Resources.Forms[1].Resources;
XImage xImage = formResources.Images[1];
using (FileStream outputImage = new FileStream(outputJpg, FileMode.Create))
{
    xImage.Save(outputImage);
    outputImage.Close();
}
var input = "input.pdf";
var outputJpg = "output.jpg";
PdfExtractor pdfExtractor = new PdfExtractor();
pdfExtractor.BindPdf(input);
pdfExtractor.StartPage = 1;
pdfExtractor.EndPage = 1;
pdfExtractor.ExtractImageMode = ExtractImageMode.ActuallyUsed;
pdfExtractor.ExtractImage();
while (pdfExtractor.HasNextImage())
{
    MemoryStream memoryStream = new MemoryStream();
    pdfExtractor.GetNextImage(memoryStream);
    FileStream fileStream = new
    FileStream(outputJpg, FileMode.Create);
    memoryStream.WriteTo(fileStream);
    fileStream.Close();
}