C# + VB.NET: 使用 HTML 來建立 PDF 使用 HTML 來建立 PDF
using IronPdf;

// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Create a PDF from a HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");

// Export to a file or Stream
pdf.SaveAs("output.pdf");

// Advanced Example with HTML Assets
// Load external html assets: Images, CSS and JavaScript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
Imports IronPdf

' Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = True

' Instantiate Renderer
Dim renderer = New ChromePdfRenderer()

' Create a PDF from a HTML string using C#
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")

' Export to a file or Stream
pdf.SaveAs("output.pdf")

' Advanced Example with HTML Assets
' Load external html assets: Images, CSS and JavaScript.
' An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
myAdvancedPdf.SaveAs("html-with-assets.pdf")

<p>使用 IronPDF,您可以在 .NET 專案中從簡單的 HTML 字串創建新的 PDF 文件,並且 IronPDF 可以在 C#、F# 和 VB.NET 中使用。 由於使用了 <code>ChromePdfRenderer</code> 類,您可以確保從 HTML 字串渲染的任何 PDF 文件將會呈現出來。<a href="/how-to/pixel-perfect-html-to-pdf/" target="__blank">像素完美</a>. 使用IronPDF的強大功能<a href="/tutorials/html-to-pdf/" target="__blank">HTML 轉換為 PDF</a>功能可創建符合您個人需求的高品質 PDF 文件。</p> <div class="examples__featured-snippet"> <h2>將 HTML 字串轉換為 PDF 的四個步驟</h2> <ol> <li>匯入 IronPDF 程式庫。</li> <li>初始化一個新的 <code>ChromePdfRenderer</code> 物件。</li> <li>使用 <code>ChromePdfRenderer.RenderHtmlAsPdf</code> 方法。</li> <li>使用保存 PDF <code>PdfDocument.SaveAs</code>.</li> </ol> </div> <p>請參閱下面的代碼範例以了解更多詳細信息:</p> <pre class='naked-code'><code class="language-cs">using IronPdf; var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("&lt;h1&gt;Hello World&lt;/h1&gt;"); var myAdvancedPdf = renderer.RenderHtmlAsPdf("&lt;img src='icons/iron.png'&gt;", @"C:\site\assets\"); pdf.SaveAs("output.pdf");</code></pre> <div class="code-content code-content-inner"> <div class="code_window" > <div class="language-selection__content-page-wrapper"> </div> <div class="code_window_content"> <div class="code-window__action-buttons-wrapper code-window__action-buttons-wrapper--content-page"> <button title="點擊複製" class=" code-window__action-button code-window__action-button--copy copy-clipboard " data-copy-text="點擊複製" data-copied-text="已複製到剪貼板" data-clipboard-id="code-explorer" data-placement="bottom" > <i class="fa-kit fa-copy-example"></i> </button> <button title="全螢幕模式" class=" code-window__action-button code-window__action-button--full-screen js-full-screen-code-example-modal " > <i class="fas fa-expand"></i> </button> <button title="退出全螢幕" class=" code-window__action-button code-window__action-button--exit-full-screen js-exit-full-screen-code-example-modal " > <i class="fas fa-compress"></i> </button> </div> <pre class="prettyprint linenums lang-cs"><code>using IronPdf; var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("&lt;h1&gt;Hello World&lt;/h1&gt;"); var myAdvancedPdf = renderer.RenderHtmlAsPdf("&lt;img src='icons/iron.png'&gt;", @"C:\site\assets\"); pdf.SaveAs("output.pdf");</code></pre> <pre class="prettyprint linenums lang-vb"><code>Imports IronPdf Private renderer = New ChromePdfRenderer() Private pdf = renderer.RenderHtmlAsPdf(&quot;&lt;h1&gt;Hello World&lt;/h1&gt;&quot;) Private myAdvancedPdf = renderer.RenderHtmlAsPdf(&quot;&lt;img src='icons/iron.png'&gt;&quot;, &quot;C:\site\assets\&quot;) pdf.SaveAs(&quot;output.pdf&quot;)</code></pre> </div> <div class="code_window_bottom"> <span class="language_selection"> <span class="ls-span">VB &nbsp;</span> <span> <label class="switch"> <input type="checkbox" checked="checked"> <span class="slider round"></span> </label> </span> <span class="ls-span">C#</span> </span> </div> </div> </div> <p>將 HTML 字串轉換為 C# 中的 PDF 的第一步是確保在專案中正確設置並運行 IronPDF 庫。 透過包含使用 IronPdf,我們確保可以訪問所需的 IronPDF 程式庫中的類,以進行 HTML 到 PDF 的轉換。 完成此操作後,下一行 <code>Installation.EnableWebSecurity = true</code> 用於禁用本地磁碟存取或跨域請求,確保操作安全。</p> <p>下一行會建立一個新的 ChromePdfRenderer 實例,該實例將負責將 HTML 轉換為 PDF。 在基本範例中,使用 RenderHtmlAsPdf 方法將簡單的 HTML 字串轉換為 PDF(&quot;<h1>你好,世界</h1>&quot;)<code>到 PDF 文件,並使用</code>SaveAs` 方法將其保存到磁碟。</p> <p>在進階方法中,我們展示了IronPDF如何處理包含外部資源(如圖片、CSS和JavaScript)的HTML內容。 要加載這些資產,使用可選的 BasePath 參數來指定包含所需文件的目錄。 包含外部資產的生成 PDF 使用與基本範例中相同的 <code>SaveAs</code> 方法保存。 此程式碼範例突顯了 IronPDF 處理簡單和複雜 HTML 內容的能力,使其成為以程式方式生成 PDF 的高效工具。 <a href="/how-to/html-string-to-pdf/" class="code_content__related-link__doc-cta-link">如需更多示例,請查看使用IronPDF與C#的操作指南。</a></p>

C# + VB.NET: 將 URL 轉換為 PDF 將 URL 轉換為 PDF
using IronPdf;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Create a PDF from a URL or local file path
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");

// Export to a file or Stream
pdf.SaveAs("url.pdf");
Imports IronPdf

' Instantiate Renderer
Private renderer = New ChromePdfRenderer()

' Create a PDF from a URL or local file path
Private pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")

' Export to a file or Stream
pdf.SaveAs("url.pdf")

