PDF注釈をC#で追加・編集する方法
IronPDF は、C# 開発者が Annotations.Add メソッドと TextAnnotation クラスを通じて、テキストコメントや付箋などのPDF注釈を追加、編集、削除できるようにすることで、ビジネスアプリケーションでのドキュメントの共同作業とレビューのワークフローを向上させます。
貴社はPDFのセキュリティとコンプライアンスに年間サブスクリプション費用をかけすぎています。デジタル署名、編集、暗号化、保護などのSaaSサービスを管理するソリューションを提供するIronSecureDocを検討してください。すべて一度の支払いで可能です。IronSecureDocのドキュメンテーションを見る
注釈は、ユーザーがドキュメントの特定のセクションにコメント、リマインダー、または追加情報を追加できるようにします。 このツールは、PDFで作業する際のコラボレーションとコミュニケーションを強化し、ユーザーが注釈を付けたり、コメントしたり、共有コンテンツにコンテキストを提供したりすることを可能にします。
PDFの注釈は、ビジネスワークフローにおいてさまざまな役割を果たします。レビュアーは文書にマークアップしてフィードバックすることができ、チームは元のコンテンツを変更することなく契約書について共同作業を行うことができます。 ドキュメント管理システムを構築中または既存のPDFワークフローを強化中の場合、IronPDFの注釈機能はC#によるPDF作成および編集機能と統合されます。 注釈機能と共に高度なセキュリティ機能が必要な組織向けに、当社の包括的なPDFセキュリティチュートリアルを参照してください。
クイックスタート: IronPDFを使用して PDF に注釈を追加するこのクイックガイドでは、C#でIronPDFを使用してPDFドキュメントにテキスト注釈を追加する方法を説明します。 ほんの数行のコードで、開発者はPDFにコメントやノートを追加することで、ドキュメントのインタラクティビティとコラボレーションを向上させることができます。 PDF を読み込み、TextAnnotation インスタンスを作成し、それを Annotations.Add に渡して注釈をすばやく挿入します。
-
1IronPDF を NuGet Package Manager でインストールします
-
2このコード スニペットをコピーして実行します。
PdfDocument.FromFile("input.pdf") .Annotations.Add(new TextAnnotation(0) { Title="Note", Contents="Review this section.", X=50, Y=700 }) .SaveAs("annotated.pdf");PdfDocument.FromFile("input.pdf") _ .Annotations.Add(New TextAnnotation(0) With {.Title = "Note", .Contents = "Review this section.", .X = 50, .Y = 700}) _ .SaveAs("annotated.pdf")PdfDocument.FromFile("input.pdf") _ .Annotations.Add(New TextAnnotation(0) With {.Title = "Note", .Contents = "Review this section.", .X = 50, .Y = 700}) _ .SaveAs("annotated.pdf") -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronPDFを使い始めるには、無料トライアルをお試しください。
最小限のワークフロー(5ステップ)
- PDF用C#ライブラリのダウンロード
- 既存のPDFをロードするか、新しいPDF文書をレンダリングする
- 注釈を追加するには、
Addメソッドを使用します。 - PDF注釈の取得と編集
- PDF文書から注釈を削除
PDFに注釈を追加するにはどうすればよいですか?
Annotations
Title
Contents
X
Y
PDF注釈により、PDFページに "付箋" のようなコメントを追加することができます。 注釈は、Annotations プロパティの Add メソッドを使用してプログラム化することで追加できます。
PDFのテキスト注釈は、物理的な文書の付箋と同様の機能を果たします。 ページ上に小さなアイコンで表示され、クリックするとコメント全文が表示されます。 この押し付けがましくないアプローチは、ドキュメントを読みやすく保ちながら、必要不可欠なフィードバックメカニズムを提供します。 HTMLからPDFへの変換を扱う際、変換後に注釈を追加してレビューが必要な箇所や追加の文脈を提供することができます。 この機能は、追加の説明が必要な動的なコンテンツにJavaScriptレンダリングと組み合わせると特に有用です。
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");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");Imports IronPdf
Imports IronPdf.Annotations
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Annotation</h1>")
' Create a PDF annotation object on a specified page index
Dim annotation As New TextAnnotation(0) With {
.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")Imports IronPdf
Imports IronPdf.Annotations
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Annotation</h1>")
' Create a PDF annotation object on a specified page index
Dim annotation As New TextAnnotation(0) With {
.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")TextAnnotationクラスはカスタマイズ用のいくつかのプロパティを提供します:
Title:通常は注釈ポップアップに表示される注釈のヘッダーテキストContents:注釈のメインボディテキストX、Y:注釈アイコンがページ上で表示される座標を指定しますPageIndex:注釈が配置されるべきページのゼロベースページ番号
より複雑なドキュメントワークフローには、承認プロセスのためにデジタル署名やドキュメントバージョニングのためのウォーターマーキングなど、他のIronPDF機能と注釈を組み合わせることを考慮してください。 機密文書を扱う際には、PDFの権限とパスワードと注釈を統合して、誰が注釈を表示または変更できるかを制御できます。
テキスト注釈にはどのようなプロパティを設定できますか?
TextAnnotationクラスは、基本的なものを超えるカスタマイズ用のいくつかのプロパティを提供します:
Title:通常は注釈ポップアップに表示される注釈のヘッダーテキストContents:注釈のメインボディテキストX、Y:注釈アイコンがページ上で表示される座標を指定しますPageIndex:注釈が配置されるべきページのゼロベースページ番号Subject:注釈を分類するためのオプションの件名行Icon:注釈の視覚的表現(例えば、ノート、コメント、ヘルプ)Open:注釈ポップアップがデフォルトで開いているかどうか
これらの特性により、開発者は、文書コミュニケーションを強化する豊富な文脈注釈を作成することができます。 さまざまなドキュメントタイプを含む高度なワークフローについては、注釈を異なるソース形式間で維持するためにRTFからPDFへの変換やMarkdownからPDFへの変換を探究してください。
PDF注釈における座標はどのように機能しますか?
PDFの座標は、左上起点を使用する多くのUIフレームワークとは異なり、ページの左下から始まります。 X と Y プロパティは、注釈アイコンがページ上で表示される位置を決定します (単位はポイント、1インチの1/72) プログラムでアノテーションを配置する場合、座標計算がこの違いを考慮していることを確認してください。
注釈の位置を計算する際は、標準的なUSレターのページが8.5 x 11インチ(612 x 792ポイント)であることを覚えておいてください。 A4ページ、595 x 842ポイント。 正確な位置決めのために、アノテーションを配置する前に、ページの寸法をプログラムで取得することをお勧めします。 カスタム用紙サイズを使用する場合やコンテンツに基づいたレスポンシブな注釈配置を実装する際に特に重要です。
注釈付きPDF
上記のPDFドキュメントの注釈はChromeブラウザーで表示できます。
既存の注釈を取得して編集するにはどうすればよいですか?
PDF注釈の取得と編集は、明確さ、正確さ、使いやすさを向上させることでコラボレーションを改善します。 Annotations プロパティを介して注釈コレクションにアクセスし、Header、Body、X、Y などのプロパティを新しい情報で更新します
URL変換やDOCXインポートなどからの既存のPDFを扱う際には、他のユーザーやシステムによって追加された注釈を修正する必要があるかもしれません。 IronPDFはアノテーションコレクションへのフルアクセスを提供し、プログラムによって特定のアノテーションを繰り返し、特定し、更新することができます。 この能力は、文書レビューのワークフローを実装する場合や、既存の文書管理システムと統合する場合に不可欠です。
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");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")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")編集プロセスでは、他のすべてのドキュメントプロパティとコンテンツが維持され、指定された注釈のみが変更されるようにします。 これは、ドキュメントの改訂や要件の変更に基づいて注釈を更新する必要があるレビューワークフローで特に役立ちます。 包括的なドキュメント管理のために、注釈編集とメタデータ操作を組み合わせて、ドキュメントバージョンや改訂履歴を追跡することを検討してください。
なぜ既存の注釈を編集する必要があるのですか?
注釈の編集は、フィードバックが改訂に基づいて更新されたり、あいまいなコメントを明確にする必要があったり、コンテンツの変更によって注釈の位置が変更されたりするような共同文書のワークフローでは不可欠です。 この機能により、文書レビューが改訂サイクルを通じて最新かつ適切なものに保たれます。
企業環境では、注釈の編集は承認ワークフローと統合されることが多く、最終承認前に上司がレビュアーのコメントを修正する必要があります。 さらに、文書が翻訳またはローカライズされる際には、言語の変更や文化的な適応を反映するために注釈の更新が必要になることがあります。 このようなシナリオの場合、IronPDFのUTF-8および国際的な言語対応により、異なる言語や文字セットで注釈が正しく表示されることを保証します。
注釈を編集するとき、他のドキュメントプロパティには何が起こりますか?
編集プロセスでは、他のすべてのドキュメントプロパティとコンテンツが維持され、指定された注釈のみが変更されるようにします。 文書の構造、書式、埋め込みリソース、その他の注釈は変更せず、PDFの完全性を維持しながら、特定のレビューコメントに対して的を絞った更新を可能にします。
このような選択的な編集アプローチは、特に文書の改ざんを避けなければならない規制業界において、文書の完全性を維持するために非常に重要です。 このプロセスでは、デジタル署名、フォームフィールド、しおり、その他すべてのPDF機能が保持されます。 監査証跡が必要な文書については、注釈の変更と共に改訂履歴の追跡を実行することを考慮してください。
編集された注釈付きPDF
上記のPDFドキュメントの注釈はChromeブラウザーで表示できます。
PDFドキュメントから注釈を削除するにはどうすればよいですか?
次のメソッドを使用して、不要または古い注釈を削除します: RemoveAt, RemoveAllAnnotationsForPage, およびClear。
RemoveAt:指定されたインデックスの注釈を1つ削除します。RemoveAllAnnotationsForPage:指定されたページのすべての注釈を削除します。Clear:ドキュメント内のすべての注釈を削除します。
注釈の除去は、文書の最終化にとって非常に重要です。 フィードバックを取り入れ、必要な変更を加えた後、最終版を配布する前に、レビューコメントを一掃するとよいでしょう。 このプロセスは、PDF圧縮などの他のIronPDF機能と統合されており、配布用のクリーンで最適化されたドキュメントを作成します。 アーカイブが必要な文書については、長期保存の遵守を確保するために注釈を削除した後、PDF/A形式に変換することを考慮してください。
単一の注釈を削除するにはどうすればよいですか?
単一の注釈を削除するには、注釈コレクションインデックスに基づいて対応するインデックスを持つRemoveAtメソッドを使用します。
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("multipleAnnotation.pdf");
// Remove a single annotation with specified index
pdf.Annotations.RemoveAt(1);
pdf.SaveAs("removeSingleAnnotation.pdf");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")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 メソッドを呼び出してください。
この一括削除機能は、最終配布用のドキュメントを準備する場合や、以前のレビューサイクルの注釈を削除する必要があるドキュメントのバージョン管理システムを実装する場合に特に役立ちます。 メタデータ編集と組み合わせて、ドキュメントプロパティを更新し、レビューの状態を示すようにします。 サニタイズされたドキュメントを必要とするワークフローには、注釈を含む潜在的に機密性の高い情報をすべて削除するための[PDFサニタイズ](https://ironpdf.com/docs/ to sanitize-pdf/)オプションを探してください。
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");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")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")一括注釈削除はいつ使用すべきですか?
一括削除は、配布用の文書の最終化、アーカイブ目的のクリーンバージョンの作成、または以前のレビューサイクルからの注釈を消去する必要がある文書のバージョニングの実装に最適です。 このアプローチは、注釈を個別に削除するよりも時間を節約し、本番ドキュメントに誤ってレビューコメントが残らないようにします。
さらに、注釈を正しく扱えない可能性のある自動処理システム用に文書を準備する場合や、注釈付きPDFを他の形式に変換する場合には、一括削除が不可欠です。 セキュリティの高い環境では、配布前にすべての注釈を削除することで、社内のレビューコメントや社外向けではない機密のフィードバックが不用意に公開されるのを防ぎます。
PDFにクリック可能な内部リンクを追加するには?
LinkAnnotation
DestinationType
Hidden
LinkAnnotationクラスは、クリックされたときに同じPDF内の別のページに移動するクリック可能な長方形をページ上に作成します。 カスタム目次、クロスリファレンス、「トップに戻る」ボタン、およびその他のドキュメント内ナビゲーションの構築に最適です。 TextAnnotation と同様に、LinkAnnotation は Annotations.Add メソッドを使用して追加され、コメントや付箋ですでに使用しているコレクションと統合されます
位置は X、Y、Width、Height (ポイント単位、72ポイント=1インチ) で設定するか、Rectangle を直接指定して設定します リンクが設置されているページとターゲットページの両方は、コンストラクタでゼロベースのインデックスで指定されます。
X、Y、Width、Height はすべて、設定するまで -1 を返します それらを設定しないと無効な注釈が生成されるため、常にクリック可能なエリアを割り当ててください。using IronPdf;
using IronPdf.Annotations;
// Load an existing multi-page PDF
PdfDocument pdf = PdfDocument.FromFile("multipage.pdf");
// Create a clickable link on page 1 (index 0) that jumps to page 6 (index 5).
// Page indexes are zero-based. The default DestinationType (Page) fits the
// whole destination page in the viewer when the link is clicked.
LinkAnnotation link = new LinkAnnotation(pageIndex: 0, destinationPageIndex: 5)
{
X = 72, // points from the LEFT edge of the page (72 points = 1 inch)
Y = 700, // BOTTOM edge of the clickable area (PDF origin is bottom-left)
Width = 200,
Height = 20,
Contents = "Go to Chapter 6"
};
// LinkAnnotation lives in the same collection as TextAnnotation
pdf.Annotations.Add(link);
pdf.SaveAs("internal-link.pdf");using IronPdf;
using IronPdf.Annotations;
// Load an existing multi-page PDF
PdfDocument pdf = PdfDocument.FromFile("multipage.pdf");
// Create a clickable link on page 1 (index 0) that jumps to page 6 (index 5).
// Page indexes are zero-based. The default DestinationType (Page) fits the
// whole destination page in the viewer when the link is clicked.
LinkAnnotation link = new LinkAnnotation(pageIndex: 0, destinationPageIndex: 5)
{
X = 72, // points from the LEFT edge of the page (72 points = 1 inch)
Y = 700, // BOTTOM edge of the clickable area (PDF origin is bottom-left)
Width = 200,
Height = 20,
Contents = "Go to Chapter 6"
};
// LinkAnnotation lives in the same collection as TextAnnotation
pdf.Annotations.Add(link);
pdf.SaveAs("internal-link.pdf");Imports IronPdf
Imports IronPdf.Annotations
' Load an existing multi-page PDF
Dim pdf As PdfDocument = PdfDocument.FromFile("multipage.pdf")
' Create a clickable link on page 1 (index 0) that jumps to page 6 (index 5).
' Page indexes are zero-based. The default DestinationType (Page) fits the
' whole destination page in the viewer when the link is clicked.
Dim link As New LinkAnnotation(pageIndex:=0, destinationPageIndex:=5) With {
.X = 72, ' points from the LEFT edge of the page (72 points = 1 inch)
.Y = 700, ' BOTTOM edge of the clickable area (PDF origin is bottom-left)
.Width = 200,
.Height = 20,
.Contents = "Go to Chapter 6"
}
' LinkAnnotation lives in the same collection as TextAnnotation
pdf.Annotations.Add(link)
pdf.SaveAs("internal-link.pdf")Imports IronPdf
Imports IronPdf.Annotations
' Load an existing multi-page PDF
Dim pdf As PdfDocument = PdfDocument.FromFile("multipage.pdf")
' Create a clickable link on page 1 (index 0) that jumps to page 6 (index 5).
' Page indexes are zero-based. The default DestinationType (Page) fits the
' whole destination page in the viewer when the link is clicked.
Dim link As New LinkAnnotation(pageIndex:=0, destinationPageIndex:=5) With {
.X = 72, ' points from the LEFT edge of the page (72 points = 1 inch)
.Y = 700, ' BOTTOM edge of the clickable area (PDF origin is bottom-left)
.Width = 200,
.Height = 20,
.Contents = "Go to Chapter 6"
}
' LinkAnnotation lives in the same collection as TextAnnotation
pdf.Annotations.Add(link)
pdf.SaveAs("internal-link.pdf")配置以外にも、外観やメタデータを制御するいくつかのプロパティがあります。Color はリンクの境界線の色を設定し、Contents は説明文またはツールチップを提供し、Title は注釈の名前を設定します。 既存のコンテンツに透明なクリックオーバーレイを設置するには、Color を設定せず、Hidden = true を設定します (本ガイド後半で説明)
リンク注釈とテキスト注釈の違いは何ですか?
TextAnnotationは「付箋メモ」です:クリックされるとテキストを表示するコメントアイコンです。 LinkAnnotationはナビゲーションコントロールで、読者をターゲットページにジャンプさせる無視可能または境界のあるクリック可能な領域です。 両者は Annotations コレクションと、同じ Add、RemoveAt、RemoveAllAnnotationsForPage、Clear 操作を共有するので、コメントとナビゲーションリンクを同じドキュメント内で混在して管理可能です
LinkAnnotationは同じファイル内のページをターゲットとしているため、IronPDFのアウトラインとブックマーク(ビューワーのサイドバーナビゲーションツリーを構築するもの)およびHTML-to-PDFレンダリングの自動生成された目次機能を補完します。 サイドバーにはブックマークを使用し、レンダリングされたHTMLにはTOC機能を使用し、LinkAnnotationは既存のPDF上でクリック可能なホットスポットが必要な場合に使用します。
目的地でリーダーが見るものをどのように制御するか?
DestinationType プロパティは、リンクをクリックした際のターゲットページの表示方法を制御するために既存の BookmarkDestinations 列挙型を使用します デフォルトはBookmarkDestinations.Pageで、ウィンドウに目的地ページ全体を合わせます。 他の値は、位置へのスクロールやズームレベルを設定したり、特定の矩形をフィットさせたりするために、DestinationTop、DestinationLeft、DestinationRight、DestinationBottom、DestinationZoom 座標を使用します
BookmarkDestinations 値 | クリックされたときの動作 | 使用された目的地の座標 |
|---|---|---|
Page (デフォルト) | ウィンドウに目的地ページ全体を合わせる。 | none |
PageY | 垂直位置にスクロールする; 全幅を表示。 | DestinationTop |
PageX | 水平位置にスクロールする; 全高を表示。 | DestinationLeft |
PageZoom | 位置に移動し そして ズームレベルを設定します。 | DestinationLeft、DestinationTop、DestinationZoom |
PageRect | ページ上の特定の長方形に合わせます。 | DestinationLeft、DestinationBottom、DestinationRight、DestinationTop |
PageBounds | ページのバウンディングボックスに従ってページを合わせます。 | none |
PageBoundsY | ページのバウンディングボックスに基づいて、PageYと同じ。 | DestinationTop |
PageBoundsX | ページのバウンディングボックスに基づいて、PageXと同じ。 | DestinationLeft |
DestinationZoom = 0 は「現在のズームを引き継ぐ」という意味であり、ゼロズームではありません 150%の150などの値を設定してください。using IronPdf;
using IronPdf.Annotations;
using IronPdf.Bookmarks;
PdfDocument pdf = PdfDocument.FromFile("multipage.pdf");
// 1. Scroll to a specific vertical position on the destination page (full width shown)
LinkAnnotation scrollLink = new LinkAnnotation(0, 2)
{
X = 72, Y = 680, Width = 300, Height = 16,
DestinationType = BookmarkDestinations.PageY,
DestinationTop = 400 // scroll so y=400 sits at the top of the view
};
pdf.Annotations.Add(scrollLink);
// 2. Jump to a position AND set the zoom level
LinkAnnotation zoomLink = new LinkAnnotation(0, 3, "Zoom to figure")
{
X = 72, Y = 650, Width = 200, Height = 16,
DestinationType = BookmarkDestinations.PageZoom,
DestinationLeft = 100,
DestinationTop = 500,
DestinationZoom = 150 // 150% zoom; use 0 to inherit the current zoom
};
pdf.Annotations.Add(zoomLink);
// 3. Fit a specific rectangle on the destination page
LinkAnnotation rectLink = new LinkAnnotation(0, 4)
{
X = 72, Y = 620, Width = 200, Height = 16,
DestinationType = BookmarkDestinations.PageRect,
DestinationLeft = 50,
DestinationBottom = 100,
DestinationRight = 550,
DestinationTop = 700
};
pdf.Annotations.Add(rectLink);
pdf.SaveAs("link-destinations.pdf");using IronPdf;
using IronPdf.Annotations;
using IronPdf.Bookmarks;
PdfDocument pdf = PdfDocument.FromFile("multipage.pdf");
// 1. Scroll to a specific vertical position on the destination page (full width shown)
LinkAnnotation scrollLink = new LinkAnnotation(0, 2)
{
X = 72, Y = 680, Width = 300, Height = 16,
DestinationType = BookmarkDestinations.PageY,
DestinationTop = 400 // scroll so y=400 sits at the top of the view
};
pdf.Annotations.Add(scrollLink);
// 2. Jump to a position AND set the zoom level
LinkAnnotation zoomLink = new LinkAnnotation(0, 3, "Zoom to figure")
{
X = 72, Y = 650, Width = 200, Height = 16,
DestinationType = BookmarkDestinations.PageZoom,
DestinationLeft = 100,
DestinationTop = 500,
DestinationZoom = 150 // 150% zoom; use 0 to inherit the current zoom
};
pdf.Annotations.Add(zoomLink);
// 3. Fit a specific rectangle on the destination page
LinkAnnotation rectLink = new LinkAnnotation(0, 4)
{
X = 72, Y = 620, Width = 200, Height = 16,
DestinationType = BookmarkDestinations.PageRect,
DestinationLeft = 50,
DestinationBottom = 100,
DestinationRight = 550,
DestinationTop = 700
};
pdf.Annotations.Add(rectLink);
pdf.SaveAs("link-destinations.pdf");Imports IronPdf
Imports IronPdf.Annotations
Imports IronPdf.Bookmarks
Dim pdf As PdfDocument = PdfDocument.FromFile("multipage.pdf")
' 1. Scroll to a specific vertical position on the destination page (full width shown)
Dim scrollLink As New LinkAnnotation(0, 2) With {
.X = 72,
.Y = 680,
.Width = 300,
.Height = 16,
.DestinationType = BookmarkDestinations.PageY,
.DestinationTop = 400 ' scroll so y=400 sits at the top of the view
}
pdf.Annotations.Add(scrollLink)
' 2. Jump to a position AND set the zoom level
Dim zoomLink As New LinkAnnotation(0, 3, "Zoom to figure") With {
.X = 72,
.Y = 650,
.Width = 200,
.Height = 16,
.DestinationType = BookmarkDestinations.PageZoom,
.DestinationLeft = 100,
.DestinationTop = 500,
.DestinationZoom = 150 ' 150% zoom; use 0 to inherit the current zoom
}
pdf.Annotations.Add(zoomLink)
' 3. Fit a specific rectangle on the destination page
Dim rectLink As New LinkAnnotation(0, 4) With {
.X = 72,
.Y = 620,
.Width = 200,
.Height = 16,
.DestinationType = BookmarkDestinations.PageRect,
.DestinationLeft = 50,
.DestinationBottom = 100,
.DestinationRight = 550,
.DestinationTop = 700
}
pdf.Annotations.Add(rectLink)
pdf.SaveAs("link-destinations.pdf")Imports IronPdf
Imports IronPdf.Annotations
Imports IronPdf.Bookmarks
Dim pdf As PdfDocument = PdfDocument.FromFile("multipage.pdf")
' 1. Scroll to a specific vertical position on the destination page (full width shown)
Dim scrollLink As New LinkAnnotation(0, 2) With {
.X = 72,
.Y = 680,
.Width = 300,
.Height = 16,
.DestinationType = BookmarkDestinations.PageY,
.DestinationTop = 400 ' scroll so y=400 sits at the top of the view
}
pdf.Annotations.Add(scrollLink)
' 2. Jump to a position AND set the zoom level
Dim zoomLink As New LinkAnnotation(0, 3, "Zoom to figure") With {
.X = 72,
.Y = 650,
.Width = 200,
.Height = 16,
.DestinationType = BookmarkDestinations.PageZoom,
.DestinationLeft = 100,
.DestinationTop = 500,
.DestinationZoom = 150 ' 150% zoom; use 0 to inherit the current zoom
}
pdf.Annotations.Add(zoomLink)
' 3. Fit a specific rectangle on the destination page
Dim rectLink As New LinkAnnotation(0, 4) With {
.X = 72,
.Y = 620,
.Width = 200,
.Height = 16,
.DestinationType = BookmarkDestinations.PageRect,
.DestinationLeft = 50,
.DestinationBottom = 100,
.DestinationRight = 550,
.DestinationTop = 700
}
pdf.Annotations.Add(rectLink)
pdf.SaveAs("link-destinations.pdf")既存のテキスト上にリンクを配置するにはどうすればよいですか?
ページ上に既に存在するテキストにクリック可能なリンクをオーバーレイするには、PdfPage.TextChunks でテキストを抽出し、各チャンクのBoundingBox を使用してリンクの大きさを決定します PDF の座標はページの左下から始まるため、BoundingBox.Bottom を Y に割り当てるべきであり、BoundingBox.Top に割り当てると、クリック可能な領域が可視テキスト上に配置されます 可視ボーダーを削除するためにHidden = trueを設定し、リンクをレンダリングされたテキストの上に無視可能に座らせます。
これは静的な印刷された目次をナビゲート可能なものに変えるための基盤です。 以下の例では、目次ページをスキャンし、エントリをそのテキストで一致させ、適切なページにジャンプする無視可能なLinkAnnotationをオーバーレイします。
using IronPdf;
using IronPdf.Annotations;
using IronPdf.Bookmarks;
using System;
using System.Collections.Generic;
PdfDocument pdf = PdfDocument.FromFile("report-with-toc.pdf");
// Zero-based index of the page that holds the table-of-contents text
int tocPageIndex = 1;
// Map each TOC entry's leading text to the page index it should jump to
var tocEntries = new Dictionary<string, int>
{
{ "Introduction", 2 },
{ "Methodology", 4 },
{ "Results", 6 },
{ "Conclusion", 9 },
};
// Walk the text chunks on the TOC page and overlay a clickable link on each match
foreach (var chunk in pdf.Pages[tocPageIndex].TextChunks)
{
string text = chunk.Contents.Trim();
foreach (var entry in tocEntries)
{
if (!text.StartsWith(entry.Key)) continue;
var box = chunk.BoundingBox;
pdf.Annotations.Add(new LinkAnnotation(tocPageIndex, entry.Value)
{
X = (int)box.Left,
Y = (int)box.Bottom, // Bottom, NOT Top (PDF origin is bottom-left)
Width = (int)Math.Max(box.Width, 400),
Height = (int)Math.Abs(box.Top - box.Bottom),
DestinationType = BookmarkDestinations.PageY,
DestinationTop = 792, // top of a US Letter page
Hidden = true // invisible overlay on the existing TOC text
});
break;
}
}
pdf.SaveAs("clickable-toc.pdf");using IronPdf;
using IronPdf.Annotations;
using IronPdf.Bookmarks;
using System;
using System.Collections.Generic;
PdfDocument pdf = PdfDocument.FromFile("report-with-toc.pdf");
// Zero-based index of the page that holds the table-of-contents text
int tocPageIndex = 1;
// Map each TOC entry's leading text to the page index it should jump to
var tocEntries = new Dictionary<string, int>
{
{ "Introduction", 2 },
{ "Methodology", 4 },
{ "Results", 6 },
{ "Conclusion", 9 },
};
// Walk the text chunks on the TOC page and overlay a clickable link on each match
foreach (var chunk in pdf.Pages[tocPageIndex].TextChunks)
{
string text = chunk.Contents.Trim();
foreach (var entry in tocEntries)
{
if (!text.StartsWith(entry.Key)) continue;
var box = chunk.BoundingBox;
pdf.Annotations.Add(new LinkAnnotation(tocPageIndex, entry.Value)
{
X = (int)box.Left,
Y = (int)box.Bottom, // Bottom, NOT Top (PDF origin is bottom-left)
Width = (int)Math.Max(box.Width, 400),
Height = (int)Math.Abs(box.Top - box.Bottom),
DestinationType = BookmarkDestinations.PageY,
DestinationTop = 792, // top of a US Letter page
Hidden = true // invisible overlay on the existing TOC text
});
break;
}
}
pdf.SaveAs("clickable-toc.pdf");Imports IronPdf
Imports IronPdf.Annotations
Imports IronPdf.Bookmarks
Imports System
Imports System.Collections.Generic
Dim pdf As PdfDocument = PdfDocument.FromFile("report-with-toc.pdf")
' Zero-based index of the page that holds the table-of-contents text
Dim tocPageIndex As Integer = 1
' Map each TOC entry's leading text to the page index it should jump to
Dim tocEntries As New Dictionary(Of String, Integer) From {
{"Introduction", 2},
{"Methodology", 4},
{"Results", 6},
{"Conclusion", 9}
}
' Walk the text chunks on the TOC page and overlay a clickable link on each match
For Each chunk In pdf.Pages(tocPageIndex).TextChunks
Dim text As String = chunk.Contents.Trim()
For Each entry In tocEntries
If Not text.StartsWith(entry.Key) Then Continue For
Dim box = chunk.BoundingBox
pdf.Annotations.Add(New LinkAnnotation(tocPageIndex, entry.Value) With {
.X = CInt(box.Left),
.Y = CInt(box.Bottom), ' Bottom, NOT Top (PDF origin is bottom-left)
.Width = CInt(Math.Max(box.Width, 400)),
.Height = CInt(Math.Abs(box.Top - box.Bottom)),
.DestinationType = BookmarkDestinations.PageY,
.DestinationTop = 792, ' top of a US Letter page
.Hidden = True ' invisible overlay on the existing TOC text
})
Exit For
Next
Next
pdf.SaveAs("clickable-toc.pdf")Imports IronPdf
Imports IronPdf.Annotations
Imports IronPdf.Bookmarks
Imports System
Imports System.Collections.Generic
Dim pdf As PdfDocument = PdfDocument.FromFile("report-with-toc.pdf")
' Zero-based index of the page that holds the table-of-contents text
Dim tocPageIndex As Integer = 1
' Map each TOC entry's leading text to the page index it should jump to
Dim tocEntries As New Dictionary(Of String, Integer) From {
{"Introduction", 2},
{"Methodology", 4},
{"Results", 6},
{"Conclusion", 9}
}
' Walk the text chunks on the TOC page and overlay a clickable link on each match
For Each chunk In pdf.Pages(tocPageIndex).TextChunks
Dim text As String = chunk.Contents.Trim()
For Each entry In tocEntries
If Not text.StartsWith(entry.Key) Then Continue For
Dim box = chunk.BoundingBox
pdf.Annotations.Add(New LinkAnnotation(tocPageIndex, entry.Value) With {
.X = CInt(box.Left),
.Y = CInt(box.Bottom), ' Bottom, NOT Top (PDF origin is bottom-left)
.Width = CInt(Math.Max(box.Width, 400)),
.Height = CInt(Math.Abs(box.Top - box.Bottom)),
.DestinationType = BookmarkDestinations.PageY,
.DestinationTop = 792, ' top of a US Letter page
.Hidden = True ' invisible overlay on the existing TOC text
})
Exit For
Next
Next
pdf.SaveAs("clickable-toc.pdf")バック・トゥ・トップまたは同じページリンクを作成できますか?
はい。 pageIndex と destinationPageIndex が等しい同一ページリンクは完全にサポートされており、「トップに戻る」ボタンを構築する一般的な方法です 同一ページリンクを DestinationType = BookmarkDestinations.PageY と高い DestinationTop 値と組み合わせることで、クリックするとリーダーが現在のページのトップにスクロールします 長いレポートに一貫したトップへのリターンコントロールを提供するために、各ページのフットに同じリンクを追加します。
PDF注釈を扱うベストプラクティスは何ですか?
アプリケーションにアノテーション機能を実装する際には、以下のベストプラクティスを考慮してください:
- 座標系: PDFの座標はページの左下隅から始まり、多くのUIフレームワークのように左上起点ではありません。 この違いを考慮した座標計算を行うようにしてください。
- パフォーマンス最適化: 複数の注釈を追加する際には、各追加後に保存するのではなく、一括で操作を行うことを検討してください。 このアプローチは、特に大きなPDFファイルを扱う際にパフォーマンスを向上させます。
- 注釈の可視性: すべてのPDFビューアが注釈を同じように表示するわけではありません。 注釈付きPDFをさまざまなビューアでテストし、一貫したユーザーエクスペリエンスを確保します。
- フォームとの統合: 注釈は、フォーム構造を変更することなく、PDFフォームに文脈的なヘルプや指示を提供します。
- セキュリティの考慮事項: 機密文書を扱う際には、注釈に機密情報が含まれる可能性があることを忘れないでください。 注釈された内容を保護するために適切なセキュリティ対策を実施してください。
- アクセシビリティ: 障害を持つユーザーに追加のコンテキストを提供するために、文書のアクセシビリティを向上させる注釈の追加を検討してください。 これはアクセス可能な文書のためのPDF/UA準拠要件に適合します。
注釈のために座標系が重要なのはなぜですか?
左下隅を原点とするPDF座標は、左上の原点システムに慣れた開発者を混乱させる可能性があります。 不正確な座標計算により、注釈が予期せぬ場所に配置され、重要なコンテンツが不明瞭になったり、ページ外に表示されたりする可能性があります。 UIフレームワークやユーザー入力システムと統合する場合は、常に座標を適切に変換してください。
座標系を理解することは、クリックトゥアノテーション機能のような機能を実装する場合や、ユーザーインタラクションから画面座標をPDF座標に変換する場合に、さらに重要になります。 複雑な配置要件のために、あらゆる閲覧条件下でも注釈が正しく表示されるようにする、IronPDFのビューポートとズーム機能の使用を検討してください。
複数の注釈を追加する際にパフォーマンスを最適化するにはどうすればよいですか?
複数の注釈を追加する場合は、ドキュメントを保存する前に、すべての注釈をコレクションに追加して、操作をバッチ化してください。 このアプローチにより、ファイルI/O操作が削減され、特に大きなPDFや複数の文書を連続して処理する場合のパフォーマンスが大幅に向上します。 一括操作中のユーザーエクスペリエンスを向上させるために、進捗インジケータの実装を検討してください。
// Example of batch annotation processing
var annotations = new List<TextAnnotation>();
for (int i = 0; i < 100; i++)
{
annotations.Add(new TextAnnotation(0)
{
Title = $"Note {i}",
Contents = $"Content for note {i}",
X = 50 + (i * 10),
Y = 700 - (i * 20)
});
}
// Add all annotations at once
foreach (var annotation in annotations)
{
pdf.Annotations.Add(annotation);
}
// Save once after all additions
pdf.SaveAs("batch-annotated.pdf");// Example of batch annotation processing
var annotations = new List<TextAnnotation>();
for (int i = 0; i < 100; i++)
{
annotations.Add(new TextAnnotation(0)
{
Title = $"Note {i}",
Contents = $"Content for note {i}",
X = 50 + (i * 10),
Y = 700 - (i * 20)
});
}
// Add all annotations at once
foreach (var annotation in annotations)
{
pdf.Annotations.Add(annotation);
}
// Save once after all additions
pdf.SaveAs("batch-annotated.pdf");Imports System.Collections.Generic
' Example of batch annotation processing
Dim annotations As New List(Of TextAnnotation)()
For i As Integer = 0 To 99
annotations.Add(New TextAnnotation(0) With {
.Title = $"Note {i}",
.Contents = $"Content for note {i}",
.X = 50 + (i * 10),
.Y = 700 - (i * 20)
})
Next
' Add all annotations at once
For Each annotation In annotations
pdf.Annotations.Add(annotation)
Next
' Save once after all additions
pdf.SaveAs("batch-annotated.pdf")Imports System.Collections.Generic
' Example of batch annotation processing
Dim annotations As New List(Of TextAnnotation)()
For i As Integer = 0 To 99
annotations.Add(New TextAnnotation(0) With {
.Title = $"Note {i}",
.Contents = $"Content for note {i}",
.X = 50 + (i * 10),
.Y = 700 - (i * 20)
})
Next
' Add all annotations at once
For Each annotation In annotations
pdf.Annotations.Add(annotation)
Next
' Save once after all additions
pdf.SaveAs("batch-annotated.pdf")高ボリュームシナリオでさらに良いパフォーマンスを得るためには、非同期処理やマルチスレッド技術を使用して、並行して注釈操作を処理することを考慮してください。
ビューワー間の互換性を考慮する際に何を考えるべきですか?
PDFビューアによって、アイコンのスタイル、ポップアップの動作、位置の癖が異なる注釈が表示されることがあります。 Adobe Acrobat、Chrome、Edge、モバイルPDFリーダーなどの一般的なビューアで注釈付きPDFを常にテストし、注釈が正しく表示され、ユーザーが使用する可能性のあるプラットフォーム全体で機能することを確認します。
ビューアによっては、すべての注釈タイプに対応していない場合や、表示が異なる場合があります。 互換性を最大限に保つため、標準的な注釈タイプにこだわり、ビューア固有の機能に依存しないようにしてください。 AzureやAWSなどの特定の環境にデプロイする場合、ターゲット環境のデフォルトPDFビューアで注釈をテストして一貫した動作を確認してください。
次に何ができるのかを見てみましょうか? こちらのチュートリアルページをご覧ください:PDFを編集
よくある質問
C#でIronPDFを使用してPDFに注釈を追加するにはどうすればよいですか?
C#でIronPDFを使用して注釈を追加するには、Annotations.Addメソッドを使用し、TextAnnotationクラスを使用して注釈のパラメータを定義します。PDFドキュメントをロードし、タイトル、内容、および座標などの属性を指定して注釈インスタンスを作成し、それをAnnotations.Addメソッドに渡します。
IronPDFを使用してどのような種類の注釈をPDFに追加できますか?
IronPDFはテキストコメントや付箋を含むさまざまな注釈タイプをサポートしています。 PDFの特定のセクションにコメント、フィードバック、または追加情報を提供するために注釈を追加することで、コラボレーションやドキュメントレビューのワークフローを強化できます。
IronPDFを使用してPDF内の既存の注釈をどのように編集できますか?
IronPDFで注釈を編集するには、PDFドキュメントからAnnotationsコレクションにアクセスします。目的の注釈を見つけて、そのプロパティ、たとえばTitle、Contents、X、またはYを更新して、内容や位置を変更します。変更を保存してドキュメントを更新します。
ビジネスワークフローにおいてPDFの注釈はどのような利点がありますか?
PDF注釈は、元のコンテンツを変更せずにドキュメントにフィードバック、文脈、またはリマインダーを追加できるため、コラボレーションを強化します。これにより、ドキュメントのレビュー、契約のコラボレーション、品質保証プロセス中のコミュニケーションが促進されます。
注釈を追加する際、PDFの座標はどのように機能しますか?
PDFの座標はページの左下隅から始まります。X座標とY座標を使用して注釈を配置するときは、注釈を正確に配置するためにこの原点で計算を行うことを確認してください。US LetterやA4などの標準的なページサイズも、精度を考慮する必要があります。
IronPDFを使用してPDFから注釈を削除できますか?
はい、IronPDFを使用して特定の注釈を削除するためのRemoveAt、ページレベルで削除するためのRemoveAllAnnotationsForPage、またはドキュメントからすべての注釈を削除するためのClearなどのメソッドを使用して注釈を削除できます。
IronPDFを使用してテキスト注釈を追加する際にカスタマイズできるプロパティは何ですか?
TextAnnotationクラスのさまざまなプロパティ、たとえばTitle、Contents、X、Y、PageIndex、Subject、Icon、Openなどをカスタマイズできます。これらのプロパティはPDF内での注釈の表示と位置を制御します。
IronPDFを使用してPDF内にクリック可能な内部リンクをどのように追加できますか?
内部リンクを作成するには、IronPDFのLinkAnnotationクラスを使用します。位置とサイズの座標でクリック可能な領域を定義し、ターゲットページを設定します。DestinationTypeなどのプロパティで外観や目的地の動作をカスタマイズできます。
異なるリーダーで注釈付きのPDFをテストすることがなぜ重要ですか?
異なるPDFリーダーは注釈を異なった方法でレンダリングし、アイコンのスタイルやポップアップの動作に影響を与えるため、Adobe Acrobat、Chrome、モバイルリーダーなどの人気のあるビューアでテストすることで一貫した見た目と機能性をプラットフォーム間で確保することができます。
IronPDFを使用したPDF注釈の作業におけるベストプラクティスは何ですか?
ベストプラクティスには、左下から始まる座標系の理解、注釈追加の一括処理によるパフォーマンスの最適化、クロスビューア互換性の確保、および注釈付きコンテンツのセキュリティ対策の考慮が含まれます。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。