Tüm PDF DOM Nesnelerine C# ile Nasıl Erişilir
C# ile PDF DOM nesnelerine erişmek için IronPDF'nin ObjectModel özelliğini kullanın. Bu özellik, PDF belgelerindeki metin, görüntü ve yol nesnelerine programatik erişim sağlayarak öğeleri doğrudan okumanıza, değiştirmenize, taşımanıza, ölçeklendirmenize ve kaldırmanıza olanak tanır.
IronPDF'nin DOM erişim özelliklerini kullanarak PDF belgelerini düzenlemeye başlayın. Bu kılavuz, PDF DOM'una nasıl erişileceğini, bir sayfanın nasıl seçileceğini ve metin nesnelerinin nasıl değiştirileceğini gösterir. PDF'nizi yükleyin, istediğiniz sayfaya erişin ve birkaç satır kodla içeriği güncelleyin.
-
1IronPDF ile NuGet Package Manager'u yükleyin
-
2Bu kod parçacığını kopyalayın ve çalıştırın.
using System.Linq; var objs = IronPdf.PdfDocument.FromFile("input.pdf").Pages.First().ObjectModel;Imports System.Linq Dim objs = IronPdf.PdfDocument.FromFile("input.pdf").Pages.First().ObjectModelImports System.Linq Dim objs = IronPdf.PdfDocument.FromFile("input.pdf").Pages.First().ObjectModel -
3Canlı ortamınızda test için dağıtım yapın
Projenizde IronPDF'yi bugün ücretsiz deneme sürümü ile kullanmaya başlayın
Asgari İş Akışı (5 adım)
- C# kütüphanesini indirerek PDF DOM Nesnelerine erişin
- Hedeflenen PDF belgesini içe aktarın veya işleyin
- PDF'nin
Pageskoleksiyonuna erişin ve istenen sayfayı seçin - ObjectModel özelliğini kullanarak DOM nesnelerine göz atın ve etkileşimde bulunun
- Düzenlenen PDF belgesini kaydedin veya dışa aktarın
PDF'lerde DOM Nesnelerine Nasıl Erişirim?
ObjectModel, PdfPage nesnesinden erişilir. Önce, hedef PDF'yi içe aktarın ve onun Pages özelliğine erişin. Oradan, ObjectModel özelliğine erişmek için herhangi bir sayfayı seçin. Bu, HTML DOM öğeleri ile çalışmaya benzer şekilde PDF içeriği ile programlı olarak etkileşimi sağlar.
PDF DOM nesneleri ile çalışırken, PDF belgesinin altında yatan yapıya erişirsiniz. Bu, PDF dosyanızın görsel temsilini oluşturan, metin öğeleri, resimler, vektör grafikler (paths) ve diğer içerikleri içerir. IronPDF, C# uygulamalarıyla entegre olan nesne yönelimli bir PDF manipülasyonu yaklaşımı sunar.
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;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;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().ObjectModelImports 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
ObjectModel özelliği ImageObject, PathObject ve TextObject içerir. Her nesne, sayfa dizini, sınır kutusu, Scale ve Translate hakkında bilgi içerir. Bu bilgi değiştirilebilir. Render seçenekleri için, bu nesnelerin nasıl görüntüleneceğini özelleştirebilirsiniz. Özel kenar boşlukları ile çalışırken, nesne yerleşimini anlamak önemlidir.
<ImageObject>:
Height: Resmin yüksekliğiWidth: Resmin genişliğiExportBytesAsJpg: Resmi JPG bayt dizisi olarak dışa aktarma yöntemi
<PathObject>:
FillColor: Yolun dolgu rengiStrokeColor: Yolun çizgi rengiPoints: Yolu tanımlayan nokta koleksiyonuStrokeWidth: PDF kullanıcı alanı birimlerindeki çizgi kalınlığıLineCap: Uç noktası stili (Butt,RoundveyaProjectingSquare)LineJoin: Köşe stili (Miter,RoundveyaBevel)DashPattern: Ardışık çizgi ve boşluk uzunlukları; kesintisiz bir çizgi için boş bırakılırDashPhase: Çizgi desenine ofsetOcgId: Yolun ait olduğu katmanın kimliği veya tüm katmanların dışındayken-1GetLayer(): EşleşenPdfLayerdöndürür veyanull
<TextObject>:
Color: Metnin rengiContents: AsılTextiçeriğiOcgId: Metnin ait olduğu katmanın kimliği veya tüm katmanların dışındayken-1GetLayer(): EşleşenPdfLayerdöndürür veyanull
Her nesne türü, içeriğinin tipine uygun olarak yöntemler ve özellikler içerir. Metin ve resim çıkarmak veya belirli içeriği değiştirmek gerektiğinde, bu nesneler hassas kontrol sağlar. PDF formları ile çalışırken form alanlarınızı programatik olarak manipüle etmeniz gerektiğinde bu faydalıdır.
Glif Bilgilerini ve Sınırlayıcı Kutuları Nasıl Elde Edebilirim?
Özel yazı tipleriyle belirli glifleri kullanırken sınırlayıcı kutu ve glif bilgilerini almak önemlidir. IronPDF, mevcut PDF'lerde metin ve bitmap çizimi yaparken piksel düzeyinde hassas konumlandırma için bu bilgileri sağlar.
ObjectModel'a PdfPage nesnesinden erişin. Sonra TextObjects koleksiyonuna erişin. Glif ve sınır kutusu bilgilerini almak için GetGlyphInfo yöntemini çağırın.
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();Imports IronPdf
Imports System.Linq
Dim pdf As PdfDocument = 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()
Glif bilgileri, konumlandırma verilerini, yazı tipi metriklerini ve karmaşık PDF manipülasyonları için karaktere özgü ayrıntıları içerir. Bu, karmaşık tipografi ve düzen gereksinimlerini ele alan PDF işleme uygulamaları oluşturmaya olanak tanır. Özel fontlar ile çalışırken bu glif düzeyinde erişim, sistemler arasında doğru render sağlanmasını garanti eder.
PDF Katmanları (Opsiyonel İçerik Grupları) ile Nasıl Çalışırım?
Katmanlı bir PDF, içeriğini bir çizimin üzerine yerleştirilen aydınger kağıtları gibi etiketli katmanlar halinde düzenler. Bunlar, Acrobat'ın Katmanlar panelinde gösterdiği İsteğe Bağlı İçerik Gruplarıdır (OCG). PdfDocument.Layers koleksiyonu tüm katmanları sunar. Bu koleksiyon üzerinden katmanları listeleyebilir, Id veya Name ile bir katmanı bulabilir, ChildrenOf ile üst/alt katman ağacında gezinebilir ve tek bir katmana ait içeriği okuyabilirsiniz. Katmanları okuma işlemi salt okunurdur: adlarını, sıralarını veya görünürlüklerini değiştirmez. Her PdfLayer, Id, Name, IsVisible, DefaultVisible ve ParentId özelliklerini sunar.
using IronPdf;
using IronSoftware;
using System;
// Load a layered PDF, such as a CAD plan, engineering drawing, or map export
using PdfDocument pdf = new PdfDocument("blueprint.pdf");
// Enumerate every Optional Content Group (OCG) layer in the document
Console.WriteLine($"Document has {pdf.Layers.Count} layers");
foreach (PdfLayer layer in pdf.Layers)
{
Console.WriteLine($" {layer.Id}: \"{layer.Name}\" visible={layer.IsVisible} parent={layer.ParentId}");
}
// Look a layer up by name (case-sensitive) and extract just its text
PdfLayer titleBlock = pdf.Layers.FindByName("Title Block");
if (titleBlock != null)
{
string headerText = pdf.ExtractTextFromLayer(titleBlock.Id);
Console.WriteLine(headerText);
}using IronPdf;
using IronSoftware;
using System;
// Load a layered PDF, such as a CAD plan, engineering drawing, or map export
using PdfDocument pdf = new PdfDocument("blueprint.pdf");
// Enumerate every Optional Content Group (OCG) layer in the document
Console.WriteLine($"Document has {pdf.Layers.Count} layers");
foreach (PdfLayer layer in pdf.Layers)
{
Console.WriteLine($" {layer.Id}: \"{layer.Name}\" visible={layer.IsVisible} parent={layer.ParentId}");
}
// Look a layer up by name (case-sensitive) and extract just its text
PdfLayer titleBlock = pdf.Layers.FindByName("Title Block");
if (titleBlock != null)
{
string headerText = pdf.ExtractTextFromLayer(titleBlock.Id);
Console.WriteLine(headerText);
}Imports IronPdf
Imports IronSoftware
Imports System
' Load a layered PDF, such as a CAD plan, engineering drawing, or map export
Using pdf As New PdfDocument("blueprint.pdf")
' Enumerate every Optional Content Group (OCG) layer in the document
Console.WriteLine($"Document has {pdf.Layers.Count} layers")
For Each layer As PdfLayer In pdf.Layers
Console.WriteLine($" {layer.Id}: ""{layer.Name}"" visible={layer.IsVisible} parent={layer.ParentId}")
Next
' Look a layer up by name (case-sensitive) and extract just its text
Dim titleBlock As PdfLayer = pdf.Layers.FindByName("Title Block")
If titleBlock IsNot Nothing Then
Dim headerText As String = pdf.ExtractTextFromLayer(titleBlock.Id)
Console.WriteLine(headerText)
End If
End UsingImports IronPdf
Imports IronSoftware
Imports System
' Load a layered PDF, such as a CAD plan, engineering drawing, or map export
Using pdf As New PdfDocument("blueprint.pdf")
' Enumerate every Optional Content Group (OCG) layer in the document
Console.WriteLine($"Document has {pdf.Layers.Count} layers")
For Each layer As PdfLayer In pdf.Layers
Console.WriteLine($" {layer.Id}: ""{layer.Name}"" visible={layer.IsVisible} parent={layer.ParentId}")
Next
' Look a layer up by name (case-sensitive) and extract just its text
Dim titleBlock As PdfLayer = pdf.Layers.FindByName("Title Block")
If titleBlock IsNot Nothing Then
Dim headerText As String = pdf.ExtractTextFromLayer(titleBlock.Id)
Console.WriteLine(headerText)
End If
End UsingExtractTextFromLayer dışında, ExtractTextFromLayers ile birden fazla katmanı aynı anda çekebilir veya GetTextObjectsByLayer ve GetPathObjectsByLayer ile nesnelerin kendilerine ulaşabilirsiniz. Daha geniş bir çıkarım çalışma akışının parçası olan katman-kapsamlı metin için, metin ve resim çıkarma kılavuzuna bakın.
FindByName("title block"), "Title Block" ile eşleşmeyecektir. Katmansız bir PDF, null yerine boş bir koleksiyon döndürür, böylece null kontrolü yapmadan pdf.Layers sırasında sıralama yapabilirsiniz.CAD Özelliklerini Çizgi Stili ile Nasıl Ayırt Edebilirim?
Bazı çizimler hiç katman bilgisi taşımaz. Ölçme ve CAD araçlarından dışa aktarılan PDF'ler, genellikle OCG'ler olmadan gelir, bu nedenle özelliklerin ayrılması çizgilerinin nasıl çizildiğine bağlıdır. Her PathObject, grafik durumunu (StrokeWidth, LineCap, LineJoin, DashPattern ve DashPhase) rapor eder, bu da kesik bir sınırı sağlam bir konturdan veya kalın bir yolu ince bir yoldan ayırmak için yeterlidir.
using IronPdf;
using IronSoftware;
using System;
using System.Linq;
// PDFs from surveying and CAD tools often have no layer information.
// Distinguish features by each path's graphics-state attributes instead.
using PdfDocument pdf = new PdfDocument("survey-drawing.pdf");
var paths = pdf.Pages.First().ObjectModel.PathObjects;
foreach (PathObject path in paths)
{
bool isDashed = path.DashPattern.Count > 0;
Console.WriteLine(
$"width={path.StrokeWidth} cap={path.LineCap} join={path.LineJoin} " +
$"dashed={isDashed} color={path.StrokeColor}");
}using IronPdf;
using IronSoftware;
using System;
using System.Linq;
// PDFs from surveying and CAD tools often have no layer information.
// Distinguish features by each path's graphics-state attributes instead.
using PdfDocument pdf = new PdfDocument("survey-drawing.pdf");
var paths = pdf.Pages.First().ObjectModel.PathObjects;
foreach (PathObject path in paths)
{
bool isDashed = path.DashPattern.Count > 0;
Console.WriteLine(
$"width={path.StrokeWidth} cap={path.LineCap} join={path.LineJoin} " +
$"dashed={isDashed} color={path.StrokeColor}");
}Imports IronPdf
Imports IronSoftware
Imports System
Imports System.Linq
' PDFs from surveying and CAD tools often have no layer information.
' Distinguish features by each path's graphics-state attributes instead.
Dim pdf As New PdfDocument("survey-drawing.pdf")
Dim paths = pdf.Pages.First().ObjectModel.PathObjects
For Each path As PathObject In paths
Dim isDashed As Boolean = path.DashPattern.Count > 0
Console.WriteLine($"width={path.StrokeWidth} cap={path.LineCap} join={path.LineJoin} dashed={isDashed} color={path.StrokeColor}")
NextImports IronPdf
Imports IronSoftware
Imports System
Imports System.Linq
' PDFs from surveying and CAD tools often have no layer information.
' Distinguish features by each path's graphics-state attributes instead.
Dim pdf As New PdfDocument("survey-drawing.pdf")
Dim paths = pdf.Pages.First().ObjectModel.PathObjects
For Each path As PathObject In paths
Dim isDashed As Boolean = path.DashPattern.Count > 0
Console.WriteLine($"width={path.StrokeWidth} cap={path.LineCap} join={path.LineJoin} dashed={isDashed} color={path.StrokeColor}")
NextHer yol, çizgi kalınlığını, uç ve köşe stillerini, kesikli olup olmadığını ve rengini konsola yazar. Böylece PDF katman içermese bile kesikli bir sınır ile kesintisiz bir kontur ayırt edilebilir.
PDF Nesnelerini Nasıl Taşıyabilirim?
Metin veya resim gibi öğeleri yeniden konumlandırarak PDF düzenini ayarlayın. Nesneleri, Translate özelliklerini değiştirerek taşıyın. Bu işlevsellik, IronPDF'in PDF dönüştürme yeteneklerinin bir parçasıdır.
Aşağıdaki örnek, metni ortalamak için CSS Flexbox kullanan HTML'yi işler. İlk TextObject nesnesine erişir ve Translate özelliğine yeni bir PointF atayarak nesneyi taşır. Bu, metni 200 punto sağa ve 150 punto yukarı kaydırır. Daha fazla örnek için PDF nesnelerini taşıma örnek sayfasını ziyaret edin.
Nesneleri Taşımak İçin Hangi Kodu Kullanırım?
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");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");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")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")Çıktı
Çıktı, 'Centered' metninin orijinal konumundan 200 punto sağa ve 150 punto yukarı kaydırıldığını gösterir.

