导入和导出注释到XFDF

XFDF代表XML Forms Data Format。它是一种基于XML的文件格式。此文件格式用于表示PDF表单中包含的表单数据或注释。XFDF可以用于许多不同的目的,但在我们的例子中,它可以用于在计算机或服务器之间发送或接收表单数据或注释,也可以用于存档表单数据或注释。在本文中,我们将看到Aspose.Pdf.Facades如何考虑到这个概念,以及我们如何将注释数据导入和导出到XFDF文件。

导入和导出注释到XFDF

Aspose.PDF for .NET是一个功能丰富的组件,当涉及到编辑PDF文档时。 ``` As we know XFDF is an important aspect of PDF forms manipulation, Aspose.Pdf.Facades namespace in Aspose.PDF for .NET has considered this very well, and have provided methods to import and export annotations data to XFDF files.

PDFAnnotationEditor class contains two methods to work with import and export of annotations to XFDF file.

正如我们所知,XFDF 是 PDF 表单操作的重要方面,Aspose.Pdf.Facades 命名空间Aspose.PDF for .NET 中对此进行了充分考虑,并提供了将注释数据导入和导出到 XFDF 文件的方法。

PDFAnnotationEditor 类包含两个用于处理注释到 XFDF 文件的导入和导出的方法。


以下代码片段向您展示了如何将注释导入XFDF文件:

```csharp
public static void ImportAnnotation()
        {
            var sources = new string[] { _dataDir + "sample_cats_dogs.pdf" };
            PdfAnnotationEditor annotationEditor = new PdfAnnotationEditor();
            annotationEditor.BindPdf(_dataDir + "sample.pdf");
            annotationEditor.ImportAnnotations(sources);
            annotationEditor.Save(_dataDir + "sample_demo.pdf");
        }

下一个代码片段描述了如何将注释导入/导出到XFDF文件:

public static void ImportExportXFDF01()
        {
            PdfAnnotationEditor annotationEditor = new PdfAnnotationEditor();
            annotationEditor.BindPdf(_dataDir + "sample_cats_dogs.pdf");
            System.IO.FileStream xmlOutputStream = System.IO.File.OpenWrite(_dataDir + "sample.xfdf");
            annotationEditor.ExportAnnotationsToXfdf(xmlOutputStream);
            xmlOutputStream.Close();
            var document = new Document();
            document.Pages.Add();
            annotationEditor.BindPdf(document);
            annotationEditor.ImportAnnotationsFromXfdf(System.IO.File.OpenRead(_dataDir + "sample.xfdf"));
            annotationEditor.Save(_dataDir + "ImportedAnnotation.pdf");
        }

这样,只有指定类型的注释才会被导入或导出到XFDF文件。

   public static void ImportExportXFDF02()
        {
            PdfAnnotationEditor annotationEditor = new PdfAnnotationEditor();
            annotationEditor.BindPdf(_dataDir + "sample_cats_dogs.pdf");
            System.IO.FileStream xmlOutputStream = System.IO.File.OpenWrite(_dataDir + "sample.xfdf");
            var annotationTypes = new[] { AnnotationType.FreeText, AnnotationType.Text };
            annotationEditor.ExportAnnotationsXfdf(xmlOutputStream, 2, 2, annotationTypes);
            xmlOutputStream.Close();

            var document = new Document(_dataDir + "sample.pdf");
            document.Pages.Add();
            annotationEditor.BindPdf(document);
            annotationEditor.ImportAnnotationsFromXfdf(System.IO.File.OpenRead(_dataDir + "sample.xfdf"));
            annotationEditor.Save(_dataDir + "ImportedAnnotation.pdf");
        }