PDF注釈を追加および編集する方法
注釈により、ユーザーはドキュメントの特定のセクションにコメント、リマインダー、または追加情報を追加することができます。 それらは、PDFの共同作業やコミュニケーションを強化し、ユーザーが共有コンテンツに注釈を付け、コメントし、文脈を提供することを可能にします。
IronPDFを始めましょう!
今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。
PDF注釈を追加および編集する方法
- PDF注釈用C#ライブラリをダウンロード
- 既存のPDFドキュメントを読み込むか、新しいPDFドキュメントをレンダリングします。
- 注釈を追加するために
Add
メソッドを使用する - PDF注釈の取得と編集
- PDFドキュメントから注釈を削除する
注釈の追加例
PDF注釈は、PDFページに「付箋メモ」のようなコメントを追加することを可能にします。 Add
メソッドを使用することで、Annotations プロパティに注釈をプログラムで追加することができます。
ヒント
: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");
注釈付きPDF
上記のPDFドキュメント内の注釈は、Chromeブラウザーで表示できます。
注釈の取得と編集の例
PDF注釈の取得および編集は、明確さ、正確性、使用性を向上させることでコラボレーションを改善します。 アノテーションコレクションには、Annotations プロパティを介してアクセスし、Title、Contents、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");
編集された注釈付きPDF
上記のPDFドキュメント内の注釈は、Chromeブラウザーで表示できます。
注釈を削除する例
次の方法を使用して、不必要または古い注釈を簡単に削除できます:RemoveAt
、RemoveAllAnnotationsForPage
、Clear
。
- RemoveAt: 指定されたインデックスの注釈を1つ削除します。
- 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");
単一の注釈を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");