从 PDF 中提取注释

Contents
[ ]

ExtractAnnotations 方法允许您从 PDF 文件中提取注释。为了提取注释,您需要创建 PdfAnnotationEditor 对象并使用 BindPdf 方法绑定 PDF 文件。之后,您需要创建一个要从 PDF 文件中提取的注释类型的枚举。

然后,您可以使用 ExtractAnnotations 方法将注释提取到 ArrayList 中。之后,您可以遍历此列表并获取单个注释。最后,使用 PdfAnnotationEditor 对象的 Save 方法保存更新后的 PDF 文件。以下代码片段向您展示如何从 PDF 文件中提取注释。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExtractAnnotation()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdfFacades_Annotations();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "AnnotationsInput.pdf"))
    {
        using (var annotationEditor = new Aspose.Pdf.Facades.PdfAnnotationEditor())
        {
            // Bind PDF document
            annotationEditor.BindPdf(document);
            // Extract annotations
            var annotationTypes = new[] { Aspose.Pdf.Annotations.AnnotationType.FreeText, Aspose.Pdf.Annotations.AnnotationType.Text };
            var annotations = annotationEditor.ExtractAnnotations(1, 2, annotationTypes);
            foreach (var annotation in annotations)
            {
                Console.WriteLine(annotation.Contents);
            }
        }
    }
}