<p>IronPDF 讓從現有 URL 渲染 HTML 為 PDF 文件變得非常簡單。 對 JavaScript、圖片、表單和 CSS 的支持非常全面。</p> <p>從接受查詢字串變數的 ASP.NET 網址渲染 PDF 可以促進設計師和編碼人員之間的協作,使 PDF 開發更加順利。</p> <p>請提供您要翻譯的內容。</p> <div class="examples__featured-snippet"> <h2>將 URL 轉換為 PDF 的 C# 步驟</h2> <ol> <li>下載 <a href="/" target="_blank" rel="nofollow noopener noreferrer">IronPDF URL 轉 PDF 轉換庫</a></li> <li>使用 NuGet 安裝該庫以測試其功能。</li> <li>使用 IronPDF 從接受查詢字串變數的 ASP.NET URL 生成 PDF。</li> <li>使用 IronPDF 直接從 URL 建立 PDF 文件。</li> <li>輕鬆查看和驗證您的 PDF 輸出文件。</li> </ol> </div>

C# + VB.NET: PDF生成設定 PDF生成設定
using IronPdf;
using IronPdf.Engines.Chrome;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Many rendering options to use to customize!
renderer.RenderingOptions.SetCustomPaperSizeInInches(12.5, 20);
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape;
renderer.RenderingOptions.Title = "My PDF Document Name";
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.WaitFor.RenderDelay(50); // in milliseconds
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen;
renderer.RenderingOptions.FitToPaperMode = FitToPaperModes.Zoom;
renderer.RenderingOptions.Zoom = 100;
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;

// Supports margin customization!
renderer.RenderingOptions.MarginTop = 40; //millimeters
renderer.RenderingOptions.MarginLeft = 20; //millimeters
renderer.RenderingOptions.MarginRight = 20; //millimeters
renderer.RenderingOptions.MarginBottom = 40; //millimeters

// Can set FirstPageNumber if you have a cover page
renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a cover page will be appended

// Settings have been set, we can render:
renderer.RenderHtmlFileAsPdf("assets/wikipedia.html").SaveAs("output/my-content.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com

<p>IronPDF 致力於為開發者提供最大的靈活性。</p> <p>In this<a href="/blog/using-ironpdf/csharp-generate-pdf-tutorial/" target="_blank" rel="nofollow noopener noreferrer">C# PDF 生成教學範例</a>,在此,我們展示了提供自動化內部功能的 API 與提供可讓您控制的 API 之間的平衡。</p> <p>IronPDF支持生成PDF文件的多種自定義選項,包括:頁面大小、頁面邊距、頁首/頁尾內容、內容縮放、CSS規則集和JavaScript執行。</p> <hr class="separator"> <p>我们希望开发者能够控制 Chrome 如何将网页转换为 PDF。 這<a href="/object-reference/api/IronPdf.ChromePdfRenderOptions.html" target="_blank" rel="nofollow noopener noreferrer"><code>ChromePdfRenderer</code> 類別概述</a>使這成為可能。</p> <p><code>ChromePDFRenderOptions</code> 類別上可用的設置示例包括邊距、頁眉、頁腳、紙張大小和表單創建的設置。</p>

C# + VB.NET: HTML或圖像文件轉換為PDF HTML或圖像文件轉換為PDF
using IronPdf;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Create a PDF from an existing HTML file using C#
var pdf = renderer.RenderHtmlFileAsPdf("example.html");

// Export to a file or Stream
pdf.SaveAs("output.pdf");
Imports IronPdf

' Instantiate Renderer
Private renderer = New ChromePdfRenderer()

' Create a PDF from an existing HTML file using C#
Private pdf = renderer.RenderHtmlFileAsPdf("example.html")

' Export to a file or Stream
pdf.SaveAs("output.pdf")

<p>IronPDF 是一個功能強大的 .NET 函式庫,能夠將 HTML 文件轉換成高品質的 PDF 文件。 使用 IronPDF,您只需幾行代碼即可將 HTML 檔案轉換成 PDF,並且由於其對現代 Web 標準的支持,生成的 PDF 檔會以像素完美的效果呈現。 利用IronPDF強大的HTML文件轉PDF功能變得很簡單,這要歸功於它使用了<code>ChromePdfRenderer</code>類,這使得HTML到PDF的轉換變得輕而易舉。</p> <div class="examples__featured-snippet"> <h2>使用 IronPDF 將 HTML 文件轉換為 PDF 的步驟</h2> <ol> <li>安裝 C# IronPDF 庫以將 HTML 轉換為 PDF。</li> <li><code>使用 IronPdf;</code></li> <li><code>var renderer = new ChromePdfRenderer();</code></li> <li><code>var pdf = renderer.RenderHtmlFileAsPdf("example.html");</code></li> <li><code>pdf.SaveAs("output.pdf");</code></li> </ol> </div> <p>此程式碼從 HTML 文件生成一個新的 PDF 文件。要實現這一點,我們必須首先確保 IronPDF 庫已安裝並通過 <code>using IronPdf</code> 行包含在您的專案中。接下來,初始化 ChromePdfRenderer 類,該類提供將 HTML 內容渲染為 PDF 的功能,確保在轉換過程中不丟失 HTML 文件的原始品質。</p> <p>一旦渲染器被實例化,您可以使用 <code>RenderHtmlAsPdf</code> 方法將現有的 HTML 文件轉換為 PDF。 在這個範例中,HTML 檔案 &quot;example.html&quot; 被傳遞給方法,創建一個 PDF 物件。 最後,使用 <code>SaveAs</code> 方法來儲存生成的 PDF,指定所需的檔案名稱和位置。 此簡單過程使您能夠在 C# 應用程式中輕鬆將 HTML 檔案生成 PDF。 <a href="/how-to/html-file-to-pdf/" class="code_content__related-link__doc-cta-link">點擊這裡查看使用指南,包括範例、範例代碼和文件。</a></p>

C# + VB.NET: ASPX 到 PDF 設定 ASPX 到 PDF 設定
using IronPdf;

var PdfOptions = new IronPdf.ChromePdfRenderOptions()
{
    CreatePdfFormsFromHtml = true,
    EnableJavaScript = false,
    Title = "My ASPX Page Rendered as a PDF"
    //.. many more options available
};

AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.Attachment, "MyPdfFile.pdf", PdfOptions);
Imports IronPdf

Private PdfOptions = New IronPdf.ChromePdfRenderOptions() With {
	.CreatePdfFormsFromHtml = True,
	.EnableJavaScript = False,
	.Title = "My ASPX Page Rendered as a PDF"
}

AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.Attachment, "MyPdfFile.pdf", PdfOptions)

