0
votes

I have created a Word document where I have inserted some images, added hyperlinks (to these images), and converted the document to pdf. Is there any way to find the position of the image that has a specific hyperlink using iTextSharp library? I have found solutions that can return the image or the hyperlink text but it's not exactly what I need. My end goal is to find the image with a specific URL and delete it (along with the associated URL) while saving its location (have to save x, y, height, and width before deletion).

Thank you.

1

1 Answers

1
votes

You have found solutions that can return:

  • the image and its position,
  • the hyperlink and its position.

And that's exactly what you need. Now compare the positions of the image with the positions of the hyperlinks and you'll know which image corresponds with which link.

You are asking to find images with a specific URL, but there is no such thing in PDF. In a PDF, each page is described using a page dictionary. In this page dictionary, there is:

  • an entry named /Contents (required): this refers to the content stream(s) of the page and the content stream(s) contain references to images (stored as /XObject in the /Resources entry of the page dictionary).
  • an entry named /Annots (optional): this refers to all the annotations that are added on top of the content. Hyperlinks are stored in link annotations.

Links are not aware of the content they cover. Content is not aware of the annotations that cover them. That's why you didn't find an answer to your question. You've been making the wrong assumptions about clickable images.