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);
xObjects.update();
}
}
/* for(Map.Entry<PdfName,XObject> xObjectEntry : xObjects.entrySet())
{
if(xObjectEntry.getValue() instanceof ImageXObject)