# How to Edit PDFs in C#
Iron Software已將各種PDF編輯功能簡化為`IronPDF`程式庫中易於理解的方法。 無論是新增簽名、新增HTML頁腳、印製浮水印還是新增註釋。 IronPDF是適合您的工具,讓您擁有可讀的程式碼、程式化的PDF生成、簡單的偵錯及無縫地部署到任何支援的環境或平台。
IronPDF在編輯PDF方面擁有眾多功能。 在這篇教學文章中,我們將介紹一些主要功能,並提供程式碼範例和解釋。
通過這篇文章,您將對如何使用IronPDF在C#中編輯您的PDF有詳細的了解。
*as-heading:2(快速入門:在數秒內編輯您的PDF文件)*
使用IronPDF在C#中輕鬆編輯PDF文件。 這本快速指南向您展示如何將文字印章新增到現有的PDF文件中。只需幾行程式碼,您就可以修改PDF並立即保存更改。 非常適合需要快速且高效的PDF編輯解決方案的開發者。
```cs
:title=Edit PDFs Instantly with IronPDF
var pdf = IronPdf.PdfDocument.FromFile("example.pdf");
pdf.ApplyStamp(new IronPdf.Editing.TextStamper("Confidential"));
pdf.SaveAs("edited_example.pdf");
```
*as-heading:2(目錄)*
- **編輯文件結構**
- [存取PDF DOM物件](#anchor-access-pdf-dom-object)
- [保存和導出PDF文件](#anchor-save-export-documents)
- [從記憶體載入PDF](#anchor-load-pdfs-from-memory)
- [導出PDF到記憶體](#anchor-export-pdfs-to-memory)
- **編輯文件屬性**
- [在C#中解析PDF](#anchor-parse-pdfs-in-c)
- [提取文字和圖像](#anchor-extract-text-images)
- [編輯文字和區域](#anchor-redact-texts-regions)
- [替換PDF中的文字](#anchor-replace-text-in-pdf)
- **增強PDF設計**
- [新增和編輯註釋](#anchor-add-edit-annotations)
- [印製文字和圖像](#anchor-stamp-text-images)
- [自訂浮水印](#anchor-custom-watermarks)
- [背景和前景](#anchor-backgrounds-foregorunds)
- [繪製文字和位元圖](#anchor-draw-text-bitmap)
- [繪製線條和矩形](#anchor-draw-line-rectangle)
- [旋轉文字和頁面](#anchor-rotate-text-and-pages)
- [變換PDF頁面](#anchor-transform-pdf-pages)
## 編輯文件結構
### 存取PDF DOM物件
操作和存取PDF物件快速且簡單。 IronPDF簡化了開發者與`DOM` - 使程式開發者能夠以程式化方式存取和操作各種元素,比如文字。
```cs
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;
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/access-pdf-dom-object/)。
### 保存和導出文件
為了保存和導出文件,IronPDF允許使用者快速將編輯的文件`PdfDocument.SaveAs`保存到磁碟,還允許導出為其他格式,如二進位資料和儲存器流。
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/export-save-pdf-csharp/)。
### 從記憶體載入PDF
IronPDF與現有的C# .NET應用完美整合; 我們可以通過`MemoryStream`中載入和建立PDF文件。
```cs
using IronPdf;
using System.IO;
// Read PDF file as stream
var fileByte = File.ReadAllBytes("sample.pdf");
// Instantiate PDF object from stream
PdfDocument pdf = new PdfDocument(fileByte);
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/pdf-memory-stream/)。
### 導出PDF到記憶體
同樣,我們也可以通過`MemoryStream`物件在C# .NET中將PDF導出到`MemoryStream`中。
```cs
using IronPdf;
using System.IO;
var renderer = new ChromePdfRenderer();
// Convert the URL into PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
// Export PDF as Stream
MemoryStream pdfAsStream = pdf.Stream;
// Export PDF as Byte Array
byte[] pdfAsByte = pdf.BinaryData;
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/pdf-to-memory-stream/)。
## 編輯文件文字
### Parse PDFs in C#
使用IronPDF從PDF中提取文字既快速又簡單。 只需使用`ExtractAllText`方法即可從每個頁面提取出所有文字,讓您輕鬆地存取並利用文件的內容。 這項強大的功能可提高生產效率並簡化工作流程!
```cs
using IronPdf;
// Select the desired PDF File
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Extract all text from an pdf
string allText = pdf.ExtractAllText();
// Extract all text from page 1
string page1Text = pdf.ExtractTextFromPage(0);
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/csharp-parse-pdf/)。
### 提取文字和圖像
使用IronPDF,您不僅限於提取文字——它也能非常輕鬆地從PDF中提取出圖像! 通過`ExtractAllImages`功能,您可以迅速獲取所有需要的視覺資料。
```cs
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Extract images
var images = pdf.ExtractAllImages();
for(int i = 0; i < images.Count; i++)
{
// Export the extracted images
images[i].SaveAs($"images/image{i}.png");
}
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/extract-text-and-images/)。
### 編輯文字和區域
在需要通過編輯來保護敏感資訊的情況下,我們擁有一個強大的工具:`RedactTextonAllPages`。 使用此功能,我們可以輕鬆地識別並隱藏整個PDF中每一個特定關鍵字的所有實例。 這是一種有效的方法來確保機密細節得到保護,同時仍能自信地共享文件。
```cs
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("novel.pdf");
// Redact 'Alaric' phrase from all pages
pdf.RedactTextOnAllPages("Alaric");
pdf.SaveAs("redacted.pdf");
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/redact-text/)。
### 替換PDF中的文字
為了通過IronPDF增強您的PDF文件,您可以輕鬆地替換整個文件中的文字。通過使用`newText`。 此方法有效地更新了文件中`oldText`的所有實例,確保一致且專業的外觀。
```cs
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>.NET6</h1>");
string oldText = ".NET6";
string newText = ".NET7";
// Replace text on all pages
pdf.ReplaceTextOnAllPages(oldText, newText);
pdf.SaveAs("replaceText.pdf");
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/find-replace-text/)。
## 增強PDF設計
### 新增和編輯註釋
IronPDF提供了廣泛的PDF註釋自訂選項,允許使用者直接在PDF頁面上新增"便箋"樣式的評論。 通過`TextAnnotation`類,註釋可以以程式化方式新增,並具有進階選項,如尺寸、透明度、圖標選擇和編輯能力。
```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");
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/annotations/)。
### 印製文字和圖像
IronPDF提供了廣泛的選項來自訂如何在PDF上印製文字和圖像。 在此範例中,我們將使用`ApplyStamp`方法對PDF進行印製,如下所示。
```cs
using IronPdf;
using IronPdf.Editing;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create text stamper
TextStamper textStamper = new TextStamper()
{
Text = "Text Stamper!",
FontFamily = "Bungee Spice",
UseGoogleFont = true,
FontSize = 30,
IsBold = true,
IsItalic = true,
VerticalAlignment = VerticalAlignment.Top,
};
// Stamp the text stamper
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/stamp-text-image/)。
### 自訂浮水印
我們也可以使用`ApplyWatermark`方法在新渲染的PDF和現有文件中無縫整合浮水印。 此功能提升了品牌識別度,確保您的資料展現專業形象。
```cs
using IronPdf;
string watermarkHtml = @"
<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>");
// Apply watermark
pdf.ApplyWatermark(watermarkHtml);
pdf.SaveAs("watermark.pdf");
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/custom-watermark/)。
### 背景和前景
除了浮水印和印製,我們也可以使用`AddBackgroundPdf`為PDF新增背景以進行自訂。
```cs
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>");
// Render background
PdfDocument background = renderer.RenderHtmlAsPdf("<body style='background-color: cyan;'></body>");
// Add background
pdf.AddBackgroundPdf(background);
pdf.SaveAs("addBackground.pdf");
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/background-foreground/)。
### 繪製文字和位元圖
在PDF上繪製文字直觀且簡單; 我們使用`DrawText`並為其提供必要的參數。 在此範例中,我們正在使用Times New Roman字體新增新短語`Some text`。
```cs
using IronPdf;
using IronSoftware.Drawing;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");
// Draw text on PDF
pdf.DrawText("Some text", FontTypes.TimesNewRoman.Name, FontSize: 12, PageIndex: 0, X: 100, Y: 100, Color.Black, Rotation: 0);
pdf.SaveAs("drawText.pdf");
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/draw-text-and-bitmap/)。
### 繪製線條和矩形
IronPDF也支援在PDF上繪製線條。 我們首先通過初始化兩個`DrawLine`方法將其應用,如下所示。
```cs
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");
// Configure the required parameters
int pageIndex = 0;
var start = new IronSoftware.Drawing.PointF(200,150);
var end = new IronSoftware.Drawing.PointF(1000,150);
int width = 10;
var color = new IronSoftware.Drawing.Color("#000000");
// Draw line on PDF
pdf.DrawLine(pageIndex, start, end, width, color);
pdf.SaveAs("drawLine.pdf");
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/draw-line-and-rectangle/)。
### 旋轉文字和頁面
為了旋轉PDF頁面,我們可以使用`SetPageRotation`方法來旋轉特定頁面。 在下面的範例中,我們僅旋轉頁面2到4,而頁面1保持不變,以展示其功能。
```cs
using IronPdf;
using IronPdf.Rendering;
using System.Linq;
// Import PDF
PdfDocument pdf = PdfDocument.FromFile("multi-page.pdf");
// Set rotation for a single page
pdf.SetPageRotation(0, PdfPageRotation.Clockwise90);
// Set rotation for multiple pages
pdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270);
// Set rotation for the entire document
pdf.SetAllPageRotations(PdfPageRotation.Clockwise180);
pdf.SaveAs("rotated.pdf");
```
關於旋轉角度的可用枚舉列表,請參閱[這裡](https://ironpdf.com/object-reference/api/IronPdf.Rendering.PdfPageRotation.html)。
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/rotating-text/)。
### 變換PDF頁面
除了旋轉之外,我們還可以通過提供一範圍的參數來變換pdf頁面。 在下面的範例中,我們選擇PDF的第一頁,並使用`Transform`將第一頁的內容向右和向下移動50點,並縮放至其原始大小的80%。
```cs
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("basic.pdf");
pdf.Pages[0].Transform(50, 50, 0.8, 0.8);
pdf.SaveAs("transformPage.pdf");
```
如需對此程式碼段的更詳細解釋並探索其額外功能,請參閱我們的完整版[指南](https://ironpdf.com/how-to/transform-pdf-pages/)。
## 結論
上面的範例列表證明了IronPDF在編輯PDF時擁有開箱即用的關鍵功能。
如果您想提交功能請求或對IronPDF或授權有任何一般性問題,請[聯絡我們的支援團隊](/troubleshooting/engineering-request-pdf/)。 我們將非常樂意為您提供幫助。
var pdf = IronPdf.PdfDocument.FromFile("example.pdf");pdf.ApplyStamp(new IronPdf.Editing.TextStamper("Confidential"));pdf.SaveAs("edited_example.pdf");
var pdf = IronPdf.PdfDocument.FromFile("example.pdf");
pdf.ApplyStamp(new IronPdf.Editing.TextStamper("Confidential"));
pdf.SaveAs("edited_example.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
using IronPdf;using System.IO;// Read PDF file as streamvar fileByte = File.ReadAllBytes("sample.pdf");// Instantiate PDF object from streamPdfDocument pdf = new PdfDocument(fileByte);
using IronPdf;
using System.IO;
// Read PDF file as stream
var fileByte = File.ReadAllBytes("sample.pdf");
// Instantiate PDF object from stream
PdfDocument pdf = new PdfDocument(fileByte);
ImportsIronPdfImportsSystem.IO' Read PDF file as streamPrivate fileByte = File.ReadAllBytes("sample.pdf")' Instantiate PDF object from streamPrivate pdf As New PdfDocument(fileByte)
Imports IronPdf
Imports System.IO
' Read PDF file as stream
Private fileByte = File.ReadAllBytes("sample.pdf")
' Instantiate PDF object from stream
Private pdf As New PdfDocument(fileByte)
using IronPdf;using System.IO;var renderer = new ChromePdfRenderer();// Convert the URL into PDFPdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");// Export PDF as StreamMemoryStream pdfAsStream = pdf.Stream;// Export PDF as Byte Arraybyte[] pdfAsByte = pdf.BinaryData;
using IronPdf;
using System.IO;
var renderer = new ChromePdfRenderer();
// Convert the URL into PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
// Export PDF as Stream
MemoryStream pdfAsStream = pdf.Stream;
// Export PDF as Byte Array
byte[] pdfAsByte = pdf.BinaryData;
ImportsIronPdfImportsSystem.IOPrivate renderer = New ChromePdfRenderer()' Convert the URL into PDFPrivate pdf AsPdfDocument = renderer.RenderUrlAsPdf("https://ironpdf.com/")' Export PDF as StreamPrivate pdfAsStream AsMemoryStream = pdf.Stream' Export PDF as Byte ArrayPrivate pdfAsByte() AsByte = pdf.BinaryData
Imports IronPdf
Imports System.IO
Private renderer = New ChromePdfRenderer()
' Convert the URL into PDF
Private pdf As PdfDocument = renderer.RenderUrlAsPdf("https://ironpdf.com/")
' Export PDF as Stream
Private pdfAsStream As MemoryStream = pdf.Stream
' Export PDF as Byte Array
Private pdfAsByte() As Byte = pdf.BinaryData
using IronPdf;// Select the desired PDF FilePdfDocument pdf = PdfDocument.FromFile("sample.pdf");// Extract all text from an pdfstring allText = pdf.ExtractAllText();// Extract all text from page 1string page1Text = pdf.ExtractTextFromPage(0);
using IronPdf;
// Select the desired PDF File
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Extract all text from an pdf
string allText = pdf.ExtractAllText();
// Extract all text from page 1
string page1Text = pdf.ExtractTextFromPage(0);
ImportsIronPdf' Select the desired PDF FilePrivate pdf AsPdfDocument = PdfDocument.FromFile("sample.pdf")' Extract all text from an pdfPrivate allText AsString = pdf.ExtractAllText()' Extract all text from page 1Private page1Text AsString = pdf.ExtractTextFromPage(0)
Imports IronPdf
' Select the desired PDF File
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Extract all text from an pdf
Private allText As String = pdf.ExtractAllText()
' Extract all text from page 1
Private page1Text As String = pdf.ExtractTextFromPage(0)
using IronPdf;PdfDocument pdf = PdfDocument.FromFile("sample.pdf");// Extract imagesvar images = pdf.ExtractAllImages();for(int i = 0; i < images.Count; i++){ // Export the extracted images images[i].SaveAs($"images/image{i}.png");}
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Extract images
var images = pdf.ExtractAllImages();
for(int i = 0; i < images.Count; i++)
{
// Export the extracted images
images[i].SaveAs($"images/image{i}.png");
}
ImportsIronPdfPrivate pdf AsPdfDocument = PdfDocument.FromFile("sample.pdf")' Extract imagesPrivate images = pdf.ExtractAllImages()For i AsInteger = 0 To images.Count - 1 ' Export the extracted images images(i).SaveAs($"images/image{i}.png")Next i
Imports IronPdf
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Extract images
Private images = pdf.ExtractAllImages()
For i As Integer = 0 To images.Count - 1
' Export the extracted images
images(i).SaveAs($"images/image{i}.png")
Next i
using IronPdf;PdfDocument pdf = PdfDocument.FromFile("novel.pdf");// Redact 'Alaric' phrase from all pagespdf.RedactTextOnAllPages("Alaric");pdf.SaveAs("redacted.pdf");
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("novel.pdf");
// Redact 'Alaric' phrase from all pages
pdf.RedactTextOnAllPages("Alaric");
pdf.SaveAs("redacted.pdf");
ImportsIronPdfPrivate pdf AsPdfDocument = PdfDocument.FromFile("novel.pdf")' Redact 'Alaric' phrase from all pagespdf.RedactTextOnAllPages("Alaric")pdf.SaveAs("redacted.pdf")
Imports IronPdf
Private pdf As PdfDocument = PdfDocument.FromFile("novel.pdf")
' Redact 'Alaric' phrase from all pages
pdf.RedactTextOnAllPages("Alaric")
pdf.SaveAs("redacted.pdf")
using IronPdf;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>.NET6</h1>");string oldText = ".NET6";string newText = ".NET7";// Replace text on all pagespdf.ReplaceTextOnAllPages(oldText, newText);pdf.SaveAs("replaceText.pdf");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>.NET6</h1>");
string oldText = ".NET6";
string newText = ".NET7";
// Replace text on all pages
pdf.ReplaceTextOnAllPages(oldText, newText);
pdf.SaveAs("replaceText.pdf");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>.NET6</h1>")Private oldText AsString = ".NET6"Private newText AsString = ".NET7"' Replace text on all pagespdf.ReplaceTextOnAllPages(oldText, newText)pdf.SaveAs("replaceText.pdf")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>.NET6</h1>")
Private oldText As String = ".NET6"
Private newText As String = ".NET7"
' Replace text on all pages
pdf.ReplaceTextOnAllPages(oldText, newText)
pdf.SaveAs("replaceText.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 indexTextAnnotation annotation = new TextAnnotation(0){Title = "This is the title",Contents = "This is the long 'sticky note' comment content...",X = 50,Y = 700,};// Add the annotationpdf.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");
ImportsIronPdfImportsIronPdf.AnnotationsDim renderer As New ChromePdfRenderer()Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Annotation</h1>")' Create a PDF annotation object on a specified page indexDim 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 annotationpdf.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")
using IronPdf;using IronPdf.Editing;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");// Create text stamperTextStamper textStamper = new TextStamper(){Text = "Text Stamper!",FontFamily = "Bungee Spice",UseGoogleFont = true,FontSize = 30,IsBold = true,IsItalic = true,VerticalAlignment = VerticalAlignment.Top,};// Stamp the text stamperpdf.ApplyStamp(textStamper);pdf.SaveAs("stampText.pdf");
using IronPdf;
using IronPdf.Editing;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create text stamper
TextStamper textStamper = new TextStamper()
{
Text = "Text Stamper!",
FontFamily = "Bungee Spice",
UseGoogleFont = true,
FontSize = 30,
IsBold = true,
IsItalic = true,
VerticalAlignment = VerticalAlignment.Top,
};
// Stamp the text stamper
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");
ImportsIronPdfImportsIronPdf.EditingPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")' Create text stamperPrivate textStamper As New TextStamper() With { .Text = "Text Stamper!", .FontFamily = "Bungee Spice", .UseGoogleFont = True, .FontSize = 30, .IsBold = True, .IsItalic = True, .VerticalAlignment = VerticalAlignment.Top}' Stamp the text stamperpdf.ApplyStamp(textStamper)pdf.SaveAs("stampText.pdf")
Imports IronPdf
Imports IronPdf.Editing
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create text stamper
Private textStamper As New TextStamper() With {
.Text = "Text Stamper!",
.FontFamily = "Bungee Spice",
.UseGoogleFont = True,
.FontSize = 30,
.IsBold = True,
.IsItalic = True,
.VerticalAlignment = VerticalAlignment.Top
}
' Stamp the text stamper
pdf.ApplyStamp(textStamper)
pdf.SaveAs("stampText.pdf")
using IronPdf;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>");// Render backgroundPdfDocument background = renderer.RenderHtmlAsPdf("<body style='background-color: cyan;'></body>");// Add backgroundpdf.AddBackgroundPdf(background);pdf.SaveAs("addBackground.pdf");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>");
// Render background
PdfDocument background = renderer.RenderHtmlAsPdf("<body style='background-color: cyan;'></body>");
// Add background
pdf.AddBackgroundPdf(background);
pdf.SaveAs("addBackground.pdf");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>")' Render backgroundPrivate background AsPdfDocument = renderer.RenderHtmlAsPdf("<body style='background-color: cyan;'></body>")' Add backgroundpdf.AddBackgroundPdf(background)pdf.SaveAs("addBackground.pdf")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>")
' Render background
Private background As PdfDocument = renderer.RenderHtmlAsPdf("<body style='background-color: cyan;'></body>")
' Add background
pdf.AddBackgroundPdf(background)
pdf.SaveAs("addBackground.pdf")
在PDF上繪製文字直觀且簡單; 我們使用DrawText並為其提供必要的參數。 在此範例中,我們正在使用Times New Roman字體新增新短語Some text。
using IronPdf;using IronSoftware.Drawing;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");// Draw text on PDFpdf.DrawText("Some text", FontTypes.TimesNewRoman.Name, FontSize: 12, PageIndex: 0, X: 100, Y: 100, Color.Black, Rotation: 0);pdf.SaveAs("drawText.pdf");
using IronPdf;
using IronSoftware.Drawing;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");
// Draw text on PDF
pdf.DrawText("Some text", FontTypes.TimesNewRoman.Name, FontSize: 12, PageIndex: 0, X: 100, Y: 100, Color.Black, Rotation: 0);
pdf.SaveAs("drawText.pdf");
ImportsIronPdfImportsIronSoftware.DrawingDim renderer As New ChromePdfRenderer()Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>")' Draw text on PDFpdf.DrawText("Some text", FontTypes.TimesNewRoman.Name, FontSize:=12, PageIndex:=0, X:=100, Y:=100, Color.Black, Rotation:=0)pdf.SaveAs("drawText.pdf")
Imports IronPdf
Imports IronSoftware.Drawing
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>")
' Draw text on PDF
pdf.DrawText("Some text", FontTypes.TimesNewRoman.Name, FontSize:=12, PageIndex:=0, X:=100, Y:=100, Color.Black, Rotation:=0)
pdf.SaveAs("drawText.pdf")
using IronPdf;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");// Configure the required parametersint pageIndex = 0;var start = new IronSoftware.Drawing.PointF(200,150);var end = new IronSoftware.Drawing.PointF(1000,150);int width = 10;var color = new IronSoftware.Drawing.Color("#000000");// Draw line on PDFpdf.DrawLine(pageIndex, start, end, width, color);pdf.SaveAs("drawLine.pdf");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");
// Configure the required parameters
int pageIndex = 0;
var start = new IronSoftware.Drawing.PointF(200,150);
var end = new IronSoftware.Drawing.PointF(1000,150);
int width = 10;
var color = new IronSoftware.Drawing.Color("#000000");
// Draw line on PDF
pdf.DrawLine(pageIndex, start, end, width, color);
pdf.SaveAs("drawLine.pdf");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>")' Configure the required parametersPrivate pageIndex AsInteger = 0Private start = New IronSoftware.Drawing.PointF(200,150)Private [end] = New IronSoftware.Drawing.PointF(1000,150)Private width AsInteger = 10Private color = New IronSoftware.Drawing.Color("#000000")' Draw line on PDFpdf.DrawLine(pageIndex, start, [end], width, color)pdf.SaveAs("drawLine.pdf")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>")
' Configure the required parameters
Private pageIndex As Integer = 0
Private start = New IronSoftware.Drawing.PointF(200,150)
Private [end] = New IronSoftware.Drawing.PointF(1000,150)
Private width As Integer = 10
Private color = New IronSoftware.Drawing.Color("#000000")
' Draw line on PDF
pdf.DrawLine(pageIndex, start, [end], width, color)
pdf.SaveAs("drawLine.pdf")
using IronPdf;using IronPdf.Rendering;using System.Linq;// Import PDFPdfDocument pdf = PdfDocument.FromFile("multi-page.pdf");// Set rotation for a single pagepdf.SetPageRotation(0, PdfPageRotation.Clockwise90);// Set rotation for multiple pagespdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270);// Set rotation for the entire documentpdf.SetAllPageRotations(PdfPageRotation.Clockwise180);pdf.SaveAs("rotated.pdf");
using IronPdf;
using IronPdf.Rendering;
using System.Linq;
// Import PDF
PdfDocument pdf = PdfDocument.FromFile("multi-page.pdf");
// Set rotation for a single page
pdf.SetPageRotation(0, PdfPageRotation.Clockwise90);
// Set rotation for multiple pages
pdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270);
// Set rotation for the entire document
pdf.SetAllPageRotations(PdfPageRotation.Clockwise180);
pdf.SaveAs("rotated.pdf");
ImportsIronPdfImportsIronPdf.RenderingImportsSystem.Linq' Import PDFPrivate pdf AsPdfDocument = PdfDocument.FromFile("multi-page.pdf")' Set rotation for a single pagepdf.SetPageRotation(0, PdfPageRotation.Clockwise90)' Set rotation for multiple pagespdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270)' Set rotation for the entire documentpdf.SetAllPageRotations(PdfPageRotation.Clockwise180)pdf.SaveAs("rotated.pdf")
Imports IronPdf
Imports IronPdf.Rendering
Imports System.Linq
' Import PDF
Private pdf As PdfDocument = PdfDocument.FromFile("multi-page.pdf")
' Set rotation for a single page
pdf.SetPageRotation(0, PdfPageRotation.Clockwise90)
' Set rotation for multiple pages
pdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270)
' Set rotation for the entire document
pdf.SetAllPageRotations(PdfPageRotation.Clockwise180)
pdf.SaveAs("rotated.pdf")