C# VB PDF .NET : 在Blazor中生成PDF 在Blazor中生成PDF
@using IronPdf;

public void ExportData()
{
    try
    {
        string fileName = "Demo.pdf";
        var Renderer = new IronPdf.ChromePdfRenderer();
        var pdf = Renderer.RenderUrlAsPdf("https://localhost:7018/fetchdata");
        JSRuntime.InvokeVoidAsync("saveAsFile", fileName, Convert.ToBase64String(pdf.Stream.ToArray()));
    }
    catch (Exception ex)
    {
    }
}
Private IronPdf As [using]

Public Sub ExportData()
	Try
		Dim fileName As String = "Demo.pdf"
		Dim Renderer = New IronPdf.ChromePdfRenderer()
		Dim pdf = Renderer.RenderUrlAsPdf("https://localhost:7018/fetchdata")
		JSRuntime.InvokeVoidAsync("saveAsFile", fileName, Convert.ToBase64String(pdf.Stream.ToArray()))
	Catch ex As Exception
	End Try
End Sub

<p>IronPDF允许开发人员在C#、F# 和 VB.NET 中为.NET Core 和 .NET Framework 轻松创建PDF文档。</p> <p>在这个例子中,我们展示了可以从任何 HTML 呈现 PDF 文档。 这使我们能够创建与现有网站的品牌形象紧密匹配的PDF文件。</p> <p>您可以选择类似上述的简单 HTML,也可以加入 CSS、图片和 JavaScript。</p> <p>This<a href="/tutorials/html-to-pdf/" target="_blank" rel="nofollow noopener noreferrer">HTML 到 PDF 的转换过程</a>此外,还可以将 PDF 设计工作委托给网页设计师,而不是后端编码员。</p> <p>IronPDF 使用<a href="/how-to/pixel-perfect-html-to-pdf/" target="_blank" rel="nofollow noopener noreferrer">像素完美的 Chrome 渲染引擎</a>将支持 CSS3 和 JavaScript 的 HTML5 转换为 PDF 文档。 其形式可以是字符串、外部文件或外部 URL,所有这些都可以使用 IronPDF 轻松呈现为 PDF。</p>

C# VB PDF .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 中使用。 由于使用了 &quot;ChromePdfRenderer &quot;类,您可以确保从 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>用 C# 将 HTML 字符串转换为 PDF 的第一步是确保在项目中正确设置并运行 IronPDF 库。 通过包括使用 IronPdf,我们要确保能从 IronPDF 库中访问所需的类,以进行 HTML 到 PDF 的转换。 翻译完成后,下一行 <code>Installation.EnableWebSecurity = true</code> 将用于禁止本地磁盘访问或跨源请求,确保安全操作。</p> <p>下一行将创建一个新的 ChromePdfRenderer 实例,处理 HTML 到 PDF 的转换。 在基本示例中,RenderHtmlAsPdf 方法用于转换一个简单的 HTML 字符串 `.(&quot;<h1>你好,世界</h1>&quot;)翻译成 PDF 文档,并使用 &quot;SaveAs &quot;方法保存到磁盘。</p> <p>在高级方法中,我们演示了 IronPdf 如何处理包含图片、CSS 和 JavaScript 等外部资产的 HTML 内容。 要加载这些资产,需要使用可选的 BasePath 参数,该参数指定了包含所需文件的目录。 生成的 PDF(包括外部资产)使用与基本示例中相同的 &quot;SaveAs &quot;方法保存。 该代码示例突出了 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 PDF .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 URL 渲染 PDF 可以促进 PDF 开发的顺利进行,是设计人员和编码人员之间的一项协作努力。</p> <hr /> <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 for .NET 从接受查询字符串变量的 ASP.NET URL 渲染 PDF 文件</li> <li>使用 IronPDF 直接从 URL 创建 PDF 文档</li> <li>轻松查看和验证您的PDF输出文档。</li> </ol> </div>

C# VB PDF .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。 &quot;(《世界人权宣言》)<a href="/object-reference/api/IronPdf.ChromePdfRenderOptions.html" target="_blank" rel="nofollow noopener noreferrer">ChromePdfRenderer`类概述</a>这一切都有赖于我们的翻译团队。</p> <p><code>ChromePDFRenderOptions</code> 类中可用的设置示例包括边距、页眉、页脚、纸张大小和表单创建的设置。</p>

C# VB PDF .NET : 将ASPX页面渲染为PDF 将ASPX页面渲染为PDF
using IronPdf;

