# C#ですべてのPDF DOMオブジェクトにアクセスする方法
C#でPDF DOMオブジェクトにアクセスするには、IronPDFの`ObjectModel`プロパティを使用してください。これによりPDFドキュメント内のテキスト、画像、およびパスオブジェクトへのプログラムによるアクセスが可能となり、要素を直接読み込み、変更、翻訳、スケーリング、および削除することができます。
*as-heading:2(クイックスタート: IronPDF を使用した PDF DOM 要素へのアクセスと更新)*
IronPDFのDOMアクセス機能を使ってPDFドキュメントを操作しましょう。 このガイドでは、PDF DOMにアクセスし、ページを選択し、テキストオブジェクトを変更する方法を示します。 PDFを読み込み、目的のページにアクセスし、数行のコードでコンテンツを更新します。
```cs
:title=Access and modify PDF DOM objects in one line!
var objs = IronPdf.ChromePdfRenderer.RenderUrlAsPdf("https://example.com").Pages.First().ObjectModel;
```
<div class="hsg-featured-snippet">
<h3>最小限のワークフロー(5ステップ)</h3>
<ol>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronPdf">PDFのDOMオブジェクトにアクセスするためのC#ライブラリをダウンロードする</a>。</li>
<li>ターゲットとするPDFドキュメントをインポートまたはレンダリングする</li>
<li>PDFの<code>Pages</code>コレクションにアクセスし、必要なページを選択します</li>
<li><strong>ObjectModel</strong> プロパティを使用して、DOM オブジェクトを表示し、操作します。</li>
<li>修正されたPDFドキュメントを保存またはエクスポートする</li>
</ol>
</div>
## PDFのDOMオブジェクトにアクセスするには?
`PdfPage`オブジェクトからアクセスできます。 まず、対象のPDFをインポートし、その`Pages`プロパティにアクセスします。 そこから、任意のページを選択して`ObjectModel`プロパティにアクセスしてください。 これは、HTMLのDOM要素を扱うのと同様に、プログラム的にPDFコンテンツと対話することを可能にします。
PDF DOM オブジェクトを扱うとき、PDF 文書の基本構造にアクセスします。 これには、テキスト要素、画像、ベクターグラフィックス(`paths`)、およびPDFの視覚表現を構成するその他のコンテンツが含まれます。 IronPDFはC#アプリケーションと統合するPDF操作へのオブジェクト指向のアプローチを提供します。
```csharp
using IronPdf;
using System.Linq;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF from a URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
// Access DOM Objects
var objects = pdf.Pages.First().ObjectModel;
```
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/pdf/how-to/access-pdf-dom-object/debug.webp" alt="TextObjectsコレクションとBoundingBox座標と変換プロパティを表示するIronPDFデバッガ" class="img-responsive add-shadow" />
</div>
</div>
`TextObject`が含まれています。 各オブジェクトには、そのページインデックス、バウンディングボックス、`Translation`に関する情報が含まれています。 この情報は変更可能です。 [レンダリングオプション](https://ironpdf.com/how-to/rendering-options/)では、これらのオブジェクトの表示方法をカスタマイズできます。 [カスタムマージン](https://ironpdf.com/how-to/custom-margins/)を使用する場合、オブジェクトの位置を理解することが重要です。
**`<ImageObject>`:**
- `Height`: 画像の高さ
- `Width`: 画像の幅
- `ExportBytesAsJpg`: 画像をJPGバイト配列としてエクスポートする方法
**`<PathObject>`:**
- `FillColor`: パスの塗りつぶし色
- `StrokeColor`: パスのストローク色
- `Points`: パスを定義するポイントのコレクション
**`<TextObject>`:**
- `Color`: テキストの色
- `Contents`: 実際の`Text`コンテンツ
各オブジェクトタイプは、コンテンツタイプに合わせたメソッドとプロパティを提供します。 [テキストや画像を抽出したり](https://ironpdf.com/how-to/extract-text-and-images/)、特定のコンテンツを変更する必要がある場合、これらのオブジェクトはきめ細かなコントロールを提供します。 [PDF フォーム](https://ironpdf.com/how-to/create-forms/)で、プログラム的にフォームフィールドを操作する必要がある場合に役立ちます。
### グリフ情報とバウンディングボックスを取得するにはどうすればよいですか?
カスタムフォントで正確なグリフを指定する場合、バウンディングボックスとグリフ情報の取得が不可欠です。 IronPDFは既存のPDFに[テキストやビットマップ](https://ironpdf.com/how-to/draw-text-and-bitmap/)を描画する際、ピクセルパーフェクトな位置決めのためにこの情報を提供します。
`PdfPage`オブジェクトを使用します。 その後、`TextObjects`コレクションにアクセスします。 `GetGlyphInfo`メソッドを呼び出して、グリフとバウンディングボックスの情報を取得します。
```cs
using IronPdf;
using System.Linq;
PdfDocument pdf = PdfDocument.FromFile("invoice.pdf");
var glyph = pdf.Pages.First().ObjectModel.TextObjects.First().GetGlyphInfo();
```
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/pdf/how-to/access-pdf-dom-object/glyphinformation.webp" alt="座標、境界、テキスト内容の詳細を含むPDFグリフオブジェクトプロパティを表示するデバッガ" class="img-responsive add-shadow" />
</div>
</div>
グリフ情報には、位置データ、フォントメトリクス、高度なPDF操作のための文字固有の詳細が含まれます。 これにより、複雑な組版やレイアウト要件を扱うPDF処理アプリケーションの作成が可能になります。 [カスタムフォント](https://ironpdf.com/how-to/manage-fonts/)を使用する場合、このグリフレベルのアクセスにより、システム間で正確なレンダリングが保証されます。
<hr />
## PDFオブジェクトを翻訳するにはどうすればよいですか?
テキストや画像などの要素を再配置することで、PDFのレイアウトを調整します。 オブジェクトを移動するには、その`Translate`プロパティを変更します。 この機能はIronPDFの[PDF変換機能](https://ironpdf.com/how-to/transform-pdf-pages/)の一部です。
以下の例では、CSS Flexboxを使用してHTMLをレンダリングし、テキストを中央に配置しています。 最初の`Translate`プロパティに割り当てることでそれを変換します。 これにより、テキストは右に200ポイント、上に150ポイント移動します。その他の例については、[translate PDF objects example page](https://ironpdf.com/examples/translate-pdf-objects/)をご覧ください。
### オブジェクトを翻訳するにはどのコードを使用すればよいですか?
```csharp
using IronPdf;
using System.Drawing;
using System.Linq;
// Setup the Renderer
var renderer = new ChromePdfRenderer();
// We use CSS Flexbox to perfectly center the text vertically and horizontally.
var html = @"
<div style='display: flex; justify-content: center; align-items: center; font-size: 48px;'>
Centered
</div>";
// Render the HTML to a PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
// Save the original PDF to see the "before" state
pdf.SaveAs("BeforeTranslate.pdf");
// Access the first text object on the first page
// In this simple HTML, this will be our "Centered" text block.
var textObject = pdf.Pages.First().ObjectModel.TextObjects.First();
// Apply the translation
// This moves the object 200 points to the right and 150 points up from its original position.
textObject.Translate = new PointF(200, 150);
// Save the modified PDF to see the "after" state
pdf.SaveAs("AfterTranslate.pdf");
```
### 翻訳結果はどのようになりますか?
出力では、"Centered"が元の位置から右に200ポイント、上に150ポイントシフトしています。
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/pdf/how-to/access-pdf-dom-object/translate.webp" alt="テキストの位置と書式が保持されたPDF翻訳前後の比較" class="img-responsive add-shadow" />
</div>
</div>
翻訳作業では、フォント、サイズ、色などのオブジェクトの元のプロパティを維持し、位置のみを変更します。 これは、見た目に影響を与えないレイアウト調整に最適です。 この機能は、動的に生成されたコンテンツを再配置するときに、[ヘッダーとフッター](https://ironpdf.com/how-to/headers-and-footers/)で動作します。
<hr />
## PDFオブジェクトを拡大縮小するには?
PDFオブジェクトをリサイズするには、`Scale`プロパティを使用します。 このプロパティは乗数として機能します。 1より大きい値はサイズが大きくなり、0から1の間の値は小さくなります。 動的なレイアウトや、ページの寸法に合わせてコンテンツを調整するには、スケーリングが不可欠です。 その他の例については、[スケールPDFオブジェクトガイド](https://ironpdf.com/examples/scale-pdf-objects/)を参照してください。
この例では、画像を含むHTMLをレンダリングしています。 最初の`Scale`に割り当てることで70%にスケールします。
### PDFオブジェクトをスケーリングするコードは何ですか?
```csharp
using IronPdf;
using System.Linq;
// Setup the Renderer
var renderer = new ChromePdfRenderer();
// The image is placed in a div to give it some space on the page.
string html = @"<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTi8LuOR6_A98euPLs-JRwoLU7Nc31nVP15rw&s'>";
// Render the HTML to a PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
// Save the PDF before scaling for comparison
pdf.SaveAs("BeforeScale.pdf");
// Access the first image object on the first page
var image = pdf.Pages.First().ObjectModel.ImageObjects.First();
// We scale the image to 70% of its original size on both the X and Y axes.
image.Scale = new System.Drawing.PointF(0.7f, 0.7f);
// Save the modified PDF to see the result
pdf.SaveAs("AfterScale.pdf");
```
X軸とY軸にそれぞれ異なるスケーリング係数を適用して、不均一なスケーリングを行います。 これは、コンテンツを特定の次元に当てはめるのに便利です。 [カスタム用紙サイズ](https://ironpdf.com/how-to/custom-paper-size/)で作業する場合、拡大縮小することで、コンテンツがページの境界内に収まるようにします。
### スケーリングは実際にはどのようなものですか?
出力は元のサイズの70%にスケーリングされた画像を示しています。
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/pdf/how-to/access-pdf-dom-object/scale.webp" alt="PDFの拡大縮小デモ:IRONのロゴを大きなサイズ(左)から小さなサイズ(右)に拡大縮小したもの。" class="img-responsive add-shadow" />
</div>
</div>
<hr />
## どのように PDF オブジェクトを削除できますか?
PDF DOMコレクション、たとえば`TextObjects`にアクセスしてオブジェクトを削除します。 コレクションに対して`RemoveAt`を呼び出し、削除するオブジェクトのインデックスを渡します。 これは、コンテンツの再編集や文書の簡素化に役立ちます。 詳しくは[PDFオブジェクトの削除例](https://ironpdf.com/examples/remove-pdf-objects/)をご覧ください。
コードはBeforeScale.pdfを読み込み、最初のページから最初の画像を削除します。
### オブジェクトを削除するにはどのコードを使用すればよいですか?
```csharp
using IronPdf;
using System.Linq;
// Load the PDF file we created in the Scale example
PdfDocument pdf = PdfDocument.FromFile("BeforeScale.pdf");
// Access DOM Objects
var objects = pdf.Pages.First().ObjectModel;
// Remove first image
objects.ImageObjects.RemoveAt(0);
// Save the modified PDF
pdf.SaveAs("removedFirstImage.pdf");
```
### 複数のオブジェクトを削除するとどうなりますか?
残りのオブジェクトのインデックスは、削除後にシフトします。 複数のオブジェクトを削除する場合は、正しいインデックスを維持するために、逆順に削除してください。 このテクニックは、機密文書から[テキストを削除](https://ironpdf.com/how-to/redact-text/)するときに役立ちます。
## 複数の DOM 操作を組み合わせるにはどうすればよいですか?
IronPDFのDOMアクセスは高度な文書処理ワークフローを可能にします。 複雑な変換のための操作を組み合わせる:
### どのような場合に複合語を使うべきですか?
```csharp
// Example of combining multiple DOM operations
using IronPdf;
using System.Linq;
PdfDocument pdf = PdfDocument.FromFile("complex-document.pdf");
// Iterate through all pages
foreach (var page in pdf.Pages)
{
var objects = page.ObjectModel;
// Process text objects
foreach (var textObj in objects.TextObjects)
{
// Change color of specific text
if (textObj.Contents.Contains("Important"))
{
textObj.FillColor = IronSoftware.Drawing.Color.Red;
}
}
// Scale down all images by 50%
foreach (var imgObj in objects.ImageObjects)
{
imgObj.Scale = new System.Drawing.PointF(0.5f, 0.5f);
}
}
pdf.SaveAs("processed-document.pdf");
```
### 複合操作の一般的なユースケースは何ですか?
DOM 操作の組み合わせは、次のような場合に有効です:
1. **バッチ文書処理:** 文書のフォーマットを標準化したり、機密内容を削除する
2. **動的レポート生成:** レイアウトを制御しながら、リアルタイムデータでテンプレートPDFを修正する
3. **コンテンツ移行:** PDFからコンテンツを抽出し、新しいレイアウトに再編成する
4. **アクセシビリティの向上:** テキストサイズ、コントラスト、または間隔を変更して文書を強化する
これらの技術は、複雑な変更を扱う強力なPDF処理アプリケーションを可能にします。 ドキュメントのプロパティの管理については、[メタデータ管理ガイド](https://ironpdf.com/how-to/metadata/)を参照してください。
## DOMアクセスは他のPDF操作方法と比較してどうですか?
PDF DOMを使用することで、従来のアプローチにはない利点が得られます:
```csharp
// Example: Selective content modification based on criteria
using IronPdf;
using System.Linq;
PdfDocument report = PdfDocument.FromFile("quarterly-report.pdf");
foreach (var page in report.Pages)
{
var textObjects = page.ObjectModel.TextObjects;
// Highlight negative values in financial reports
foreach (var text in textObjects)
{
if (text.Contents.StartsWith("-$") || text.Contents.Contains("Loss"))
{
text.FillColor = IronSoftware.Drawing.Color.Red;
}
}
}
report.SaveAs("highlighted-report.pdf");
```
[HTMLからPDFへの変換](https://ironpdf.com/how-to/html-to-pdf-responsive-css/)だけでは、このようなきめ細かな制御は不可能であり、高度なPDF処理にはDOMアクセスが不可欠です。
次に何ができるのかを見てみましょうか? チュートリアルのページはこちらをご覧ください:[PDFを編集する](https://ironpdf.com/tutorials/csharp-edit-pdf-complete-tutorial/).
PDF DOM オブジェクトを扱うとき、PDF 文書の基本構造にアクセスします。 これには、テキスト要素、画像、ベクターグラフィックス(paths)、およびPDFの視覚表現を構成するその他のコンテンツが含まれます。 IronPDFはC#アプリケーションと統合するPDF操作へのオブジェクト指向のアプローチを提供します。
using IronPdf;using System.Linq;// Instantiate RendererChromePdfRenderer renderer = new ChromePdfRenderer();// Create a PDF from a URLPdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");// Access DOM Objectsvar objects = pdf.Pages.First().ObjectModel;
using IronPdf;
using System.Linq;
// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF from a URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
// Access DOM Objects
var objects = pdf.Pages.First().ObjectModel;
ImportsIronPdfImportsSystem.Linq' Instantiate RendererPrivate renderer As New ChromePdfRenderer()' Create a PDF from a URLPrivate pdf AsPdfDocument = renderer.RenderUrlAsPdf("https://ironpdf.com/")' Access DOM ObjectsPrivate objects = pdf.Pages.First().ObjectModel
Imports IronPdf
Imports System.Linq
' Instantiate Renderer
Private renderer As New ChromePdfRenderer()
' Create a PDF from a URL
Private pdf As PdfDocument = renderer.RenderUrlAsPdf("https://ironpdf.com/")
' Access DOM Objects
Private objects = pdf.Pages.First().ObjectModel
各オブジェクトタイプは、コンテンツタイプに合わせたメソッドとプロパティを提供します。 テキストや画像を抽出したり、特定のコンテンツを変更する必要がある場合、これらのオブジェクトはきめ細かなコントロールを提供します。 PDF フォームで、プログラム的にフォームフィールドを操作する必要がある場合に役立ちます。
using IronPdf;using System.Linq;PdfDocument pdf = PdfDocument.FromFile("invoice.pdf");var glyph = pdf.Pages.First().ObjectModel.TextObjects.First().GetGlyphInfo();
using IronPdf;
using System.Linq;
PdfDocument pdf = PdfDocument.FromFile("invoice.pdf");
var glyph = pdf.Pages.First().ObjectModel.TextObjects.First().GetGlyphInfo();
ImportsIronPdfImportsSystem.LinqDim pdf AsPdfDocument = PdfDocument.FromFile("invoice.pdf")Dim glyph = pdf.Pages.First().ObjectModel.TextObjects.First().GetGlyphInfo()
Imports IronPdf
Imports System.Linq
Dim pdf As PdfDocument = PdfDocument.FromFile("invoice.pdf")
Dim glyph = pdf.Pages.First().ObjectModel.TextObjects.First().GetGlyphInfo()
以下の例では、CSS Flexboxを使用してHTMLをレンダリングし、テキストを中央に配置しています。 最初のTranslateプロパティに割り当てることでそれを変換します。 これにより、テキストは右に200ポイント、上に150ポイント移動します。その他の例については、translate PDF objects example pageをご覧ください。
オブジェクトを翻訳するにはどのコードを使用すればよいですか?
using IronPdf;using System.Drawing;using System.Linq;// Setup the Renderervar renderer = new ChromePdfRenderer();// We use CSS Flexbox to perfectly center the text vertically and horizontally.var html = @"<div style='display: flex; justify-content: center; align-items: center; font-size: 48px;'> Centered</div>";// Render the HTML to a PDFPdfDocument pdf = renderer.RenderHtmlAsPdf(html);// Save the original PDF to see the "before" statepdf.SaveAs("BeforeTranslate.pdf");// Access the first text object on the first page// In this simple HTML, this will be our "Centered" text block.var textObject = pdf.Pages.First().ObjectModel.TextObjects.First();// Apply the translation// This moves the object 200 points to the right and 150 points up from its original position.textObject.Translate = new PointF(200, 150);// Save the modified PDF to see the "after" statepdf.SaveAs("AfterTranslate.pdf");
using IronPdf;
using System.Drawing;
using System.Linq;
// Setup the Renderer
var renderer = new ChromePdfRenderer();
// We use CSS Flexbox to perfectly center the text vertically and horizontally.
var html = @"
<div style='display: flex; justify-content: center; align-items: center; font-size: 48px;'>
Centered
</div>";
// Render the HTML to a PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
// Save the original PDF to see the "before" state
pdf.SaveAs("BeforeTranslate.pdf");
// Access the first text object on the first page
// In this simple HTML, this will be our "Centered" text block.
var textObject = pdf.Pages.First().ObjectModel.TextObjects.First();
// Apply the translation
// This moves the object 200 points to the right and 150 points up from its original position.
textObject.Translate = new PointF(200, 150);
// Save the modified PDF to see the "after" state
pdf.SaveAs("AfterTranslate.pdf");
ImportsIronPdfImportsSystem.DrawingImportsSystem.Linq' Setup the RendererDim renderer As New ChromePdfRenderer()' We use CSS Flexbox to perfectly center the text vertically and horizontally.Dim html AsString = "<div style='display: flex; justify-content: center; align-items: center; font-size: 48px;'> Centered</div>"' Render the HTML to a PDFDim pdf AsPdfDocument = renderer.RenderHtmlAsPdf(html)' Save the original PDF to see the "before" statepdf.SaveAs("BeforeTranslate.pdf")' Access the first text object on the first page' In this simple HTML, this will be our "Centered" text block.Dim textObject = pdf.Pages.First().ObjectModel.TextObjects.First()' Apply the translation' This moves the object 200 points to the right and 150 points up from its original position.textObject.Translate = New PointF(200, 150)' Save the modified PDF to see the "after" statepdf.SaveAs("AfterTranslate.pdf")
Imports IronPdf
Imports System.Drawing
Imports System.Linq
' Setup the Renderer
Dim renderer As New ChromePdfRenderer()
' We use CSS Flexbox to perfectly center the text vertically and horizontally.
Dim html As String = "
<div style='display: flex; justify-content: center; align-items: center; font-size: 48px;'>
Centered
</div>"
' Render the HTML to a PDF
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)
' Save the original PDF to see the "before" state
pdf.SaveAs("BeforeTranslate.pdf")
' Access the first text object on the first page
' In this simple HTML, this will be our "Centered" text block.
Dim textObject = pdf.Pages.First().ObjectModel.TextObjects.First()
' Apply the translation
' This moves the object 200 points to the right and 150 points up from its original position.
textObject.Translate = New PointF(200, 150)
' Save the modified PDF to see the "after" state
pdf.SaveAs("AfterTranslate.pdf")
using IronPdf;using System.Linq;// Setup the Renderervar renderer = new ChromePdfRenderer();// The image is placed in a div to give it some space on the page.string html = @"<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTi8LuOR6_A98euPLs-JRwoLU7Nc31nVP15rw&s'>";// Render the HTML to a PDFPdfDocument pdf = renderer.RenderHtmlAsPdf(html);// Save the PDF before scaling for comparisonpdf.SaveAs("BeforeScale.pdf");// Access the first image object on the first pagevar image = pdf.Pages.First().ObjectModel.ImageObjects.First();// We scale the image to 70% of its original size on both the X and Y axes.image.Scale = new System.Drawing.PointF(0.7f, 0.7f);// Save the modified PDF to see the resultpdf.SaveAs("AfterScale.pdf");
using IronPdf;
using System.Linq;
// Setup the Renderer
var renderer = new ChromePdfRenderer();
// The image is placed in a div to give it some space on the page.
string html = @"<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTi8LuOR6_A98euPLs-JRwoLU7Nc31nVP15rw&s'>";
// Render the HTML to a PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
// Save the PDF before scaling for comparison
pdf.SaveAs("BeforeScale.pdf");
// Access the first image object on the first page
var image = pdf.Pages.First().ObjectModel.ImageObjects.First();
// We scale the image to 70% of its original size on both the X and Y axes.
image.Scale = new System.Drawing.PointF(0.7f, 0.7f);
// Save the modified PDF to see the result
pdf.SaveAs("AfterScale.pdf");
ImportsIronPdfImportsSystem.LinqImportsSystem.Drawing' Setup the RendererDim renderer As New ChromePdfRenderer()' The image is placed in a div to give it some space on the page.Dim html AsString = "<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTi8LuOR6_A98euPLs-JRwoLU7Nc31nVP15rw&s'>"' Render the HTML to a PDFDim pdf AsPdfDocument = renderer.RenderHtmlAsPdf(html)' Save the PDF before scaling for comparisonpdf.SaveAs("BeforeScale.pdf")' Access the first image object on the first pageDim image = pdf.Pages.First().ObjectModel.ImageObjects.First()' We scale the image to 70% of its original size on both the X and Y axes.image.Scale = New PointF(0.7F, 0.7F)' Save the modified PDF to see the resultpdf.SaveAs("AfterScale.pdf")
Imports IronPdf
Imports System.Linq
Imports System.Drawing
' Setup the Renderer
Dim renderer As New ChromePdfRenderer()
' The image is placed in a div to give it some space on the page.
Dim html As String = "<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTi8LuOR6_A98euPLs-JRwoLU7Nc31nVP15rw&s'>"
' Render the HTML to a PDF
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)
' Save the PDF before scaling for comparison
pdf.SaveAs("BeforeScale.pdf")
' Access the first image object on the first page
Dim image = pdf.Pages.First().ObjectModel.ImageObjects.First()
' We scale the image to 70% of its original size on both the X and Y axes.
image.Scale = New PointF(0.7F, 0.7F)
' Save the modified PDF to see the result
pdf.SaveAs("AfterScale.pdf")
PDF DOMコレクション、たとえばTextObjectsにアクセスしてオブジェクトを削除します。 コレクションに対してRemoveAtを呼び出し、削除するオブジェクトのインデックスを渡します。 これは、コンテンツの再編集や文書の簡素化に役立ちます。 詳しくはPDFオブジェクトの削除例をご覧ください。
コードはBeforeScale.pdfを読み込み、最初のページから最初の画像を削除します。
オブジェクトを削除するにはどのコードを使用すればよいですか?
using IronPdf;using System.Linq;// Load the PDF file we created in the Scale examplePdfDocument pdf = PdfDocument.FromFile("BeforeScale.pdf");// Access DOM Objectsvar objects = pdf.Pages.First().ObjectModel;// Remove first imageobjects.ImageObjects.RemoveAt(0);// Save the modified PDFpdf.SaveAs("removedFirstImage.pdf");
using IronPdf;
using System.Linq;
// Load the PDF file we created in the Scale example
PdfDocument pdf = PdfDocument.FromFile("BeforeScale.pdf");
// Access DOM Objects
var objects = pdf.Pages.First().ObjectModel;
// Remove first image
objects.ImageObjects.RemoveAt(0);
// Save the modified PDF
pdf.SaveAs("removedFirstImage.pdf");
ImportsIronPdfImportsSystem.Linq' Load the PDF file we created in the Scale exampleDim pdf AsPdfDocument = PdfDocument.FromFile("BeforeScale.pdf")' Access DOM ObjectsDim objects = pdf.Pages.First().ObjectModel' Remove first imageobjects.ImageObjects.RemoveAt(0)' Save the modified PDFpdf.SaveAs("removedFirstImage.pdf")
Imports IronPdf
Imports System.Linq
' Load the PDF file we created in the Scale example
Dim pdf As PdfDocument = PdfDocument.FromFile("BeforeScale.pdf")
' Access DOM Objects
Dim objects = pdf.Pages.First().ObjectModel
' Remove first image
objects.ImageObjects.RemoveAt(0)
' Save the modified PDF
pdf.SaveAs("removedFirstImage.pdf")
// Example of combining multiple DOM operationsusing IronPdf;using System.Linq;PdfDocument pdf = PdfDocument.FromFile("complex-document.pdf");// Iterate through all pagesforeach (var page in pdf.Pages){ var objects = page.ObjectModel; // Process text objects foreach (var textObj in objects.TextObjects) { // Change color of specific text if (textObj.Contents.Contains("Important")) { textObj.FillColor = IronSoftware.Drawing.Color.Red; } } // Scale down all images by 50% foreach (var imgObj in objects.ImageObjects) { imgObj.Scale = new System.Drawing.PointF(0.5f, 0.5f); }}pdf.SaveAs("processed-document.pdf");
// Example of combining multiple DOM operations
using IronPdf;
using System.Linq;
PdfDocument pdf = PdfDocument.FromFile("complex-document.pdf");
// Iterate through all pages
foreach (var page in pdf.Pages)
{
var objects = page.ObjectModel;
// Process text objects
foreach (var textObj in objects.TextObjects)
{
// Change color of specific text
if (textObj.Contents.Contains("Important"))
{
textObj.FillColor = IronSoftware.Drawing.Color.Red;
}
}
// Scale down all images by 50%
foreach (var imgObj in objects.ImageObjects)
{
imgObj.Scale = new System.Drawing.PointF(0.5f, 0.5f);
}
}
pdf.SaveAs("processed-document.pdf");
What is the method to scale PDF objects using IronPDF?
PDF objects can be scaled using the `Scale` property in IronPDF's `ObjectModel`, allowing you to adjust the dimensions of elements such as images or text by specifying scale factors.
How can I translate PDF objects in IronPDF?
Translate PDF objects in IronPDF by adjusting their `Translate` property. This repositioning enables layout adjustments without altering the visual style of the objects.
How do I distinguish CAD features in a PDF without layers using IronPDF?
IronPDF allows you to differentiate CAD features without layers by analyzing the `PathObject` attributes such as `StrokeWidth`, `LineCap`, and `DashPattern`.
What are some common use cases for combined PDF DOM operations using IronPDF?
Combined PDF DOM operations are useful for batch document processing, dynamic report generation, content migration, and improving document accessibility, allowing complex modifications using IronPDF.