使用IRONPDF 如何在C#中添加PDF印章器 Curtis Chau 更新日期:7月 28, 2025 Download IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article 在 PDF 上壓印文字和圖像涉及將額外的內容疊加到現有的 PDF 文件上。 這些內容通常稱為「印章」,可以是文字、圖像或兩者的結合。 通常,使用者會使用印章在 PDF 上添加信息、標籤、水印或註解。 TextStamper:TextStamper 是在 PDFs 上添加描述性文本的解決方案。 無論您是增強現有文件、將文本放置在同一頁面上,還是將其他 PDF 文檔的細節融入其中,這個印章可以讓您自定義文件中的文件描述和信息。 ImageStamper:ImageStamper 是將圖像放置在 PDFs 中的首選工具。 無論是用作文件描述的標誌、現有文檔的插圖,還是同一頁面或其他 PDF 文件的視覺元素,此印章可以確保圖像的無縫整合。 HtmlStamper:HtmlStamper 將自定義程度提升到新的高度,允許您將 HTML 內容壓印到 PDFs 上。 這包括創建動態元素,如互動內容、描述和文件規範,提供超越傳統 PDF 自定義的靈活性。 BarcodeStamper to stamp Barcodes:BarcodeStamper 簡化了在您的 PDFs 上添加條形碼的過程。 無論是用於在已簽名文件、臨時文件或文件附件中的跟踪目的,這個印章可以確保條形碼的高效整合到 PDF 中。 BarcodeStamper to stamp QR Codes:BarcodeStamper 也專門用於在您的 PDFs 上放置 QR 碼。 這對於創建交互式內容或文件附件非常完美,此印章允許您將 QR 碼嵌入同一頁面或其他 PDF 文檔中,確保輕鬆訪問額外信息。 這些專門的印章類別使用戶能夠輕鬆增強 PDF 文件,從基本文本到複雜的 HTML 設計和動態條形碼。 This article will explore the functionalities of three main stampers: Adding Text with TextStamper, Placing Images with ImageStamper, and Integrating HTML with HtmlStamper. HTMLStamper 特別強大,因為它可以利用所有 HTML 功能,加上 CSS 樣式,為壓印過程增加額外的靈活性。 如何在 PDFs 上壓印文字和圖像 下載用於壓印文字和圖像的 C# 庫。 創建並配置所需的印章類別。 使用 'ApplyStamp' 方法將印章應用到 PDF。 使用 'ApplyMultipleStamps' 方法應用多個印章。 指定特定的頁面以應用印章。 在 PDFs 中配置和應用文字印章 首先,從 TextStamper 類創建對象以支持在 PDFs 中的文本壓印。 這個類的對像包含所有配置,以指定文本印章的呈現方式。 將 textStamper 對象傳遞給 'ApplyStamp' 方法。 Text 屬性定義了要在 PDF 上顯示的內容。 此外,可以指定字體系列、字體樣式以及印章的位置。這種自定義延伸到互動元素、文件描述以及同一或其他 PDFs 上的現有內容。 然後,導出帶有實際文件名的 PDF。 完成配置後,將輸出 PDF 文件以指定的文件名導出,包裹所有設置,為您的文檔提供專業水準。 using IronPdf; using IronPdf.Editing; // Initialize the PDF renderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Create a PDF document from HTML content PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create a TextStamper object and configure its properties TextStamper textStamper = new TextStamper() { Text = "Text Stamper!", FontFamily = "Bungee Spice", UseGoogleFont = true, FontSize = 30, IsBold = true, IsItalic = true, VerticalAlignment = VerticalAlignment.Top, }; // Apply the text stamp to the PDF document pdf.ApplyStamp(textStamper); // Save the modified PDF document pdf.SaveAs("stampText.pdf"); using IronPdf; using IronPdf.Editing; // Initialize the PDF renderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Create a PDF document from HTML content PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create a TextStamper object and configure its properties TextStamper textStamper = new TextStamper() { Text = "Text Stamper!", FontFamily = "Bungee Spice", UseGoogleFont = true, FontSize = 30, IsBold = true, IsItalic = true, VerticalAlignment = VerticalAlignment.Top, }; // Apply the text stamp to the PDF document pdf.ApplyStamp(textStamper); // Save the modified PDF document pdf.SaveAs("stampText.pdf"); Imports IronPdf Imports IronPdf.Editing ' Initialize the PDF renderer Private renderer As New ChromePdfRenderer() ' Create a PDF document from HTML content Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>") ' Create a TextStamper object and configure its properties Private textStamper As New TextStamper() With { .Text = "Text Stamper!", .FontFamily = "Bungee Spice", .UseGoogleFont = True, .FontSize = 30, .IsBold = True, .IsItalic = True, .VerticalAlignment = VerticalAlignment.Top } ' Apply the text stamp to the PDF document pdf.ApplyStamp(textStamper) ' Save the modified PDF document pdf.SaveAs("stampText.pdf") $vbLabelText $csharpLabel 在 PDF 中配置和應用圖像印章 類似於文本印章,從 ImageStamper 類創建對象,然後使用 ImageStamper 應用方法將圖像應用於文檔。 此方法的第二個參數也能容納頁面索引,允許將印章應用於單頁或多頁。 這個特定的示例可以指導系統將圖像作為印章特別應用在 PDF 的首頁。 所有頁面索引是基於零索引的。 using IronPdf; using IronPdf.Editing; // Initialize the PDF renderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Create a PDF document from HTML content PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create an ImageStamper object with the image URL ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) { VerticalAlignment = VerticalAlignment.Top, }; // Apply the image stamp to the first page of the PDF document pdf.ApplyStamp(imageStamper, 0); // Save the modified PDF document pdf.SaveAs("stampImage.pdf"); using IronPdf; using IronPdf.Editing; // Initialize the PDF renderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Create a PDF document from HTML content PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create an ImageStamper object with the image URL ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) { VerticalAlignment = VerticalAlignment.Top, }; // Apply the image stamp to the first page of the PDF document pdf.ApplyStamp(imageStamper, 0); // Save the modified PDF document pdf.SaveAs("stampImage.pdf"); Imports IronPdf Imports IronPdf.Editing ' Initialize the PDF renderer Private renderer As New ChromePdfRenderer() ' Create a PDF document from HTML content Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>") ' Create an ImageStamper object with the image URL Private imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {.VerticalAlignment = VerticalAlignment.Top} ' Apply the image stamp to the first page of the PDF document pdf.ApplyStamp(imageStamper, 0) ' Save the modified PDF document pdf.SaveAs("stampImage.pdf") $vbLabelText $csharpLabel 應用多個印章 要向文檔添加多個印章,請在 IronPDF 中使用應用多個印章的方法,傳入印章的數組。 它允許您一次性添加各種元素,如文本、圖像或標籤。 在此示例中創建了兩個具有不同文本和對齊的文本印章,pdf.ApplyMultipleStamps 將兩個印章應用於 PDF,最後的文檔保存為 multipleStamps.pdf。 此方法簡化了添加不同印章的過程,提供了一種便捷的方式來增強您的 PDF,無論是在同一頁面、另一個 PDF,還是即使是空白頁。 using IronPdf; using IronPdf.Editing; // Initialize the PDF renderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Create a PDF document from HTML content PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create two TextStamper objects with different configurations TextStamper stamper1 = new TextStamper() { Text = "Text stamp 1", VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, }; TextStamper stamper2 = new TextStamper() { Text = "Text stamp 2", VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Right, }; // Add the stampers to an array Stamper[] stampersToApply = { stamper1, stamper2 }; // Apply multiple stamps to the PDF document pdf.ApplyMultipleStamps(stampersToApply); // Save the modified PDF document pdf.SaveAs("multipleStamps.pdf"); using IronPdf; using IronPdf.Editing; // Initialize the PDF renderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Create a PDF document from HTML content PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create two TextStamper objects with different configurations TextStamper stamper1 = new TextStamper() { Text = "Text stamp 1", VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, }; TextStamper stamper2 = new TextStamper() { Text = "Text stamp 2", VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Right, }; // Add the stampers to an array Stamper[] stampersToApply = { stamper1, stamper2 }; // Apply multiple stamps to the PDF document pdf.ApplyMultipleStamps(stampersToApply); // Save the modified PDF document pdf.SaveAs("multipleStamps.pdf"); Imports IronPdf Imports IronPdf.Editing ' Initialize the PDF renderer Private renderer As New ChromePdfRenderer() ' Create a PDF document from HTML content Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>") ' Create two TextStamper objects with different configurations Private stamper1 As New TextStamper() With { .Text = "Text stamp 1", .VerticalAlignment = VerticalAlignment.Top, .HorizontalAlignment = HorizontalAlignment.Left } Private stamper2 As New TextStamper() With { .Text = "Text stamp 2", .VerticalAlignment = VerticalAlignment.Top, .HorizontalAlignment = HorizontalAlignment.Right } ' Add the stampers to an array Private stampersToApply() As Stamper = { stamper1, stamper2 } ' Apply multiple stamps to the PDF document pdf.ApplyMultipleStamps(stampersToApply) ' Save the modified PDF document pdf.SaveAs("multipleStamps.pdf") $vbLabelText $csharpLabel 指定 PDF 文件上的印章位置 要定義印章的放置位置,利用帶有三個水平列和三個垂直行的 3x3 網格。 您可以選擇水平對齊:左、中和右,以及垂直對齊:上、中和下。 您可以為每個位置調整水平和垂直偏移以增加精確度。 請參照以下圖片以獲得此概念的視覺表示。 PDF 壓印器定位 HorizontalAlignment:印章相對於頁面的水平對齊。 VerticalAlignment:印章相對於頁面的垂直對齊。 HorizontalOffset:水平方向的偏移。 默認值為 0,默認單位為 IronPdf.Editing.MeasurementUnit.Percentage。 正值表示向右的偏移,而負值表示向左的偏移。 VerticalOffset:垂直方向的偏移。 默認值為 0,默認單位為 IronPdf.Editing.MeasurementUnit.Percentage。 正值表示向下的偏移,而負值表示向上的偏移。 要指定 HorizontalOffset 和 VerticalOffset 屬性,實例化 指定的長度類以進行詳細測量。 長度的默認測量單位是百分比,但也可以使用測量單位,如英寸、毫米、厘米、像素和點。 using IronPdf.Editing; // Create an ImageStamper object with an image URL ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, // Specify offsets for precise positioning HorizontalOffset = new Length(10), // 10% offset to the right VerticalOffset = new Length(10), // 10% offset downward }; using IronPdf.Editing; // Create an ImageStamper object with an image URL ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, // Specify offsets for precise positioning HorizontalOffset = new Length(10), // 10% offset to the right VerticalOffset = new Length(10), // 10% offset downward }; Imports IronPdf.Editing ' Create an ImageStamper object with an image URL Private imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With { .HorizontalAlignment = HorizontalAlignment.Center, .VerticalAlignment = VerticalAlignment.Top, .HorizontalOffset = New Length(10), .VerticalOffset = New Length(10) } $vbLabelText $csharpLabel 在 PDF 上配置和應用 HTML 印章 還有另一個印章類可以用於壓印文本和圖像。 HtmlStamper 用於 HTML 集成類可以呈現帶有 CSS 樣式的 HTML 設計,並將其印章於 PDF 文件。 InnerHtmlBaseUrl 屬性用於指定 HTML 字符串資產的基本 URL,如 CSS 和圖像文件。 HtmlStamper 類應用於 PDF。 這個印章對象包括圖像和文本,您可以在即將被印章於您的 PDF 的 HTML 片段中定義這些內容。 所有對 JavaScript、CSS 和圖像文件的外部引用將是相對於內部 Html 屬性。 此代碼允許您根據在 HTML 內容中提到的特定文件規格自定義 PDF。 最後,修改的 PDF 以文件名 'stampHtml.pdf' 保存。 using IronPdf; using IronPdf.Editing; // Initialize the PDF renderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Create a PDF document from HTML content PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create an HtmlStamper object and configure its properties HtmlStamper htmlStamper = new HtmlStamper() { Html = @"<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg'> <h1>Iron Software</h1>", VerticalAlignment = VerticalAlignment.Top, }; // Apply the HTML stamp to the PDF document pdf.ApplyStamp(htmlStamper); // Save the modified PDF document pdf.SaveAs("stampHtml.pdf"); using IronPdf; using IronPdf.Editing; // Initialize the PDF renderer ChromePdfRenderer renderer = new ChromePdfRenderer(); // Create a PDF document from HTML content PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>"); // Create an HtmlStamper object and configure its properties HtmlStamper htmlStamper = new HtmlStamper() { Html = @"<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg'> <h1>Iron Software</h1>", VerticalAlignment = VerticalAlignment.Top, }; // Apply the HTML stamp to the PDF document pdf.ApplyStamp(htmlStamper); // Save the modified PDF document pdf.SaveAs("stampHtml.pdf"); Imports IronPdf Imports IronPdf.Editing ' Initialize the PDF renderer Private renderer As New ChromePdfRenderer() ' Create a PDF document from HTML content Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>") ' Create an HtmlStamper object and configure its properties Private htmlStamper As New HtmlStamper() With { .Html = "<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg'> <h1>Iron Software</h1>", .VerticalAlignment = VerticalAlignment.Top } ' Apply the HTML stamp to the PDF document pdf.ApplyStamp(htmlStamper) ' Save the modified PDF document pdf.SaveAs("stampHtml.pdf") $vbLabelText $csharpLabel HTML 印章選項 除了上面提到並解釋的選項,下面還有更多適用於印章類的選項。 Opacity:允許此印章是透明的。 0 是完全不可見,100 是完全不透明。 Rotation:將此印章順時針旋轉指定的 0 到 360 度。 MaxWidth:輸出印章的最大寬度。 MaxHeight:輸出印章的最大高度。 MinWidth:輸出印章的最小寬度。 MinHeight:輸出印章的最小高度。 Hyperlink:使此印章的印章元素具有按一下的超鏈接。 注意:由 link(a) 標籤創建的 HTML 鏈接不會在最終輸出中被印章保留。 Scale:對印章應用百分比比例以使其放大或縮小。 默認為 100(百分比),沒有影響。 IsStampBehindContent:設為 true 以將此印章應用於內容之後。 如果內容是不透明的,此印章可能是不可見的。 WaitFor:一個方便的包裝器以等待各種事件或某些時間。 Timeout:渲染超時秒數。 默認值為 60。 IronPDF 的印章選項提供了高級自定義,允許用戶以透明度、精確的旋轉和受控尺寸來增強 PDFs。 像 Hyperlink 和 Scale 這樣的功能能夠促進交互元素的合併,符合文件規格,並專注於內容。 IsStampBehindContent 選項策略性地定位印章,確保它們是相同對像的一部分,而不是字段。 同時,WaitFor 功能高效地管理渲染事件,使 IronPDF 成為 PDF 自訂的多功能工具,包括原始頁面旋轉。 結論 總之,IronPDF 的印章功能提供了一種多功能且易於使用的解決方案來增強 PDF 文件。 無論是添加簡單的文本標籤、整合圖像,還是利用 HTML 和 CSS 的力量,IronPDF 都能滿足廣泛的自訂需求。 易於使用和展示應用文本和圖像印章的實用示例,使其適用於具備不同技術專長的用戶。印章選項,包括不透明度、旋轉和縮放,為尋求迅速自定義 PDF 的用戶提供了完整的工具包。 IronPDF 的印章功能是一款出色且高效的工具,使用戶能夠輕鬆提升其 PDF 文件。 Essentially, Mastering PDF Enhancements with IronPDF effortlessly elevates PDFs for both basic and advanced needs including Extracting Embedded Texts and Images, Handling PDF Forms with Ease, Efficient Merging or Splitting of PDF Files, and Formatting PDFs with Custom Headers and Footers programmatically. 如有查詢或功能要求,IronPDF 支援團隊隨時準備協助。 常見問題解答 什麼是 PDF 加蓋功能?如何在 C# 中使用它? PDF 加蓋是指在現有 PDF 文件上新增文字、圖像或 HTML 等內容。在 C# 中,您可以使用 IronPDF 的加蓋類別(例如TextStamper和ImageStamper來有效地應用這些元素。 有哪些印章類型可用於 PDF 自訂? IronPDF 提供多種專用圖章類,包括用於文字的TextStamper 、用於圖像的ImageStamper 、用於 HTML 內容的HtmlStamper以及用於條碼和二維碼的BarcodeStamper 。 如何使用 C# 將文字圖章加入 PDF ? 若要套用文字圖章,請建立一個TextStamper對象,設定文字內容和字型等屬性,然後使用ApplyStamp方法將其套用到 PDF。 我可以將HTML內容嵌入到PDF文件中嗎? 是的,使用 IronPDF 的HtmlStamper ,您可以將 HTML 內容嵌入到 PDF 文件中,從而實現動態和樣式化的元素。 如何控制圖章在 PDF 頁面上的位置? IronPDF 讓您可以使用 3x3 網格系統來控製印章位置,以便進行對齊和精確調整,並可進行水平和垂直偏移。 PDF圖章有哪些自訂選項? 在 IronPDF 中,您可以自訂 PDF 圖章,選項包括不透明度、旋轉、縮放、超鏈接,以及將圖章疊加在現有內容後面。 如何在單一 PDF 文件中套用多種類型的圖章? 使用 IronPDF,可以使用ApplyMultipleStamps方法有效地將各種類型的圖章(例如文字和圖像)套用到單一 PDF 文件中。 是否可以在PDF文件中加入二維碼? 是的,您可以使用 IronPDF 的BarcodeStamper為 PDF 添加二維碼,這些二維碼可用於互動和資訊展示用途。 Stamper 抽象類別在 PDF 加蓋中扮演什麼角色? IronPDF 中的 Stamper 抽象類別是建立專用沖壓器類別的基礎,為沖壓操作提供通用功能。 如何使用 C# 在 PDF 中套用影像圖章? 建立ImageStamper對象,配置其屬性,並使用ApplyStamp方法(可選擇性地指定頁面索引)將影像新增至 PDF 文件中。 IronPDF 是否支援 .NET 10 中的 PDF Stamper 類別? 是的,IronPDF 完全相容於 .NET 10。該程式庫不僅支援 .NET 10,還支援更早的版本,例如 .NET 9、.NET 8、.NET Core、.NET Standard 和 .NET Framework。這表示所有圖章類別(包括TextStamper 、 ImageStamper 、 HtmlStamper和BarcodeStamper )都可以在 .NET 10 專案中直接使用,無需任何修改。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 發表日期 11月 13, 2025 如何在 C# 中合併兩個 PDF 位元組數組 使用 IronPDF 在 C# 中合併兩個 PDF 位元組數組。學習如何透過簡單的程式碼範例,將來自位元組數組、記憶體流和資料庫的多個 PDF 文件合併在一起。 閱讀更多 發表日期 11月 13, 2025 如何在 ASP.NET MVC 中創建 PDF 檢視器 為 ASP.NET MVC 應用程式構建一個強大的 PDF 檢視器。顯示 PDF 文件,將視圖轉換為 PDF,使用 IronPDF 添加互動功能。 閱讀更多 發表日期 11月 13, 2025 如何建立 .NET HTML 轉 PDF 轉換器 學習如何在.NET中使用IronPDF將HTML轉換為PDF。 閱讀更多 如何在.NET中將PDF轉換成Tiff文件如何在C#中讀取PDF文件
發表日期 11月 13, 2025 如何在 C# 中合併兩個 PDF 位元組數組 使用 IronPDF 在 C# 中合併兩個 PDF 位元組數組。學習如何透過簡單的程式碼範例,將來自位元組數組、記憶體流和資料庫的多個 PDF 文件合併在一起。 閱讀更多
發表日期 11月 13, 2025 如何在 ASP.NET MVC 中創建 PDF 檢視器 為 ASP.NET MVC 應用程式構建一個強大的 PDF 檢視器。顯示 PDF 文件,將視圖轉換為 PDF,使用 IronPDF 添加互動功能。 閱讀更多