private void Form1_Load(object sender, EventArgs e)
{
    //Changes the ASPX output into a pdf instead of HTML
    IronPdf.AspxToPdf.RenderThisPageAsPdf();
}
Imports IronPdf

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
	'Changes the ASPX output into a pdf instead of HTML
	IronPdf.AspxToPdf.RenderThisPageAsPdf()
End Sub

<p>使用IronPDF库,通过在<strong><code>Form_Load</code></strong>事件中添加一行代码,ASP.NET网页可以被渲染成PDF而不是HTML。</p> <p>此示例展示了IronPDF如何能够生成复杂的、数据驱动的PDF文件,这些文件首先以HTML的形式进行设计和测试,以简化流程。</p> <p>IronPDF 的<a href="/how-to/aspx-to-pdf/" target="_blank" rel="nofollow noopener noreferrer">ASPX 到 PDF 的转换</a>此功能允许您在ASPX页面中调用一个方法,它会返回一个PDF而不是HTML。</p> <p>您可以对 PDF 进行编码,使其既可以在浏览器中显示,也可以作为文件下载。</p>

C# VB PDF .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,而且由于它支持现代网络标准,生成的 PDF 文件将达到完美的像素效果。 由于 IronPDF 使用了 <code>ChromePdfRenderer</code> 类,可以轻松处理 HTML 到 PDF 的转换,因此利用 IronPDF 强大的 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 对象。 最后,要保存生成的 PDF,请使用 <code>SaveAs</code> 方法,指定所需的文件名和位置。 这个简单的过程可以让您在 C# 应用程序中轻松地从 HTML 文件生成 PDF。 <a href="/how-to/html-file-to-pdf/" class="code_content__related-link__doc-cta-link">点击此处查看操作指南,其中包括示例、示例代码和文件。</a></p>

C# VB PDF .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 PDF .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>使用 &quot;IronPdf.ImageToPdfConverter &quot;类从一个或多个图像文件生成 PDF。</p> <h2 id="anchor-36-49c-36-49pdf">如何在C#中将图像转换为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 软件网站</a>了解 Iron Software 提供的整个开发者工具套件,包括 IronBarcode、IronOCR 等。</p>

C# VB PDF .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 的每一页上。 This can be used to override<a href="/examples/headers-and-footers/" target="_blank" rel="nofollow noopener noreferrer">IronPDF 经典页眉和页脚示例</a>.</p> <p>在使用 <code>HtmlHeaderFooter</code> 时,设置 <code>HtmlFragment</code> 是很重要的,这将用于渲染页眉或页脚。 它应该是一个HTML片段,而不是一个完整的文档。 它也可能包含样式和图片。</p> <p>您也可以使用这些占位符字符串将元数据合并到您的HTML中,例如:<code>{页码} {总页数} {网址} {日期} {时间} {html-title} {pdf标题}</code>.</p>

C# VB PDF .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>经典文本页眉和页脚,可添加基于文本的页眉,并可选择合并动态数据。</li> <li> <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 PDF .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>用于阅读和编辑PDFs。 最受欢迎的是<a href="/how-to/merge-or-split-pdfs/" target="_blank" rel="nofollow noopener noreferrer">合并 PDF</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>使用 C# 中的直观 API 访问和修改 PDF 文件</li> <li>使用 C# 将更新版本保存为新的 PDF 文件</li> <li>查看新编辑的 PDF 文档</li> </ol> </div>

