First of all - great work! Awesome piece of code you created.
However, i've been struggling with FormXObjects. I want to replace an image with another which is stored as IndirectObject. To find the right one i was looking through all XObjects and especially looking for ImageXObjects and check their positions to get the ID, in order to replace the right indirectObject. It worked like a charme until I realised that some PDFs store the image instance information not as ImageXObject anymore but as FormXObject, which I was unable to handle. The size always is the same as the page and i cannot get any informations anymore as i used to with ImageXObject.
Anyone struggled with FormXObjects too or has an idea how to reach the instances of an imag another way?
private PdfDirectObject GetPictureIdByPosition(ContentScanner level, Page page, int x, int y)
while ((obj = level.Current) != null)
if (obj is PaintXObject)
PdfName xObjectKey = ((PaintXObject)obj).Name;
xObjects::XObject xObject = page.Resources.XObjects[xObjectKey];
if (xObject is xObjects::ImageXObject)
double ctm = level.State.CTM;
SizeF imageSize = xObject.Size;
if (Math.Round(ctm) == x && Math.Round(page.Size.Value.Height - ctm) == y)
else if(!(obj is Operation))
PdfDirectObject res = GetPictureIdByPosition(level.ChildLevel, page, x, y);
if (res != null)
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.