<p>此示例展示了使用者如何更改 PDF 打印選項以將表單轉換為 HTML。</p> <p>IronPDF 的<a href="/how-to/aspx-to-pdf/" target="_blank" rel="nofollow noopener noreferrer">ASPX 到 PDF 轉換指南</a>功能具有多種選項,可將 HTML 從字符串或文件轉換為 PDF。</p> <p>特別重要的兩個選項是:</p> <ul> <li>允許開發者在轉換過程中指定是否應將HTML表單渲染為互動式PDF表單。</li> <li>允許開發者指定PDF應該「在瀏覽器中」顯示,還是作為文件下載。</li> </ul>

C# + VB.NET: 圖片轉PDF 圖片轉PDF
using IronPdf;
using System.IO;
using System.Linq;

// One or more images as IEnumerable. This example selects all JPEG images in a specific 'assets' folder.
var imageFiles = Directory.EnumerateFiles("assets").Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));

// Converts the images to a PDF and save it.
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("composite.pdf");

// Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails
Imports IronPdf
Imports System.IO
Imports System.Linq

' One or more images as IEnumerable. This example selects all JPEG images in a specific 'assets' folder.
Private imageFiles = Directory.EnumerateFiles("assets").Where(Function(f) f.EndsWith(".jpg") OrElse f.EndsWith(".jpeg"))

' Converts the images to a PDF and save it.
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("composite.pdf")

' Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails

<p>使用 <code>IronPdf.ImageToPdfConverter</code> 類別從一個或多個圖像文件構建 PDF。</p> <h2 id="anchor-36-49c-num-36-49pdf">如何在C&num;中將圖像轉換為PDF</h2> <p>給定位於電腦 <code>C:\images\example.png</code> 上的單一圖片,我們可以通過調用 <code>IronPdf.ImageToPdfConverter.ImageToPdf</code> 方法及其文件路徑,迅速將其轉換成 PDF 文件。</p> <pre class='naked-code'><code class="language-cs">IronPdf.ImageToPdfConverter.ImageToPdf(@"C:\images\example.png").SaveAs("example.pdf");</code></pre> <div class="code-content code-content-inner"> <div class="code_window" > <div class="language-selection__content-page-wrapper"> </div> <div class="code_window_content"> <div class="code-window__action-buttons-wrapper code-window__action-buttons-wrapper--content-page"> <button title="點擊複製" class=" code-window__action-button code-window__action-button--copy copy-clipboard " data-copy-text="點擊複製" data-copied-text="已複製到剪貼板" data-clipboard-id="code-explorer" data-placement="bottom" > <i class="fa-kit fa-copy-example"></i> </button> <button title="全螢幕模式" class=" code-window__action-button code-window__action-button--full-screen js-full-screen-code-example-modal " > <i class="fas fa-expand"></i> </button> <button title="退出全螢幕" class=" code-window__action-button code-window__action-button--exit-full-screen js-exit-full-screen-code-example-modal " > <i class="fas fa-compress"></i> </button> </div> <pre class="prettyprint linenums lang-cs"><code>IronPdf.ImageToPdfConverter.ImageToPdf(@"C:\images\example.png").SaveAs("example.pdf");</code></pre> <pre class="prettyprint linenums lang-vb"><code>IronPdf.ImageToPdfConverter.ImageToPdf(&quot;C:\images\example.png&quot;).SaveAs(&quot;example.pdf&quot;)</code></pre> </div> <div class="code_window_bottom"> <span class="language_selection"> <span class="ls-span">VB &nbsp;</span> <span> <label class="switch"> <input type="checkbox" checked="checked"> <span class="slider round"></span> </label> </span> <span class="ls-span">C#</span> </span> </div> </div> </div> <h2 id="anchor-36-49pdf36-49">將多個圖像合併成一個PDF文件</h2> <p>我們也可以使用 <code>System.IO.Directory.EnumerateFiles</code> 以及 <code>ImageToPdfConverter.ImageToPdf</code> 將圖片批量轉換成一個 PDF 文件。</p> <pre class='naked-code'><code class="language-cs">string sourceDirectory = "D:\web\assets"; string destinationFile = "JpgToPDF.pdf"; var imageFiles = Directory.EnumerateFiles(sourceDirectory, "*.jpg"); ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(destinationFile);</code></pre> <div class="code-content code-content-inner"> <div class="code_window" > <div class="language-selection__content-page-wrapper"> </div> <div class="code_window_content"> <div class="code-window__action-buttons-wrapper code-window__action-buttons-wrapper--content-page"> <button title="點擊複製" class=" code-window__action-button code-window__action-button--copy copy-clipboard " data-copy-text="點擊複製" data-copied-text="已複製到剪貼板" data-clipboard-id="code-explorer" data-placement="bottom" > <i class="fa-kit fa-copy-example"></i> </button> <button title="全螢幕模式" class=" code-window__action-button code-window__action-button--full-screen js-full-screen-code-example-modal " > <i class="fas fa-expand"></i> </button> <button title="退出全螢幕" class=" code-window__action-button code-window__action-button--exit-full-screen js-exit-full-screen-code-example-modal " > <i class="fas fa-compress"></i> </button> </div> <pre class="prettyprint linenums lang-cs"><code>string sourceDirectory = "D:\web\assets"; string destinationFile = "JpgToPDF.pdf"; var imageFiles = Directory.EnumerateFiles(sourceDirectory, "*.jpg"); ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(destinationFile);</code></pre> <pre class="prettyprint linenums lang-vb"><code>Dim sourceDirectory As String = &quot;D:\web&quot; &amp; ChrW(7) &amp; &quot;ssets&quot; Dim destinationFile As String = &quot;JpgToPDF.pdf&quot; Dim imageFiles = Directory.EnumerateFiles(sourceDirectory, &quot;*.jpg&quot;) ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(destinationFile)</code></pre> </div> <div class="code_window_bottom"> <span class="language_selection"> <span class="ls-span">VB &nbsp;</span> <span> <label class="switch"> <input type="checkbox" checked="checked"> <span class="slider round"></span> </label> </span> <span class="ls-span">C#</span> </span> </div> </div> </div> <p>探索更多有關內容<a href="/how-to/image-to-pdf/" target="_blank" rel="nofollow noopener noreferrer">使用 IronPDF 將圖像轉換為 PDF</a>以增強您的應用程式,或造訪<a href="https://ironsoftware.com" target="__blank">Iron Software 網站</a>探索由Iron Software提供的整套開發者工具,包括IronBarcode、IronOCR等。</p>

C# + VB.NET: 頁首和頁尾 頁首和頁尾
using IronPdf;

// Initiate PDF Renderer
var renderer = new ChromePdfRenderer();