C# VB PDF .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 文档的需要。 要做到这一点,就必须使用 &quot;SecuritySettings &quot;和 &quot;MetaData &quot;等类。 一些选项包括将 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>获取 PDF 的当前元数据。 要移除现有的 PDF 元数据值,请使用 <code>RemoveMetaDataKey</code> 方法。 要开始设置新的元数据值,请使用 pdf.MetaData.metadatafield(例如:&quot;pdf.MetaData.Keywords)在翻译过程中,您可以使用&quot;.NET&quot;、&quot;Java&quot;、&quot;Python &quot;或 &quot;Node.js&quot;,然后将新值赋给它。 标题和关键词等元数据字段使用字符串值,而修改数据字段使用日期值。</p> <p>接下来,我们使用 SecuritySettings 类设置新的安全设置。 如您所见,您可以在这里进行多种设置。 这样,您就可以完全控制每个 PDF 文档的权限和安全级别。 要访问这些设置,您只需确保使用了 <code>pdf.SecuritySettings</code>,然后再使用您要调整的设置。例如,&quot;MakePdfDocumentReadOnly &quot;属性将 PDF 文档设置为只读,并对内容进行 128 位加密。 SecuritySettings 的其他选项包括</p> <ul> <li><strong>AllowUserAnnotations:</strong> 控制用户是否可以对 PDF 进行注释。</li> <li><strong>允许用户打印:</strong> 控制文档的打印权限。</li> <li><strong>AllowUserFormData:</strong> 设置用户是否可以填写表格的权限。</li> <li><strong>OwnerPassword:</strong> 设置 PDF 的所有者密码,用于禁用或启用其他安全设置</li> <li> <p><strong>用户密码:</strong> 设置 PDF 的用户密码,必须输入该密码才能打开或打印文档。</p> <p>为 PDF 文档设置自定义元数据、密码和安全设置后,使用 <code>pdf.SaveAs</code> 方法将 PDF 保存到指定位置。 <a href="/how-to/metadata/" class="code_content__related-link__doc-cta-link">点击此处查看操作指南,包括示例、示例代码和文件。</a></p> </li> </ul>

C# VB PDF .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 文档 &quot;加水印 &quot;的方法。</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>将文本、图片或HTML水印添加到PDFs</li> <li>将相同的水印应用到PDF的每一页上。</li> <li>将不同的水印应用于特定的PDF页面</li> <li>调整水印在页面副本前后的位置</li> <li> <p>更精确地调整水印的不透明度、旋转和对齐方式</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">从 NuGet 下载并安装 IronPDF 库。</a></li> <li>创建一个新的 <code>PdfDocument</code> 或使用现有的 <code>PdfDocument</code> 锉刀</li> <li>致电 <code>应用水印</code> 方法为 PDF 添加水印。</li> <li>通过调用 <code>保存为</code>.</li> </ol> </div> </li> </ul>

C# VB PDF .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>您可以通过将多页 PDF 加载或创建为 <code>IronPdf.PdfDocument</code> 对象,在 C# 中实现这一操作。</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>

C# VB PDF .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/">PDF 安全综合解决方案 IronSecureDoc</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带可编辑表单的文件可以通过添加<code>&lt;form&gt;</code>, <code>&lt;input&gt;和</code><textarea>将`标签添加到文档部分。</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 PDF .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> 方法。 可以使用 <code>PdfDocument.FromFile</code> 方法或其他可用方法加载 PDF 文档。<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>RasterizeToImageFiles &quot;可将 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 PDF .NET : 数字签署PDF 数字签署PDF
using IronPdf;
using IronPdf.Signing;

// Step 1. Create a PDF
var renderer = new ChromePdfRenderer();
var doc = renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>");

// Step 2. Create a Signature.
// You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
// Read: https://helpx.adobe.com/acrobat/using/digital-ids.html

var signature = new IronPdf.Signing.PdfSignature("Iron.pfx", "123456")
{
    // Step 3. Optional signing options and a handwritten signature graphic
    SigningContact = "support@ironsoftware.com",
    SigningLocation = "Chicago, USA",
    SigningReason = "To show how to sign a PDF"
};

//Step 3. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.Sign(signature);

//Step 4. The PDF is not signed until saved to file, steam or byte array.
doc.SaveAs("signed.pdf");
Imports IronPdf
Imports IronPdf.Signing

' Step 1. Create a PDF
Private renderer = New ChromePdfRenderer()
Private doc = renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>")

' Step 2. Create a Signature.
' You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
' Read: https://helpx.adobe.com/acrobat/using/digital-ids.html

Private signature = New IronPdf.Signing.PdfSignature("Iron.pfx", "123456") With {
	.SigningContact = "support@ironsoftware.com",
	.SigningLocation = "Chicago, USA",
	.SigningReason = "To show how to sign a PDF"
}

'Step 3. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.Sign(signature)

'Step 4. The PDF is not signed until saved to file, steam or byte array.
doc.SaveAs("signed.pdf")

