这里我想使用iTextSharp永久删除PDF中的注释(链接,文本,...)。
我已经尝试过了
AnnotationDictionary.Remove(PdfName.LINK);
但该PDF中存在链接注释。
注意:
我想删除特定的选定注释(链接,文本,..), 例如,我想删除链接注释,其URI为www.google.com,剩余的链接注释我希望按照存在保留。
答案 0 :(得分:2)
我得到了我的问题的答案。
示例代码:
//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);
}
答案 1 :(得分:-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```