// Add a header to every page easily
renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a cover page  will be appended
renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
renderer.RenderingOptions.TextHeader.CenterText = "{url}";
renderer.RenderingOptions.TextHeader.Font = IronSoftware.Drawing.FontTypes.Helvetica;
renderer.RenderingOptions.TextHeader.FontSize = 12;
renderer.RenderingOptions.MarginTop = 25; //create 25mm space for header

// Add a footer too
renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
renderer.RenderingOptions.TextFooter.Font = IronSoftware.Drawing.FontTypes.Arial;
renderer.RenderingOptions.TextFooter.FontSize = 10;
renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";
renderer.RenderingOptions.MarginTop = 25; //create 25mm space for footer

// Mergeable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
Imports IronPdf

' Initiate PDF Renderer
Private renderer = New ChromePdfRenderer()

' Add a header to every page easily
renderer.RenderingOptions.FirstPageNumber = 1 ' use 2 if a cover page  will be appended
renderer.RenderingOptions.TextHeader.DrawDividerLine = True
renderer.RenderingOptions.TextHeader.CenterText = "{url}"
renderer.RenderingOptions.TextHeader.Font = IronSoftware.Drawing.FontTypes.Helvetica
renderer.RenderingOptions.TextHeader.FontSize = 12
renderer.RenderingOptions.MarginTop = 25 'create 25mm space for header

' Add a footer too
renderer.RenderingOptions.TextFooter.DrawDividerLine = True
renderer.RenderingOptions.TextFooter.Font = IronSoftware.Drawing.FontTypes.Arial
renderer.RenderingOptions.TextFooter.FontSize = 10
renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}"
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}"
renderer.RenderingOptions.MarginTop = 25 'create 25mm space for footer

' Mergeable fields are:
' {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}

<p>PDF 文件可以用兩種不同的方式添加頁首和頁尾。</p> <ul> <li> <p>經典文本頁首和頁尾,允許添加基於文本的頁首,並選擇合併動態數據。</p> <p>-<a href="/examples/html-headers-and-footers/" target="_blank" rel="nofollow noopener noreferrer">使用 IronPDF 的 HTML 標頭和頁尾</a>,允許開發人員將 HTML 頁眉和頁腳渲染為 PDF 文件,還能夠促進動態數據的模板化。 此方法更具靈活性,雖然使用起來較為困難。</p> <p><code>TextHeaderFooter</code> 類別在 IronPDF 中定義了 PDF 頁眉和頁腳的顯示選項。 這採用邏輯方法來呈現最常見用例的頁首和頁尾。</p> <p>在此示例中,我們將向您展示如何在IronPDF中為您的PDF文件添加經典的文字頁首和頁尾。</p> <p>在添加頁首和頁尾到您的文件時,您可以選擇將頁首文本設置為在PDF文件上居中。 您也可以使用占位符字符串将元数据合并到标题中。 您可以在以下位置找到這些佔位符字串<a href="/object-reference/api/IronPdf.TextHeaderFooter.html" target="_blank" rel="nofollow noopener noreferrer">TextHeaderFooter API 文件資料</a>. 您還可以在每個 PDF 文件頁面的標頭或頁腳與頁面內容之間添加水平分隔線,影響字體和字體大小等。這是一個非常實用的功能,滿足所有要求。</p> </li> </ul>

C# + VB.NET: HTML 標頭與頁尾 HTML 標頭與頁尾
using IronPdf;
using System;

// Instantiate Renderer
var renderer = new IronPdf.ChromePdfRenderer();


// Build a footer using html to style the text
// mergeable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
    MaxHeight = 15, //millimeters
    HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
    DrawDividerLine = true
};

// Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginBottom = 25; //mm


// Build a header using an image asset
// Note the use of BaseUrl to set a relative path to the assets
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    MaxHeight = 20, //millimeters
    HtmlFragment = "<img src='logo.png'>",
    BaseUrl = new Uri(@"C:\assets\images\").AbsoluteUri
};

// Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginTop = 25; //mm
Imports IronPdf
Imports System

' Instantiate Renderer
Private renderer = New IronPdf.ChromePdfRenderer()


' Build a footer using html to style the text
' mergeable fields are:
' {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter() With {
	.MaxHeight = 15,
	.HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
	.DrawDividerLine = True
}

' Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginBottom = 25 'mm


