)
{
// Get the image used to replace existing ones!
Image image = Image.get(getInputPath() + java.io.File.separator + "images" + java.io.File.separator + "gnu.jpg"); // Image is an abstract entity, as it still has to be included into the pdf document.
// Add the image to the document!
XObject imageXObject = image.toXObject(document); // XObject (i.e. external object) is, in PDF spec jargon, a reusable object.
// Looking for images to replace...
for(Page page : document.getPages())
{
Resources resources = page.getResources();
XObjectResources xObjects = resources.getXObjects();
if(xObjects == null)
continue;
for(PdfName xObjectKey : xObjects.keySet())
{
XObject xObject = xObjects.get(xObjectKey);
// Is the page's resource an image?
if(xObject instanceof ImageXObject)
{
System.out.println("Substituting " + xObjectKey + " image xobject.");
xObjects.put(xObjectKey,imageXObject);