Taşıma işlemleri yalnızca konumu değiştirirken nesnenin yazı tipi, boyut ve renk gibi orijinal özelliklerini korur. Bu, görsel görünümü etkilemeden düzen ayarlamaları yapmak için idealdir. Dinamik olarak oluşturulan içeriği yeniden konumlandırırken bu özellik üstbilgi ve altbilgilerle birlikte kullanılabilir.
PDF Nesnelerini Nasıl Ölçeklendiririm?
PDF nesnelerini Scale özelliğini kullanarak yeniden boyutlandırın. Bu özellik bir çarpan olarak işlev görür. 1'den büyük değerler boyutu artırır, 0 ile 1 arasındaki değerler ise boyutu azaltır. Ölçeklendirme, dinamik düzenler ve içeriği sayfa boyutlarına uyarlamak için önemlidir. Daha fazla örnek için PDF nesneleri ölçeklendirme kılavuzuna bakın.
Örnek, bir resim içeren HTML'yi işler. İlk ImageObject nesnesine erişir ve Scale özelliğine her iki eksende de 0,7 değerine sahip yeni bir PointF atayarak resmi orijinal boyutunun %70'ine ölçeklendirir.
PDF Nesnelerini Ölçeklendirme Kodu Nedir?
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");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");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")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")Eşit olmayan ölçeklendirme için X ve Y eksenlerine bağımsız olarak farklı ölçekleme faktörleri uygulayın. Bu, içeriği belirli boyutlara uyarlamak için kullanışlıdır. Özel kağıt boyutları ile çalışırken, ölçek, içeriğin sayfa sınırları içinde sığmasını sağlamak için yardımcı olur.
Çıktı
Çıktı, resmin orijinal boyutunun %70'ine ölçeklendirildiğini gösterir.