' Build a header using an image asset
' Note the use of BaseUrl to set a relative path to the assets
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
	.MaxHeight = 20,
	.HtmlFragment = "<img src='logo.png'>",
	.BaseUrl = (New Uri("C:\assets\images\")).AbsoluteUri
}

' Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginTop = 25 'mm

<p>HTML 頭部和尾部被渲染為獨立的 HTML 文件,它們可能有自己的資源和樣式表。 它讓開發人員完全控制其頁首和頁尾的外觀。 渲染的頁眉或頁腳的高度可以控制以精確匹配其內容。</p> <p>在此範例中,我們將展示如何在IronPDF中為您的PDF文件添加HTML頁首和頁尾。</p> <p>當您將它們添加到您的項目中時,HTML頁首或頁尾將被打印到PDF的每一頁上。 此可用於覆蓋<a href="/examples/headers-and-footers/" target="_blank" rel="nofollow noopener noreferrer">IronPDF 經典頁首和頁尾範例</a>.</p> <p>使用 <code>HtmlHeaderFooter</code> 時,設定 <code>HtmlFragment</code> 是非常重要的,它將用於渲染頁眉或頁腳。 <code>html 它應該是一個HTML片段而不是一個完整的文件。 </code> 它也可能包含樣式和圖片。</p> <p>您也可以使用以下占位符字符串之一将元数据合并到您的HTML中,例如<code>{頁面} {總頁數} {網址} {日期} {時間} {html-標題} {pdf-title}</code>.</p>

C# + VB.NET: 表單數據 表單數據
using IronPdf;
using System;

// Step 1.  Creating a PDF with editable forms from HTML using form and input tags
// Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
const string formHtml = @"
    <html>
        <body>
            <h2>Editable PDF  Form</h2>
            <form>
              First name: <br> <input type='text' name='firstname' value=''> <br>
              Last name: <br> <input type='text' name='lastname' value=''> <br>
              <br>
              <p>Please specify your gender:</p>
              <input type='radio' id='female' name='gender' value= 'Female'>
                <label for='female'>Female</label> <br>
                <br>
              <input type='radio' id='male' name='gender' value='Male'>
                <label for='male'>Male</label> <br>
                <br>
              <input type='radio' id='non-binary/other' name='gender' value='Non-Binary / Other'>
                <label for='non-binary/other'>Non-Binary / Other</label>
              <br>

              <p>Please select all medical conditions that apply:</p>
              <input type='checkbox' id='condition1' name='Hypertension' value='Hypertension'>
              <label for='condition1'> Hypertension</label><br>
              <input type='checkbox' id='condition2' name='Heart Disease' value='Heart Disease'>
              <label for='condition2'> Heart Disease</label><br>
              <input type='checkbox' id='condition3' name='Stoke' value='Stoke'>
              <label for='condition3'> Stoke</label><br>
              <input type='checkbox' id='condition4' name='Diabetes' value='Diabetes'>
              <label for='condition4'> Diabetes</label><br>
              <input type='checkbox' id='condition5' name='Kidney Disease' value='Kidney Disease'>
              <label for='condition5'> Kidney Disease</label><br>
            </form>
        </body>
    </html>";

// Instantiate Renderer
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf");

// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");

// Set and Read the value of the "firstname" field
var FirstNameField = FormDocument.Form.FindFormField("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);

// Set and Read the value of the "lastname" field
var LastNameField = FormDocument.Form.FindFormField("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);

FormDocument.SaveAs("FilledForm.pdf");
Imports IronPdf
Imports System

' Step 1.  Creating a PDF with editable forms from HTML using form and input tags
' Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
Private Const formHtml As String = "
    <html>
        <body>
            <h2>Editable PDF  Form</h2>
            <form>
              First name: <br> <input type='text' name='firstname' value=''> <br>
              Last name: <br> <input type='text' name='lastname' value=''> <br>
              <br>
              <p>Please specify your gender:</p>
              <input type='radio' id='female' name='gender' value= 'Female'>
                <label for='female'>Female</label> <br>
                <br>
              <input type='radio' id='male' name='gender' value='Male'>
                <label for='male'>Male</label> <br>
                <br>
              <input type='radio' id='non-binary/other' name='gender' value='Non-Binary / Other'>
                <label for='non-binary/other'>Non-Binary / Other</label>
              <br>

              <p>Please select all medical conditions that apply:</p>
              <input type='checkbox' id='condition1' name='Hypertension' value='Hypertension'>
              <label for='condition1'> Hypertension</label><br>
              <input type='checkbox' id='condition2' name='Heart Disease' value='Heart Disease'>
              <label for='condition2'> Heart Disease</label><br>
              <input type='checkbox' id='condition3' name='Stoke' value='Stoke'>
              <label for='condition3'> Stoke</label><br>
              <input type='checkbox' id='condition4' name='Diabetes' value='Diabetes'>
              <label for='condition4'> Diabetes</label><br>
              <input type='checkbox' id='condition5' name='Kidney Disease' value='Kidney Disease'>
              <label for='condition5'> Kidney Disease</label><br>
            </form>
        </body>
    </html>"

' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf")

' Step 2. Reading and Writing PDF form values.
Dim FormDocument = PdfDocument.FromFile("BasicForm.pdf")

' Set and Read the value of the "firstname" field
Dim FirstNameField = FormDocument.Form.FindFormField("firstname")
FirstNameField.Value = "Minnie"
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value)

' Set and Read the value of the "lastname" field
Dim LastNameField = FormDocument.Form.FindFormField("lastname")
LastNameField.Value = "Mouse"
Console.WriteLine("LastNameField value: {0}", LastNameField.Value)

FormDocument.SaveAs("FilledForm.pdf")

<div class="alert alert-info iron-variant-1" role="alert"> 您的企業在每年的 PDF 安全和合規訂閱上花費過多。 考慮 <a href="https://ironsoftware.com/enterprise/securedoc/">IronSecureDoc,一個全面的 PDF 安全解決方案</a>,提供用於管理數位簽名、編輯、加密和保護等SaaS服務的解決方案,且僅需一次性付款。 <a href="https://ironsoftware.com/enterprise/securedoc/docs/">探索 IronSecureDoc 文件</a> </div> <p>您可以像編輯普通文件一樣輕鬆地使用IronPDF創建可編輯的PDF文件。 <code>PdfForm</code> 類別是 PDF 文檔中一系列用戶可編輯的表單字段。 它可以整合到您的 PDF 渲染器中,使其成為表單或可編輯文件。</p> <p>此示例展示如何在IronPDF中創建可編輯的PDF表格。</p> <p>PDF有可編輯表單可由HTML簡單添加<code>&lt;form&gt;</code>, <code>&lt;input&gt;</code>, 和 <code>&lt;textarea&gt;將</code><p>` 標籤添加到文件部分。</p> <p><code>PdfDocument.Form.FindFormField</code> 可以用來讀寫任何表單欄位的值。 該欄位的名稱將與您的HTML中該欄位的'name'屬性相同。</p> <p><code>PdfDocument.Form</code> 物件可以有兩種使用方式。</p> <ul> <li>首先是填充表單欄位的預設值,必須在Adobe Reader中聚焦才能顯示此值。</li> <li>第二個功能是讀取使用者以任何語言填寫的PDF表格中的數據。</li> </ul>

C# + VB.NET: 將 PDF 光柵化為圖像 將 PDF 光柵化為圖像
using IronPdf;
using IronSoftware.Drawing;

var pdf = PdfDocument.FromFile("Example.pdf");

// Extract all pages to a folder as image files
pdf.RasterizeToImageFiles(@"C:\image\folder\*.png");

// Dimensions and page ranges may be specified
pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", 100, 80);

// Extract all pages as AnyBitmap objects
AnyBitmap[] pdfBitmaps = pdf.ToBitmap();
Imports IronPdf
Imports IronSoftware.Drawing

Private pdf = PdfDocument.FromFile("Example.pdf")

' Extract all pages to a folder as image files
pdf.RasterizeToImageFiles("C:\image\folder\*.png")

' Dimensions and page ranges may be specified
pdf.RasterizeToImageFiles("C:\image\folder\example_pdf_image_*.jpg", 100, 80)

' Extract all pages as AnyBitmap objects
Dim pdfBitmaps() As AnyBitmap = pdf.ToBitmap()

<p>使用 IronPDF 將 PDF 轉換成您偏好的檔案類型、影像尺寸和 DPI 品質的圖片。</p> <p>要將 PDF 文檔轉換成圖像,請在 <code>PdfDocument</code> 物件上調用 IronPDF 的 <code>RasterizeToImageFiles</code> 方法。 PDF文件可以使用<code>PdfDocument.FromFile</code>方法或其他可用方法加載。<a href="/tutorials/dotnet-core-pdf-generating/" target="_blank" rel="nofollow noopener noreferrer">.NET Core 的 PDF 生成方法</a>.</p> <hr /> <p><div class="main-article__video-wrapper js-article-video-modal-wrapper"><iframe class="" loading="lazy" src="https://www.youtube.com/embed/1MdE_nGu0UM?start=0" title="YouTube Video Player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></p> <hr /> <p><code>RasterizeToImageFiles</code> 將 PDF 的每一頁渲染為光柵圖像。 第一個參數指定每個影像使用的命名模式。 選用參數可用於自訂每個影像的品質和尺寸。 另一個選項允許該方法將選定的 PDF 頁面轉換為圖像。</p> <p>第24行的代碼示例演示了<code>ToBitMap</code>方法。 調用此方法於任何 <code>PdfDocument</code> 物件上,以快速將 PDF 轉換成可以保存到文件或根據需要操作的 <code>AnyBitmap</code> 物件。</p> <hr /> <div class="hsg-featured-snippet"> <h2>如何在 C# 中將 PDF 轉換為圖像</h2> <ol> <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronPdf/" target="_blank" rel="nofollow noopener noreferrer">安裝 PDF 到圖片 C# 函式庫</a></li> <li>匯入現有 PDF 檔案 透過 <code>從文件</code> 方法</li> <li>使用將PDF轉換為圖片 <code>光柵化為圖像檔案</code> 方法</li> <li>指定儲存目錄和圖片大小</li> <li>檢查輸出圖片</li> </ol> </div>

C# + VB.NET: 編輯PDF文件 編輯PDF文件
using IronPdf;
using System.Collections.Generic;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Join Multiple Existing PDFs into a single document
var pdfs = new List<PdfDocument>();
pdfs.Add(PdfDocument.FromFile("A.pdf"));
pdfs.Add(PdfDocument.FromFile("B.pdf"));
pdfs.Add(PdfDocument.FromFile("C.pdf"));
var pdf = PdfDocument.Merge(pdfs);
pdf.SaveAs("merged.pdf");

// Add a cover page
pdf.PrependPdf(renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"));

// Remove the last page from the PDF and save again
pdf.RemovePage(pdf.PageCount - 1);
pdf.SaveAs("merged.pdf");

// Copy pages 5-7 and save them as a new document.
pdf.CopyPages(4, 6).SaveAs("excerpt.pdf");

foreach (var eachPdf in pdfs)
{
    eachPdf.Dispose();
}
Imports IronPdf
Imports System.Collections.Generic

' Instantiate Renderer
Private renderer = New ChromePdfRenderer()

' Join Multiple Existing PDFs into a single document
Private pdfs = New List(Of PdfDocument)()
pdfs.Add(PdfDocument.FromFile("A.pdf"))
pdfs.Add(PdfDocument.FromFile("B.pdf"))
pdfs.Add(PdfDocument.FromFile("C.pdf"))
Dim pdf = PdfDocument.Merge(pdfs)
pdf.SaveAs("merged.pdf")

' Add a cover page
pdf.PrependPdf(renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"))

' Remove the last page from the PDF and save again
pdf.RemovePage(pdf.PageCount - 1)
pdf.SaveAs("merged.pdf")

' Copy pages 5-7 and save them as a new document.
pdf.CopyPages(4, 6).SaveAs("excerpt.pdf")

For Each eachPdf In pdfs
	eachPdf.Dispose()
Next eachPdf

<p>IronPDF 提供<a href="/features/" target="_blank" rel="nofollow noopener noreferrer">50 多項功能</a>用於閱讀和編輯PDF文件。 最受歡迎的是<a href="/how-to/merge-or-split-pdfs/" target="_blank" rel="nofollow noopener noreferrer">合併PDFs</a>, <a href="/examples/copy-pdf-page-to-another-pdf-file/" target="_blank" rel="nofollow noopener noreferrer">克隆頁面</a>,和<a href="/how-to/rotating-text/" target="_blank" rel="nofollow noopener noreferrer">從旋轉內容中提取文本</a>.</p> <p>IronPDF還允許用戶在生成和格式化PDF文件時添加水印、旋轉頁面、添加註釋、數位簽署PDF頁面、創建新的PDF文件、附加封面頁、自訂PDF尺寸等等。 此外,它支持將PDF轉換成所有常見的圖像文件類型,包括JPG、BMP、JPEG、GIF、PNG、TIFF等。</p> <p>讀取<a href="/tutorials/csharp-edit-pdf-complete-tutorial/" target="_blank" rel="nofollow noopener noreferrer">C# PDF 編輯教程</a>了解如何充分利用IronPDF來修改PDF文件,以最佳符合項目需求。</p> <hr /> <div class="hsg-featured-snippet"> <h2>如何在 C# 中編輯 PDF 文件</h2> <ol> <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronPdf/" target="_blank" rel="nofollow noopener noreferrer">安裝可以編輯 PDF 檔案的 C# 庫</a></li> <li>利用 `FromFile` 方法匯入多個 PDF 文件</li> <li>使用直觀的 API 在 C# 中訪問和修改 PDF 文件</li> <li>使用 C# 將更新的版本另存為新的 PDF 文件</li> <li>查看新編輯的PDF文件</li> </ol> </div>

C# + VB.NET: 密碼、安全性和元數據 密碼、安全性和元數據
using IronPdf;

// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Get file metadata
System.Collections.Generic.List<string> metadatakeys = pdf.MetaData.Keys(); // returns {"Title", "Creator", ...}

// Remove file metadata
pdf.MetaData.RemoveMetaDataKey("Title");
metadatakeys = pdf.MetaData.Keys(); // return {"Creator", ...} // title was deleted

// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = System.DateTime.Now;

// The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;

// Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret"; // password to edit the pdf
pdf.SecuritySettings.UserPassword = "sharable"; // password to open the pdf
pdf.SaveAs("secured.pdf");
Imports System
Imports IronPdf

' Open an Encrypted File, alternatively create a new PDF from Html
Private pdf = PdfDocument.FromFile("encrypted.pdf", "password")

' Get file metadata
Private metadatakeys As System.Collections.Generic.List(Of String) = pdf.MetaData.Keys() ' returns {"Title", "Creator", ...}

' Remove file metadata
pdf.MetaData.RemoveMetaDataKey("Title")
metadatakeys = pdf.MetaData.Keys() ' return {"Creator", ...} // title was deleted

' Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto"
pdf.MetaData.Keywords = "SEO, Friendly"
pdf.MetaData.ModifiedDate = DateTime.Now

' The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights

' Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret" ' password to edit the pdf
pdf.SecuritySettings.UserPassword = "sharable" ' password to open the pdf
pdf.SaveAs("secured.pdf")

<p>IronPDF為開發者提供強大的PDF安全選項,支持自訂與設置PDF的元數據、密碼、許可權等。 使用 IronPDF 的密碼、安全性和中繼資料選項,您可以針對您的 PDF 文件需求創建自訂許可與安全等級。 這是通過使用如 <code>SecuritySettings</code> 和 <code>MetaData</code> 類別等類別來完成的。 一些選項包括將 PDF 文件設置為不可列印、設置為唯讀、使用 128 位加密以及對 PDF 文件進行密碼保護。</p> <p>設置自定義元數據的工作原理是通過實施 MetaData 類來訪問各種 PDF 元數據選項,並使用自定義值設置它們。 這包括更改作者、關鍵字、修改數據等。 設定自訂安全性設置包括能夠設置自訂用戶和擁有者密碼、列印權限、只讀模式等。</p> <div class="examples__featured-snippet"> <h2>設定 PDF 密碼、元數據和安全性的 5 個步驟</h2> <ol> <li><code>var pdf = PdfDocument.FromFile("encrypted.pdf", "password");</code></li> <li><code>System.Collections.Generic.List&lt;string&gt; metadatakeys = pdf.MetaData.Keys();</code></li> <li><code>var metadatakeys = pdf.MetaData.Keys();</code></li> <li><code>pdf.MetaData.Author = "Satoshi Nakamoto";</code></li> <li><code>pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");</code></li> </ol> </div> <p>若要開始自定義 PDF 文件的安全性,你必須先加載現有的 PDF 或創建新的 PDF。 在這裡,我們已加載了一個現有的受密碼保護的 PDF 文件,並輸入了開啟 PDF 文件所需的密碼。 一旦載入 PDF,我們接著使用 <code>pdf.MetaData.Keys</code>()使用 <code>;</code> 來獲取 PDF 的當前元數據。 要移除現有的 PDF 元數據值,請使用 <code>RemoveMetaDataKey</code> 方法。 要開始設定新的元數據值,使用 pdf.MetaData.metadatafield(例如 <code>pdf.MetaData.Keywords</code>),然後只需將新值賦予給它。 元數據欄位如標題和關鍵字採用字串值,而修改日期欄位則採用日期時間值。</p> <p>接下來,我們使用 SecuritySettings 類別設置了新的安全設定。 如您所見,您可以在此設置多種設定。 這讓您能完全控制您處理的每個 PDF 文件的權限和安全等級。 要訪問這些設置,您只需確保使用 <code>pdf.SecuritySettings</code>,然後選擇您想要調整的設置。例如,<code>MakePdfDocumentReadOnly</code> 屬性將 PDF 文檔設置為只讀,以 128 位加密內容。 SecuritySettings 的其他選項包括:</p> <ul> <li><strong>AllowUserAnnotations:</strong> 控制用戶是否可以註釋 PDF。</li> <li><strong>AllowUserPrinting:</strong> 控制文件的打印權限。</li> <li><strong>AllowUserFormData:</strong> 設置是否允許用戶填寫表單的權限。</li> <li><strong>OwnerPassword:</strong> 設定 PDF 的擁有者密碼,用於禁用或啟用其他安全設置。</li> <li> <p><strong>UserPassword:</strong> 設定 PDF 的使用者密碼,以便在開啟或列印文件時輸入。</p> <p>設定好自訂的中繼資料、密碼和安全性設定後,使用 <code>pdf.SaveAs</code> 方法將您的 PDF 存儲到指定位置。 <a href="/how-to/metadata/" class="code_content__related-link__doc-cta-link">點擊此處查看操作指南,包括範例、示例代碼和文件。</a></p> </li> </ul>

C# + VB.NET: PDF 加水印 PDF 加水印
using IronPdf;

// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();

var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
Imports IronPdf

' Stamps a Watermark onto a new or existing PDF
Private renderer = New ChromePdfRenderer()

Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)
pdf.SaveAs("C:\Path\To\Watermarked.pdf")

<p>IronPDF 提供使用 HTML 對 PDF 文件進行「水印」的方法。</p> <p>使用 <code>ApplyStamp</code> 方法,開發者可以在 PDF 文件中添加基於 HTML 的浮水印。如上例所示,浮水印的 HTML 代碼作為方法的第一個參數。 對 <code>ApplyStamp</code> 的額外參數可控制浮水印的旋轉、透明度和位置。</p> <p>使用 <code>ApplyStamp</code> 方法替代 <code>ApplyWatermark</code> 方法以獲得更細緻的浮水印放置控制。 例如,使用 <code>ApplyStamp</code> 來:</p> <ul> <li>向PDF添加文字、圖像或HTML水印</li> <li>將相同的浮水印應用於 PDF 的每個頁面</li> <li>對特定PDF頁面應用不同的浮水印</li> <li>調整浮水印在頁面副本前或後的位置</li> <li> <p>更精確地調整浮水印的不透明度、旋轉和對齊方式</p> <p>請提供您要翻譯的內容。</p> <div class="hsg-featured-snippet"> <h2>如何在 C# 中將水印添加到 PDF 文件中</h2> <ol> <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronPdf/" target="_blank" rel="nofollow noopener noreferrer">從NuGet下載並安裝IronPDF庫。</a></li> <li>創建新的 <code>PdfDocument</code> 或使用現有的 <code>PdfDocument</code> 檔案。</li> <li>呼叫 <code>應用水印</code> 添加水印到 PDF 的方法。</li> <li>通過調用導出 PDF 文件 <code>另存為</code>.</li> </ol> </div> </li> </ul>

C# + VB.NET: 背景與前景 背景與前景
using IronPdf;

// With IronPDF, we can easily merge 2 PDF files using one as a background or foreground
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.AddBackgroundPdf(@"MyBackground.pdf");
pdf.AddForegroundOverlayPdfToPage(0, @"MyForeground.pdf", 0);
pdf.SaveAs(@"C:\Path\To\Complete.pdf");
Imports IronPdf

' With IronPDF, we can easily merge 2 PDF files using one as a background or foreground
Private renderer = New ChromePdfRenderer()
Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.AddBackgroundPdf("MyBackground.pdf")
pdf.AddForegroundOverlayPdfToPage(0, "MyForeground.pdf", 0)
pdf.SaveAs("C:\Path\To\Complete.pdf")

<p>在使用IronPDF創建和渲染PDF文件時,您可能會想要使用特定的背景和前景。 在這種情況下,您可以使用現有的或已渲染的PDF作為另一個PDF文件的背景或前景。 這對於設計一致性和模板化特別有用。</p> <p>此範例將展示如何將一份PDF文件作為另一份PDF文件的背景或前景使用。</p> <p>您可以在 C# 中通過加載或創建多頁 PDF 作為 <code>IronPdf.PdfDocument</code> 對象來實現。</p> <p>您可以使用 <code>PdfDocument.AddBackgroundPdf</code> 添加背景。 有關背景插入方法的更多詳細資訊,請參閱<a href="/object-reference/api/IronPdf.PdfDocument.html#IronPdf_PdfDocument_AddBackgroundPdf_IronPdf_PdfDocument_System_Int32_" target="_blank" rel="nofollow noopener noreferrer">IronPDF.PdfDocument 背景檔介紹文檔</a>; 它描述了幾種背景插入方法及其覆寫。 這在您正在處理的PDF的每個頁面上增加了背景。 背景是從另一個PDF文件的頁面複製的。</p> <p>您可以使用 <code>PdfDocument.AddForegroundOverlayPdfToPage</code> 添加前景,亦稱為「覆蓋層」。 有關前景插入方法的詳細資訊,請參閱<a href="/object-reference/api/IronPdf.PdfDocument.html" target="_blank" rel="nofollow noopener noreferrer">IronPDF.PdfDocument 疊加文件</a>.</p>

Human Support related to .NET Core PDF 庫

支援 .NET Core 程式碼編寫者

無論是技術問題還是銷售問題,Iron 團隊都會隨時在旁協助解決您的大多數問題。聯繫 Iron,以在您的專案中最大程度地利用我們的庫。

聯絡我們
C# .NET HTML轉PDF

C# 和 VB 用於 .NET Core 的 HTML-to-PDF 函式庫

IronPDF使用Chromium渲染器將HTML檔案轉換為PDF文件,適用於 .NET Chromium。不需要API來定位或佈局PDF:IronPDF使用標準的HTML、ASPX、JS、CSS和圖像。

查看教程
C# .NET PDF OCR 函式庫

讀取 PDF 文本

IronPDF 允許您從 PDF 中提取所有嵌入的文本內容,並將其傳遞到您的 C# 和 .NET Core 應用程序。將 PDF 檔案中的內容導入到您的業務流程系統中。

完整 API 參考資料
如何在 C# 中編輯 PDF 文件

在 .NET Core 中編輯 PDF

從附加、合併、分割和修改 PDF,利用您自己的編碼技巧,每次都精確獲得正確的 PDF。IronPDF 將開發功能專門交給您,放在您的 C#/VB .NET Core 項目中。

閱讀我們的文件
使用 .NET 代碼將 HTML5、JS、CSS 和圖像文件轉換為 PDF 文件。

支持您的文件類型

將 IronPDF .NET Core 函式庫指向您的 HTML 檔案、字串或 URL,輕鬆轉換為 PDF。這會使用您當前的文件和網站頁面將信息渲染為 PDF 文件。

適用於 ASP .NET Core, C#, VB, MVC, ASPX, .NET

立即設置
用於創建和編輯內容的 Visual Studio PDF 庫。

快速使用 Microsoft Visual Studio 开始

IronPDF 將 PDF 創建和編輯控制放在你手中,快速且具有完整的智能感知支持和 Visual Studio 安裝程序。使用 NuGet for Visual Studio 或下載 DLL。你只需片刻即可完成設置。只需一個 DLL。

PM > Install-Package IronPdf 下載DLL
支持:
  • .NET Core 2 及以上
  • .NET Framework 4.0及以上版本支持C#、VB、F#
  • Microsoft Visual Studio. .NET 開發 IDE 圖標
  • NuGet 安裝程式支援 Visual Studio
  • JetBrains ReSharper C# 語言助理相容
  • Microsoft Azure C#.NET 託管平台相容

授權與定價

免費 社區開發授權。商業授權起價 $749。

項目C# + VB.NET庫授權

專案

開發人員C# + VB.NET 庫許可證

開發人員

組織 C# + VB.NET 庫授權

組織

代理機構 C# + VB.NET 庫許可

代理商

SaaS C# + VB.NET 程式庫授權

SaaS

OEM C# + VB.NET 庫許可證

OEM

查看完整授權選項  

來自我們社區的 C# PDF 教程

教學 + 代碼範例 ASPX 轉 PDF | ASP.NET 教學

C# PDF ASP.NET ASPX

雅各布·穆勒 軟體產品設計師 @ Iron團隊

ASPX 轉換為 PDF | ASP.NET 教程

了解如何使用 C# 或 VB.NET 的一行程式碼將任何 ASP.NET ASPX 頁面轉換為 PDF 文件,而不是 HTML…

查看 Jacob 的 ASPX-to-PDF 範例
教學 + 範例代碼 C# HTML 轉 PDF | C Sharp 與 VB.NET 教學

C# PDF HTML

Jean Ashberg .NET軟體工程師

C# HTML 轉 PDF | C Sharp 及 VB.NET 教程

對於許多人來說,這是從 .NET 生成 PDF 文件的最有效方法,因為不需要學習額外的 API 或導航複雜的設計系統…

查看 Jean 的 HTML-To-PDF 範例
教程 + 代碼範例 VB.NET PDF 創建和編輯 | VB.NET & ASP.NET PDF

VB PDF ASP.NET

維羅妮卡·西拉  .NET 軟體工程師

VB.NET PDF創建和編輯 | VB.NET & ASP.NET PDF

學習如何在 VB.NET 應用程序和網站中創建和編輯 PDF 文件。免費教程附帶代碼示例……

查看 Veronica 的 VB.NET PDF 教程
數千名開發人員使用 IronPDF...

會計和金融系統

  • # 收據
  • # 報告
  • # 發票列印
為 ASP.NET 會計和財務系統添加 PDF 支持

企業數位化

  • # 文件資料
  • # 訂購與標籤
  • # 紙張替代
C# 業務數位化用例

企業內容管理

  • # 內容製作
  • # 文件管理
  • # 內容分發
.NET CMS PDF 支援

數據和報告應用程式

  • # 效能追蹤
  • # 趨勢映射
  • # 報告
C# PDF 報告
Iron Software 企業 .NET 組件開發者

成千上萬的企業、政府、中小企業和開發人員都信賴 Iron software 產品。

Iron 團隊在 .NET 軟體元件市場有超過 10 年的經驗。

GSK
Smith & Nephew
南澳大利亞政府
樂天
歐洲汽車租賃
土耳其航空公司
田納西州政府
3M