如何使用iText从PDF中删除链接注释?

问题描述 投票:1回答:2

这里我想使用iTextSharp从PDF中永久删除注释(链接,文本,..)。>

我已经尝试过

AnnotationDictionary.Remove(PdfName.LINK);

但是该PDF中存在链接注释。

注意:

我要删除特定的选定注释(链接,文本,..),例如,我想使用URI作为www.google.com删除链接注释,我想保留的其余链接注释按原样存在。

这里我想使用iTextSharp从PDF中永久删除Annotation(Link,Text,..)。我已经尝试过AnnotationDictionary.Remove(PdfName.LINK);但是该PDF中存在链接注释。 ...

c# itextsharp
2个回答
2
投票

我得到了我的问题的答案。


0
投票
        Dim pdfReader As New PdfReader(fileloc)
        For i = 1 To pdfReader.NumberOfPages
            Dim pageDict As PdfDictionary = pdfReader.GetPageN(i)
            Dim annots As PdfArray = pageDict.GetAsArray(PdfName.ANNOTS)
            Dim newAnnots As PdfArray = New PdfArray()
            If annots IsNot Nothing Then
                For j As Integer = 0 To annots.Size() - 1
                    Dim annotDict As PdfDictionary = annots.GetAsDict(i)
                    If Not PdfName.LINK.Equals(annotDict.GetAsName(PdfName.SUBTYPE)) Then
                        newAnnots.Add(annots.GetAsDict(j))
                    End If
                Next
                pageDict.Put(PdfName.ANNOTS, newAnnots)
            End If
        Next
        Dim pdfStamper As PdfStamper = Nothing
        Dim extension = Path.GetExtension(fileloc)
        Dim filename As String = Path.GetFileNameWithoutExtension(fileloc)
        Dim filePath As String = Path.GetDirectoryName(fileloc)
        fileloc = filePath + "\" + filename + "new" + extension
        pdfStamper = New PdfStamper(pdfReader, New FileStream(fileloc, FileMode.Create))
        pdfStamper.FormFlattening = False
        pdfStamper.Close()
        pdfReader.Close()
    End Sub```
© www.soinside.com 2019 - 2024. All rights reserved.