注释通常用于向某些文档添加说明,解释,详细信息或注释。在PDF文件中,注释经常使用,您可能需要将其导入或导出为XFDF格式在本文中将介绍如何使用C#或VB.NET轻松地以编程方式导入或导出注释。让我们看一下以下内容:
- 使用C#或VB.NET将注释从XFDF导入到PDF
- 使用C#或VB.NET将注释从PDF导出到XFDF
点击下载最新版Aspose.PDFhttps://www.evget.com/product/565/download
使用C#或VB.NET将注释从XFDF导入到PDF
可以使用C#或VB.NET编程语言从基于.NET的应用程序中的现有XFDF文件将注释导入PDF文件。API支持导入API参考中AnnotationType枚举下列出的不同类型的注释。让我们按照以下步骤在基于.NET Framework的应用程序中使用C#或VB.NET编程语言将注释从XFDF导入PDF。
- 初始化PdfAnnotationEditor类对象
- 加载输入的PDF文档
- 加载XFDF文件以导入注释
- 指定要导入的注释类型
- 将注释从XFDF导入到PDF文件
- 保存输出的PDF文件
下面的代码段显示了如何使用C#或VB.NET将注释从XFDF文件导入PDF文件:
// Create an object of PdfAnnotationEditor class PdfAnnotationEditor editor = new PdfAnnotationEditor(); // Bind input PDF file editor.BindPdf(dataDir + "inFile.pdf"); // Create a file stream for input XFDF file to import annotations FileStream fileStream = new FileStream(dataDir + "exportannotations.xfdf", FileMode.Open, FileAccess.Read); // Create an enumeration of all the annotation types which you want to import Enum[] annType = { AnnotationType.Text }; // Import annotations of specified type(s) from XFDF file editor.ImportAnnotationFromXfdf(fileStream, annType); // Save output pdf file editor.Save(dataDir + "ImportAnnotations_out.pdf");
使用C#或VB.NET将注释从PDF导出到XFDF文件
从PDF文件导出注释有助于使文件可显示或仅使特定类型的注释保持完整。例如,当某人正在审查可行性报告或论文提交时,让我们假设,他们可能会突出显示某些文本,添加评论或文本。后来,他们只想保留文本,然后再将PDF发送回作者。在这种情况下,将注释导出到XFDF会有所帮助,因为它使您可以根据需要导出特定的注释。以下步骤显示了如何将注释从PDF导出为XFDF格式:
- 初始化PdfAnnotationEditor对象
- 加载输入PDF文件
- 创建XFDF文件以保存导出的注释
- 指定注释类型以导出
- 使用ExportAnnotationsXfdf方法导出注释
下面的代码段显示了如何使用C#或VB.NET将注释从PDF文件导出到XFDF文件:
// Create an object of PdfAnnotationEditor class PdfAnnotationEditor editor = new PdfAnnotationEditor(); // Bind input PDF file editor.BindPdf(dataDir + "inFile.pdf"); // Create a file stream for output XFDF file to export annotations FileStream fileStream = new FileStream(dataDir + "exportannotations.xfdf", FileMode.Create, FileAccess.Write); // Create an enumeration of all the annotation types which you want to export Enum[] annoType = { AnnotationType.Text }; // Export annotations of specified type(s) to XFDF file editor.ExportAnnotationsXfdf(fileStream, 1, 5, annoType);