2

在这里,我想使用 iTextSharp 从 PDF 中永久删除 Annotation(Link, Text, ..)。

我已经试过了

AnnotationDictionary.Remove(PdfName.LINK);

但是那个链接注释存在于那个 PDF 中。

笔记:

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

4

2 回答 2

3

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

示例代码:

//Get the current page
PageDictionary = R.GetPageN(i);

//Get all of the annotations for the current page
Annots = PageDictionary.GetAsArray(PdfName.ANNOTS);

foreach (PdfObject A in Annots.ArrayList)
{
//code to check the annotation 

//remove the annotation
Annots.Remove(int idx);

}
于 2013-09-24T08:51:22.457 回答
-1
        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```
于 2020-01-17T19:31:19.703 回答