如何通过 itext7 更改 pdf 链接的链接类型?

问题描述

我想编辑 pdf 文件中的可见链接矩形:

如果我使用 acrobat,我可以将链接类型编辑为“Visible Rectangle

enter image description here

enter image description here

但是使用 iText7 ,如何更改此值?

我尝试设置,但它不起作用:

string strPage = @"C:\test1.pdf";
string strPageNew = @"C:\result.pdf";
PdfReader reader = new PdfReader(strPage);
using (PdfWriter writer = new PdfWriter(strPageNew))
{
    using (PdfDocument pdfDoc = new PdfDocument(reader,writer))
    {                    
        pdfpage pdfpage = pdfDoc.GetPage(1);
        var annotations = pdfpage.GetAnnotations();
        if (annotations != null)
        {
            foreach (PdfAnnotation a in annotations)
            {
                if (a.GetSubtype().Equals(PdfName.Link))
                {
                    PdfLinkAnnotation link = (PdfLinkAnnotation)a;
                    var action = link.GetAction();
                    if (action != null)
                    {
                        if (action.Get(PdfName.S).Equals(PdfName.URI))
                        {
                            PdfString destination = action.GetAsstring(PdfName.URI);
                            
                            link.SetFlag(4);
                            link.SetHighlightmode(PdfAnnotation.HIGHLIGHT_OUTLINE);
                            link.SetBorderStyle(PdfAnnotation.STYLE_SOLID);
                            link.SetColor(iText.Kernel.Colors.ColorConstants.RED );
                        }
                    }
                }
            }
        }
    }
}

reader.Close();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)