简体   繁体   English

使用iTextSharp删除具有特定超链接的图像

[英]Deleting Images With Specific Hyperlink Using iTextSharp

I have created a Word document where I have inserted some images, added hyperlinks (to these images), and converted the document to pdf. 我创建了一个Word文档,在其中插入了一些图像,向这些图像添加了超链接,并将该文档转换为pdf。 Is there any way to find the position of the image that has a specific hyperlink using iTextSharp library? 有什么方法可以使用iTextSharp库查找具有特定超链接的图像的位置? 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). 我的最终目标是找到具有特定URL的图像并将其删除(连同关联的URL),同时保存其位置(在删除之前必须保存x,y,高度和宽度)。

Thank you. 谢谢。

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. 您要查找具有特定URL的图像,但是PDF中没有此类内容。 In a PDF, each page is described using a page dictionary . 在PDF中,每个页面都使用页面字典来描述。 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). 名为/Contents的条目(必填):这是指页面的内容流,并且内容流包含对图像的引用(在页面字典的/Resources条目中存储为/XObject )。
  • an entry named /Annots (optional): this refers to all the annotations that are added on top of the content. 名为/Annots的条目(可选):这是指在内容顶部添加的所有注释。 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. 您对可点击图片做出了错误的假设。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM