I am unable to get the solution found here to work.
The code runs without any exception and while debugging it show that resources.getimages().clear();
is doing something, but for some reason the changes are not 'saved' when the output document is created. Rather, the output document is identical to the input.
I have checked that the PDF contains valid images as I've used another code from pdfbox to extract all of them.