J-F-Liu / lopdf

A Rust library for PDF document manipulation.
MIT License
1.67k stars 176 forks source link

[Question] How can I replace an image? #269

Open mnmtz opened 8 months ago

mnmtz commented 8 months ago

Is there a way to replace an image in a pdf file with another image?

Heinenen commented 2 days ago

If the new image has the same dimensions as the old one, you could maybe get away with replacing the object that contains the image data.

That would work by first finding the correct image ID with the help of Document::get_page_images. Then replacing the image with Document::get_object_mut.

Other than that, you're probably out of luck, as long as nothing better is implemented.