PDF注釈を追加および編集する方法

Chaknith related to PDF注釈を追加および編集する方法
チャクニット・ビン
2023年6月1日
更新済み 2024年12月10日
共有:
This article was translated from English: Does it need improvement?
Translated
View the article in English

注釈により、ユーザーはドキュメントの特定のセクションにコメント、リマインダー、または追加情報を追加することができます。 それらは、PDFの共同作業やコミュニケーションを強化し、ユーザーが共有コンテンツに注釈を付け、コメントし、文脈を提供することを可能にします。


IronPDFを始めましょう!

今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。

最初のステップ:
green arrow pointer



注釈の追加例

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ブラウザーで表示できます。


注釈を削除する例

次の方法を使用して、不必要または古い注釈を簡単に削除できます:RemoveAtRemoveAllAnnotationsForPageClear

  • 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");
Chaknith related to すべての注釈を削除
ソフトウェアエンジニア
チャクニットは開発者のシャーロック・ホームズです。彼がソフトウェアエンジニアリングの将来性に気付いたのは、楽しみでコーディングチャレンジをしていたときでした。彼のフォーカスはIronXLとIronBarcodeにありますが、すべての製品でお客様を助けることに誇りを持っています。チャクニットは顧客と直接話すことで得た知識を活用して、製品自体のさらなる改善に貢献しています。彼の逸話的なフィードバックは、単なるJiraチケットを超えて、製品開発、ドキュメントおよびマーケティングをサポートし、顧客の全体的な体験を向上させます。オフィスにいないときは、機械学習やコーディングについて学んだり、ハイキングを楽しんだりしています。