<div class="alert alert-info iron-variant-1" role="alert"> 您的企业在PDF安全性和合规性的年度订阅上花费过多。 考虑 <a href="https://ironsoftware.com/enterprise/securedoc/">IronSecureDoc</a>,提供了管理SaaS服务的解决方案,如数字签名、编辑、加密和保护,且仅需一次性付款。 <a href="https://ironsoftware.com/enterprise/securedoc/docs/">探索 IronSecureDoc 文档</a>. </div> <p>IronPDF 支持使用 .pfx 和 .p12 X509Certificate2 数字证书对新的或现有的 PDF 文件进行数字签名。</p> <p>PDF 一经签署,在证书失效的情况下不得修改。 这确保了保真度。</p> <p>要使用 Adobe Reader 免费生成签名证书,请阅读<a href="https://helpx.adobe.com/acrobat/using/digital-ids.html" target="_blank" rel="nofollow noopener noreferrer">Adobe 数字 ID 指南</a>.</p> <p>除加密签名外,还可使用 IronPDF 手写签名图像或公司印章图像进行签名。</p> <p>您可以从以下链接下载演示使用 IronPDF 进行 PDF 数字签名的示例项目<a href="https://ironpdf.com/downloads/digitally-sign-pdf.zip" target="_blank" rel="nofollow noopener noreferrer">IronPDF 数字签名 PDF 示例项目</a>.</p>

在ASP .NET中将HTML转换为PDF

什么是IronPDF?

IronPDF 是一个 .NET PDF 库,使程序员能够轻松地创建、编辑和导出 .NET Core 和 .NET Framework 中的 PDF 文件,支持 C#、F# 和 VB.NET。IronPDF 可自动从准备好的文档生成 PDF。Web 表单、本地 HTML 页面和其他网页都可以使用 IronPDF 转换为 PDF。它还可以创建合同、报告、报价单、发票和其他文件作为 PDF 报告/文档。它适用于 .NET Framework 和 .NET Core 的 web 表单、MVC、ASP.NET、ASP.NET Core 和 Web APIs。

除了拥有强大的内置HTML到PDF的转换引擎(可以从HTML5、JavaScript和CSS创建完美的PDF文档)之外,IronPDF还包括许多PDF操作功能。创建交互式PDF文档、填写和提交交互式表单、合并和拆分PDF文件、从PDF文件中提取文本和图像、在PDF文件中搜索文本、将PDF页面光栅化为图像以及转换PDF文件,这些都是IronPDF可以在PDF文档上执行的操作示例。

什么是Blazor?

Blazor 可以通过使用 WebAssembly 直接在浏览器中执行客户端 C# 代码。由于 WebAssembly 支持 .NET 技术,Blazor 可以在其开发的前端应用程序中重用后端的源代码和库。Blazor 还可以在服务器上执行客户端业务逻辑。通过使用 SignalR(一个实时消息传递框架),客户 UI 事件被发送到服务器。必要的 UI 更新会在执行完成后传输到客户,并合并到 DOM 中。

使用 Blazor Hybrid,开发人员可以使用 .NET MAUI 和现有的 Blazor UI 组件创建跨平台的原生客户端应用程序。开发人员还可以在桌面、网页和移动环境中使用相同的 UI 组件,而不会失去任何平台的原生功能。开发人员还可以使用 Blazor Hybrid 来更新现有的 WPF 和 Windows Forms 应用程序。

Blazor使用开放的网络标准,不依赖于使用插件或 代码翻译所有当前的网络浏览器,包括移动设备上的浏览器,都支持Blazor服务器技术。

入门
使用 IronPDF 的 .NET PDF 库功能

IronPDF 如何与 Blazor 一起工作

IronPDF for Blazor 允许用户使用 C# 和 VB.NET 创建、导入和导出 PDF 文档。该库还支持 .NET Framework、.NET Core 和 .NET Standard。IronPDF 提供了两种编辑 PDF 的方式:一种是使用原生 PDF 元素,另一种是作为流文档进行编辑。

性能

IronPDF库为Blazor提供无与伦比的性能和最佳的内存消耗;它根据需要解码照片,使用FlateDecode加密压缩内容,并通过只包含最常用的字形来嵌入字体子集。

交互表单

使用文本框、单选按钮、列表框和其他类似控件为 PDF 文档添加交互功能。这样,用户可以根据需要更新和填写 PDF 文档中的数据。表单完成后,它们可以被展平,以删除交互字段,同时保留其内容。这对于防止文档的后续更改非常有用。

加密

PDF文档可以通过密码加密来保护机密信息免受未经授权的访问。

文本属性

在制作或更新 PDF 文档时,您可以通过功能强大的 API 自定义文本和图形元素的外观。样式控制包括填充、文本、描边、字体、文本大小等,可以轻松满足任何设计需求。

在C# VB .NET中编辑PDF

IronPDF如何创建和显示PDF文档

IronPDF可以将网页转换为PDF,并且能够通过 将Html渲染为Pdf 方法。此方法可以接受包含网页 HTML 标记的字符串。通过这种方式,可以在将内容传递给方法之前按需要内联样式。附加代码可以使用户将 PDF 文件下载到他们的客户端计算机。

同样地, 将URL渲染为PDF 方法将来自URL的HTML内容转换为PDF内容,包括任何对JavaScript和CSS的引用。IronPDF从HTML生成PDF,具有高精度,确保与原始网页具有100%的相似性。该库能够处理包含图表、图形、图像、表格等复杂的网页设计。一个单独的方法允许对PDF文档进行辅助自定义。可能的自定义包括更改页面大小、边距大小、页眉/页脚内容等。

一旦生成了PDF文档,可以使用客户端JavaScript在浏览器客户端中显示该文档。

HTML、JavaScript、CSS和图像转换为PDF在.NET应用程序中。

为什么Blazor支持IronPDF

IronPDF 已使用最新的 .NET 技术开发,从而使其在 Blazor 内无缝运行,而无需复杂的集成。

IronPDF支持多种文件类型,包括HTML、ASPX、cshtml和Razor。Razor是一种文件格式,Blazor中用于将.NET源代码嵌入网页。其语法由Razor标记、C#和HTML组成。

简单安装 <br/>适用于 Visual Studio

立即通过 NuGet 试试

好处显而易见!使用IronPDF,你可以更加轻松地完成更多任务。我们的产品非常适合需要制作、管理和编辑PDF库的任何人,包括房地产、出版、金融和企业等行业的企业。我们的解决方案价格也非常有竞争力。

Ready to see what IronPDF can do for your projects and business? Try it out now

通过NuGet为.NET安装 立即下载
支持:
  • 支持 C#、VB 在 .NET Framework 4.0 及以上版本
  • Visual Studio 的 NuGet 安装程序支持
  • .NET Core 2 及以上
  • .NET 开发集成开发环境 - Microsoft Visual Studio.
  • Azure for .NET 云托管
  • JetBrains ReSharper 兼容 C#

IronPDF 许可

免费 用于开发目的。部署许可证起价 $749。

项目 C# + VB.NET 库许可

项目

组织 C# + VB.NET 库许可

组织

SaaS C# + VB.NET库许可

软件即服务

OEM C# + VB.NET 库授权

原始设备制造商

开发人员 C# + VB.NET 库许可

开发者

代理C# + VB.NET库授权

机构

部署 IronPDF 的许可  

PDF C# / VB 教程为 .NET

C# HTML 转 PDF | C Sharp 和 VB.NET 教程

C# PDF HTML

Jean Ashberg .NET 软件工程师

教程 | CSharp 和 VB .NET HTML 转 PDF

让我们在 .NET 中创建 PDF,无需复杂的程序设计布局或 APIs…

查看 Jean 的 HTML 转换为 PDF 教程
ASPX 转 PDF | ASP.NET 教程

C# PDF .NET ASPX

Jacob Müller 软件产品设计师 @ Iron团队

教程 | 在ASP.NET中将ASPX转换为PDF

看看使用C#或VB .NET将ASPX页面转换为PDF文档有多么容易……

查看Jacob的ASPX转PDF教程
VB.NET | VB .NET PDF 教程

VB.NET PDF ASP.NET

Veronica Sillar .NET软件工程师

教程 | 使用 VB.NET 创建 PDF 文件

看看我是如何在我的 VB .NET 项目中使用 IronPDF 创建 PDF 文档的……

查看Veronica的VB .NET教程
成千上万的开发人员使用IronPDF用于...

会计和财务系统

  • # 收据
  • # 报告
  • # 发票打印
将 PDF 支持添加到 ASP.NET 会计和财务系统中

业务数字化

  • # 文档
  • # 订购与标签
  • # 纸张替代
C# 业务数字化用例

企业内容管理

  • # 内容制作
  • # 文档管理
  • # 内容分发
.NET CMS PDF支持

数据和报告应用程序

  • # 性能跟踪
  • # 趋势图绘制
  • # 报告
C# PDF报告
IronPDF 组件软件库客户

开发人员在公司、政府部门以及作为自由职业者工作时使用IronPDF。

IronPDF是始终作为领先的.NET PDF库支持的

IronPDF 客户图标
IronPDF 客户图标
IronPDF 客户图标
IronPDF 客户图标
IronPDF 客户图标
IronPDF 客户图标
IronPDF 客户图标
IronPDF 客户图标