PDF Nesnelerini Nasıl Kaldırırım?
ImageObjects veya TextObjects gibi PDF DOM koleksiyonuna erişerek nesneleri kaldırın. Silinecek nesnenin dizinini geçirerek koleksiyon üzerinde RemoveAt çağırın. Bu, içeriği sansürlemek veya belgeleri basitleştirmek için kullanışlıdır. PDF nesnelerini kaldırma örneği sayfasında daha fazla bilgi edinin.
Kod, BeforeScale.pdf yükler ve ilk sayfadan ilk resmi kaldırır.
Nesneleri Kaldırmak İçin Hangi Kod Kullanılmalıdır?
Girdi
Gömülü ürün resmi içeren bir 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");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");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")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")Çıktı
İlk resim nesnesi sayfadan kaldırılmış ve geriye kalan içerik yerinde kalmıştır.
Birden Fazla Nesne Kaldırdığımda Ne Olur?
Kalan nesnelerin dizinleri, kaldırıldıktan sonra kayar. Birden fazla nesne kaldırılırken, doğru dizinleri korumak için bunları ters sırayla kaldırın. Bu teknik, metni sansürlemek için hassas belgelerde yardımcı olur.
Birden Fazla DOM İşlemini Nasıl Kombine Ederim?
IronPDF'nin DOM erişimi, karmaşık belge işleme iş akışlarını mümkün kılar. Karmaşık dönüşümler için işlemleri birleştirin:
Birleştirilmiş İşlemler Ne Zaman Kullanılmalıdır?
Girdi
Kaynak PDF, 'Önemli' olarak işaretlenmiş metin ve bir resim içerir.
using IronPdf;
using System.Linq;
// Example of combining multiple DOM operations
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");using IronPdf;
using System.Linq;
// Example of combining multiple DOM operations
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");Imports IronPdf
Imports System.Linq
' Example of combining multiple DOM operations
Dim pdf As PdfDocument = PdfDocument.FromFile("complex-document.pdf")
' Iterate through all pages
For Each page In pdf.Pages
Dim objects = page.ObjectModel
' Process text objects
For Each textObj In objects.TextObjects
' Change color of specific text
If textObj.Contents.Contains("Important") Then
textObj.FillColor = IronSoftware.Drawing.Color.Red
End If
Next
' Scale down all images by 50%
For Each imgObj In objects.ImageObjects
imgObj.Scale = New System.Drawing.PointF(0.5F, 0.5F)
Next
Next
pdf.SaveAs("processed-document.pdf")Imports IronPdf
Imports System.Linq
' Example of combining multiple DOM operations
Dim pdf As PdfDocument = PdfDocument.FromFile("complex-document.pdf")
' Iterate through all pages
For Each page In pdf.Pages
Dim objects = page.ObjectModel
' Process text objects
For Each textObj In objects.TextObjects
' Change color of specific text
If textObj.Contents.Contains("Important") Then
textObj.FillColor = IronSoftware.Drawing.Color.Red
End If
Next
' Scale down all images by 50%
For Each imgObj In objects.ImageObjects
imgObj.Scale = New System.Drawing.PointF(0.5F, 0.5F)
Next
Next
pdf.SaveAs("processed-document.pdf")Çıktı
"Önemli" metin kırmızıdır ve resim %50'ye ölçeklenmiştir.
Birleştirilmiş İşlemler İçin Yaygın Kullanım Durumları Nelerdir?
Birleştirilmiş DOM işlemleri şu amaçlar için uygundur:
- Toplu Belge İşleme: Biçimlendirme standartlarını uygulamak veya hassas içeriği kaldırmak için belgeleri işleyin
- Dinamik Rapor Oluşturma: Gerçek zamanlı verilerle şablon PDF'leri değiştirerek mizanpajı kontrol edin
- İçerik Taşıma: PDF'lerden içeriği çıkarıp yeni düzenlerde yeniden organize edin
- Erişilebilirlik İyileştirmeleri: Belgeleri metin boyutunu, kontrastını veya boşlukları değiştirerek geliştirin
Bu teknikler, karmaşık değişiklikleri ele alan güçlü PDF işleme uygulamaları sağlar. Belge özelliklerini yönetmek için meta veri yönetim kılavuzuna bakın.
DOM Erişimi Diğer PDF Manipülasyon Yöntemleri ile Nasıl Karşılaştırılır?
PDF DOM ile çalışmak, geleneksel yöntemlere göre avantajlar sağlar:
Girdi
Kaynak üç aylık rapor, zarar olarak işaretlenmiş iki tutar içerir.
using IronPdf;
using System.Linq;
// Example: Selective content modification based on criteria
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");using IronPdf;
using System.Linq;
// Example: Selective content modification based on criteria
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");Imports IronPdf
Imports System.Linq
' Example: Selective content modification based on criteria
Dim report As PdfDocument = PdfDocument.FromFile("quarterly-report.pdf")
For Each page In report.Pages
Dim textObjects = page.ObjectModel.TextObjects
' Highlight negative values in financial reports
For Each text In textObjects
If text.Contents.StartsWith("-$") OrElse text.Contents.Contains("Loss") Then
text.FillColor = IronSoftware.Drawing.Color.Red
End If
Next
Next
report.SaveAs("highlighted-report.pdf")Imports IronPdf
Imports System.Linq
' Example: Selective content modification based on criteria
Dim report As PdfDocument = PdfDocument.FromFile("quarterly-report.pdf")
For Each page In report.Pages
Dim textObjects = page.ObjectModel.TextObjects
' Highlight negative values in financial reports
For Each text In textObjects
If text.Contents.StartsWith("-$") OrElse text.Contents.Contains("Loss") Then
text.FillColor = IronSoftware.Drawing.Color.Red
End If
Next
Next
report.SaveAs("highlighted-report.pdf")Çıktı
-$ ile başlayan veya "Loss" içeren her değer kırmızı renktedir.
Bu ayrıntılı kontrol yalnızca HTML'den PDF'ye dönüştürme ile sağlanamaz; bu nedenle gelişmiş PDF işleme için DOM erişimi gereklidir.
Başka neler yapabileceğinizi görmek için hazır mısınız? Öğretici sayfasına burada göz atın: PDF'leri düzenleme
Sıkça Sorulan Sorular
C#'da PDF DOM nesnelerine nasıl erişebilirim?
IronPDF kullanarak C#'ta PDF DOM nesnelerine ObjectModel özelliği ile erişin. Bu, bir PDF belgesindeki metin, resim ve yol nesnelerini programatik olarak okumanıza, değiştirmenize ve manipüle etmenize olanak tanır.
IronPDF'teki `ObjectModel` özelliği nedir?
IronPDF'teki ObjectModel özelliği, PDF DOM'a erişim sağlar ve belirli bir PDF sayfasındaki metin nesneleri, resim nesneleri ve yol nesneleri gibi öğelerle etkileşimde bulunmanıza olanak tanır.
IronPDF kullanarak PDF metin nesnelerini nasıl değiştirebilirim?
IronPDF'te PDF metin nesnelerini ObjectModel ve TextObjects koleksiyonu aracılığıyla erişerek değiştirin, burada renk veya içerik gibi özellikleri sağlanan yöntemlerle değiştirebilirsiniz.
IronPDF kullanarak PDF'lerden glif ve sınırlayıcı kutu bilgilerini çıkarabilir miyim?
Evet, IronPDF, metin konumlandırmasını kesin bir şekilde yapmak için TextObjects'e erişip GetGlyphInfo yöntemini kullanarak glif ve çevre kutusu bilgilerini almanıza olanak tanır.
IronPDF kullanarak bir PDF'deki katmanlarla çalışmak mümkün mü?
IronPDF, bir PDF içindeki İsteğe Bağlı İçerik Grupları (OCG'ler) veya katmanlarla çalışmayı destekler ve belirli katmanlara yönelik içerik çıkarmaya olanak tanır.
IronPDF kullanarak bir PDF'den nesneleri nasıl kaldırabilirim?
PDF'ten resim veya metin gibi nesneleri kaldırmak için ObjectModel'deki ilgili koleksiyona erişebilir ve belirli bir nesneyi indeksle silmek için RemoveAt işlevini kullanabilirsiniz.
IronPDF kullanarak PDF nesnelerini ölçeklendirme yöntemi nedir?
IronPDF'in ObjectModel içindeki Scale özelliği kullanılarak PDF nesneleri ölçeklendirilebilir, bu da ölçek faktörleri belirterek resim veya metin gibi öğelerin boyutlarını ayarlamanıza olanak tanır.
IronPDF'te PDF nesnelerini nasıl çevirebilirim?
IronPDF'te PDF nesnelerini Translate özelliğini ayarlayarak çevirin. Bu yeniden konumlandırma, nesnelerin görsel tarzını değiştirmeden düzen ayarlamaları yapmanızı sağlar.
IronPDF kullanarak, katmanlar olmadan PDF'deki CAD özelliklerini nasıl ayırt edebilirim?
IronPDF, PathObject özelliklerini, örneğin StrokeWidth, LineCap ve DashPattern analiz ederek katmanlar olmadan CAD özelliklerini ayırt etmenizi sağlar.
IronPDF kullanarak birleştirilmiş PDF DOM işlemleri için bazı yaygın kullanım durumları nelerdir?
Birleştirilmiş PDF DOM işlemleri, toplu belge işleme, dinamik rapor üretimi, içerik geçişi ve belge erişilebilirliğini iyileştirmek için yararlıdır ve IronPDF kullanılarak karmaşık düzenlemelere olanak tanır.
Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapılandırılmış, görsel olarak çekici kılavuzlar oluşturmayı seviyor.