如何添加和编辑 PDF 注释
注释允许用户为文档的特定部分添加注释、提醒或其他信息。在处理 PDF 文档时,注释可加强协作和交流,使用户能够对共享内容进行注释、评论并提供上下文。
如何添加和编辑 PDF 注释
开始在您的项目中使用IronPDF,并立即获取免费试用。
查看 IronPDF 上 Nuget 用于快速安装和部署。它有超过800万次下载,正在使用C#改变PDF。
Install-Package IronPdf
考虑安装 IronPDF DLL 直接。下载并手动安装到您的项目或GAC表单中: IronPdf.zip
手动安装到你的项目中
下载DLL添加注释示例
PDF 注释允许在 PDF 页面上添加类似 "便条 "的注释。通过使用 Annotations 属性的 Add
方法,可以以编程方式添加注释。
提示
:path=/static-assets/pdf/content-code-examples/how-to/annotation-add-annotation.cs
using IronPdf;
using IronPdf.Annotations;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Annotation</h1>");
// Create a PDF annotation object on a specified page index
TextAnnotation annotation = new TextAnnotation(0)
{
Title = "This is the title",
Contents = "This is the long 'sticky note' comment content...",
X = 50,
Y = 700,
};
// Add the annotation
pdf.Annotations.Add(annotation);
pdf.SaveAs("annotation.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
带注释的 PDF
上述 PDF 文档中的注释可通过 Chrome 浏览器查看。
检索和编辑注释示例
检索和编辑 PDF 注释可提高清晰度、准确性和可用性,从而改善协作。通过注释属性访问注释集合,并根据新信息更新标题、内容、X、Y 等属性。
:path=/static-assets/pdf/content-code-examples/how-to/annotation-edit-annotation.cs
using IronPdf;
using IronPdf.Annotations;
using System.Linq;
PdfDocument pdf = PdfDocument.FromFile("annotation.pdf");
// Retrieve annotation collection
PdfAnnotationCollection annotationCollection = pdf.Annotations;
// Select the first annotation
TextAnnotation annotation = (TextAnnotation)annotationCollection.First();
// Edit annotation
annotation.Title = "New title";
annotation.Contents = "New content...";
annotation.X = 150;
annotation.Y = 800;
pdf.SaveAs("editedAnnotation.pdf");
Imports IronPdf
Imports IronPdf.Annotations
Imports System.Linq
Private pdf As PdfDocument = PdfDocument.FromFile("annotation.pdf")
' Retrieve annotation collection
Private annotationCollection As PdfAnnotationCollection = pdf.Annotations
' Select the first annotation
Private annotation As TextAnnotation = CType(annotationCollection.First(), TextAnnotation)
' Edit annotation
annotation.Title = "New title"
annotation.Contents = "New content..."
annotation.X = 150
annotation.Y = 800
pdf.SaveAs("editedAnnotation.pdf")
带有编辑注释的 PDF
上述 PDF 文档中的注释可通过 Chrome 浏览器查看。
移除注释示例
使用以下方法轻松删除不必要或过时的注释:RemoveAt
、RemoveAllAnnotationsForPage
和Clear
。
- RemoveAt:删除指定索引的单个注释。
RemoveAllAnnotationsForPage:删除指定页面上的所有注释。
- 清除:删除文档中的所有注释。
删除一个注释
要删除单个注释,请使用 RemoveAt
方法,并根据注释集合索引选择相应的索引。
:path=/static-assets/pdf/content-code-examples/how-to/annotation-remove-single-annotation.cs
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("multipleAnnotation.pdf");
// Remove a single annotation with specified index
pdf.Annotations.RemoveAt(1);
pdf.SaveAs("removeSingleAnnotation.pdf");
Imports IronPdf
Private pdf As PdfDocument = PdfDocument.FromFile("multipleAnnotation.pdf")
' Remove a single annotation with specified index
pdf.Annotations.RemoveAt(1)
pdf.SaveAs("removeSingleAnnotation.pdf")
删除 PDF 上的单个注释
之前
之后
上述 PDF 文档中的注释可通过 Chrome 浏览器查看。
删除所有注释
要移除特定页面上的所有注释,请使用 RemoveAllAnnotationsForPage
方法并指定页面索引。如果要删除整个文档中的所有注释,只需调用 Annotations 属性上的 Clear
方法即可。
:path=/static-assets/pdf/content-code-examples/how-to/annotation-remove-all-annotation.cs
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("multipleAnnotation.pdf");
// Remove all annotaions on a specified page
pdf.Annotations.RemoveAllAnnotationsForPage(0);
// Remove all annotaions on the document
pdf.Annotations.Clear();
pdf.SaveAs("removeAllAnnotation.pdf");
Imports IronPdf
Private pdf As PdfDocument = PdfDocument.FromFile("multipleAnnotation.pdf")
' Remove all annotaions on a specified page
pdf.Annotations.RemoveAllAnnotationsForPage(0)
' Remove all annotaions on the document
pdf.Annotations.Clear()
pdf.SaveAs("removeAllAnnotation.pdf")