you'll need to modify the resources references to new images that you'll create.
you can do that while modifying an existing PDF or importing the PDF and the images to a new PDF.
Assuming that you are going for modification you'll have to recreate the resources dictionary with references to the new images.
follow this process:
1. Open the PDF document for modification
2. Get the parser, loop the pages, for each page get the page dictionary object, and get it's resources dictionary.
3. Loop the resources dictionary getting to the image xobjects. for each image xobject:
3.1. if it is an image that you want to replace, import a jpg image to the PDF file. register the result form/image ID alongside with the existing image id
4. You will need to update the page object now. create a modified object (using ObjectsContent::StartModifiedObject) and copy into it all entries in the page dictionary but the resources dictionary.
5. create a resources dictionary entry in the page (or as indirect object), copy all but xobjects entries. then in it create an xobject entry and into it copy the keys of the old xobjects, where if you have a register replacement put the new object ID instead of the old one.
6. if you haven't ened the page/resources dictionary objects, do so now.
now you should have a new PDF with the images updated, and the pages updated with new resources dictionaries that point to the new images instead of the old ones.
it could have been a little shorter if there was a way to define new images as replacements to the old ones, while modifying, but there isn't.
there's something a little more comfortable if you are creating a new PDF and importing the one with the original images into it page by page. then you can simply create the image objects in advance on the new pdf, then using the copying content to mark the new images as replacements to the old ones, and then import the pages from the old PDF. the underlying copying mechanism will know not to copy the old images, using the new representatives instead.
Regards,
Gal.