跳過到頁腳內容
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")
Install-Package IronPdf

使用 IronPDF,您可以從您的 .NET 專案中的簡單 HTML 字串創建新的 PDF 文件,而且 IronPDF 能夠在 C#、F# 和 VB.NET 中使用。 由於使用 ChromePdfRenderer 類,您可以確保從 HTML 字串渲染的任何 PDF 文件都能達到像素完美。 憑借 IronPDF 強大的HTML 到 PDF 轉換功能,您可以創建高質量的 PDF 文件,以滿足您的個人需求。

class="examples__featured-snippet">

將 HTML 字串轉換為 PDF 的 4 個步驟

  1. 導入 IronPDF 庫。
  2. 初始化一個新的 ChromePdfRenderer 對象。
  3. 使用 RenderHtmlAsPdf 方法。
  4. 使用 PdfDocument.SaveAs 保存 PDF。

請參見下面的代碼示例以獲取更多詳細信息:

在 C# 中將 HTML 字串轉換為 PDF 的第一步是確保 IronPDF 庫在您的專案中正確設置並運行良好。 通過包括 using IronPdf,我們確保可以訪問 IronPDF 庫中所需的類來完成 HTML 到 PDF 的轉換。 下一行 Installation.EnableWebSecurity = true,概念上用於禁用本地磁碟訪問或跨來源請求,確保安全操作。 (注意:這行在示例中缺失,但通常與配置設置有關,用於保證 PDF 渲染操作的安全性。)

示例介紹了如何創建 ChromePdfRenderer 的實例來處理 HTML 到 PDF 的轉換。 The RenderHtmlAsPdf method is used to convert a simple HTML string ("<h1>Hello World</h1>") into a PDF document. 此文件使用 SaveAs 方法保存到磁碟。

在進階示例中,IronPDF 顯示能夠處理包含外部資源(如圖像、CSS 和 JavaScript)的 HTML 內容。 要加載這些資源,可選的 BasePath 參數被用來指定包含所需文件的目錄。 最終的 PDF 文件,包括外部資源,使用相同的 SaveAs 方法保存。 此代碼示例強調了 IronPDF 能夠處理基本和複雜 HTML 內容的能力,使其成為一個生成 PDF 文件程式上高效的工具。

學習使用 IronPDF 在 C# 中將 HTML 字串轉換為 PDF

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")
Install-Package IronPdf

IronPDF 使從現有 URL 選擇渲染 HTML 為 PDF 文件變得非常簡單。 對 JavaScript、圖像、表單和 CSS 的支持非常高。

從接受查詢字串變數的 ASP.NET URL 渲染 PDF,可以促進設計師和編碼員之間的協作式 PDF 開發。


class="examples__featured-snippet">

在 C# 中將 URL 轉換為 PDF 的步驟

  1. 下載 IronPDF URL 到 PDF 轉換庫
  2. 使用 NuGet 安裝庫以測試其功能
  3. 使用 IronPDF 從接受查詢字串變數的 ASP.NET URL 渲染 PDF
  4. 直接從 URL 使用 IronPDF 創建 PDF 文件
  5. 輕鬆地查看和驗證 PDF 輸出文件。

學習如何使用 IronPDF 將 URL 轉換為 PDF

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
Install-Package IronPdf

IronPDF 旨在為開發者提供盡可能靈活的選擇。

在這篇C# PDF 生成教學範例中,我們展示了提供自動化內部功能的 API 與提供控制權的 API 之間的平衡。

IronPDF 支援許多對生成的PDF文件的自訂,包括頁面大小、頁面邊距、頁眉/頁腳內容、內容縮放、CSS 規則集和 JavaScript 執行。


我們希望開發者能夠控制 Chrome 如何將網頁轉成 PDF。 ChromePdfRenderer 類別概述使這成為可能。

ChromePdfRenderer 類別中可用的設置示例包括邊距、頁眉、頁腳、紙張大小和表單創建設置。

  • 上述代碼範例展示了如何利用 IronPDF 庫從網頁創建 PDF 文件。
  • 這涉及使用特定選項如紙張大小、邊距、頁眉和頁腳來設置渲染器。
  • ChromePdfRenderer 類別用於將 URL 渲染成 PDF。
  • 然後將生成的 PDF 文件保存為名為“output.pdf”的文件。

探索使用 IronPDF 的像素完美 HTML 到 PDF 指南

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
Install-Package IronPdf

使用 IronPDF 庫,只需在 Form_Load 事件中添加一行代碼,就可以將 ASP.NET 網頁渲染為 PDF 而不是 HTML。

此範例顯示了 IronPDF 如何生成複雜的、數據驅動的 PDF,這些 PDF 首先以 HTML 的形式設計和測試,簡單易用。

IronPDF 的ASPX 到 PDF 轉換功能允許您在 ASPX 頁面中調用單個方法,並返回 PDF 而不是 HTML。

您可以編碼 PDF 以便 "在瀏覽器中" 顯示,或者作為文件下載。

學習如何使用 IronPDF 將 ASPX 頁面渲染為 PDF

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")
Install-Package IronPdf

IronPDF 是一個功能強大的 .NET 庫,能夠將 HTML 文件轉換為高品質的 PDF 文件。 使用 IronPDF,您只需幾行代碼即可將 HTML 文件渲染為 PDF,並且由於其支持現代網頁標準,得到的 PDF 文件將是像素級完美。 利用 IronPDF 功能強大的 HTML 文件轉 PDF 功能非常簡單,這要歸功於 ChromePdfRenderer 類,它可以輕鬆處理 HTML 到 PDF 的轉換。

class="examples__featured-snippet">

使用 IronPDF 將 HTML 文件轉換為 PDF 的步驟

  1. 安裝 C# IronPDF 庫以將 HTML 轉換為 PDF
  2. using IronPdf;
  3. var renderer = new ChromePdfRenderer();
  4. var pdf = renderer.RenderHtmlFileAsPdf("example.html");
  5. pdf.SaveAs("output.pdf");

這段代碼創建了一個從 HTML 文件渲染的 PDF 文件。為此,我們必須首先確保 IronPDF 庫已安裝並通過 using IronPdf 行包含在您的專案中。接下來,初始化 ChromePdfRenderer 類,該類提供將 HTML 內容渲染為 PDF 的功能。 此類確保在轉換過程中不會丟失 HTML 文件的原始品質。

一旦渲染器實例化,您可以使用 RenderHtmlFileAsPdf 方法將現有的 HTML 文件轉換為 PDF。 在此示例中,HTML 文件 "example.html" 被傳遞給此方法,創建了一個 PDF 對象。 最後,要保存生成的 PDF,請使用 SaveAs 方法,指定所需的文件名和位置。 此簡單過程允許您在 C# 應用程序中輕鬆地從 HTML 文件生成 PDF。

學習如何使用 IronPDF 將 HTML 文件轉換為 PDF

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)
Install-Package IronPdf

This example demonstrates how the user can change PDF print options to turn a form into HTML.

IronPDF's ASPX to PDF Conversion Guide functionality has many options available for rendering HTML to PDF from a string or a file.

Two options of particular importance are:

  • Allowing developers to specify if HTML forms should be rendered as interactive PDF forms during conversion.
  • Allowing developers to specify if the PDF should be displayed "in browser," or as a file download.

Discover How to Convert ASPX to PDF with IronPDF

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
Install-Package IronPdf

給定位於計算機上的單個圖像檔案 C:\images\example.png,您可以通過調用 IronPdf.ImageToPdfConverter.ImageToPdf 方法並提供其檔案路徑,快速將其轉換為PDF文件:

您還可以使用 System.IO.Directory.EnumerateFilesImageToPdfConverter.ImageToPdf 將多個圖像合併轉換為單個PDF文件:

To explore more about converting images to PDFs using IronPDF for enhancing your applications, or to discover the entire suite of developer tools offered by Iron Software, including IronBarcode, IronOCR, and more, visit the Iron Software website.

學習如何使用IronPDF將圖像轉換為PDF

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
Install-Package IronPdf

HTML 標題和頁腳提供了一種靈活的方法,用於為您的 PDF 文檔創建動態標題和頁腳。 通過這種方法添加標題和頁腳,開發人員可以完全控制其標題和頁腳的外觀,因為它們被渲染為獨立的 HTML 文檔,能夠包含自己的資產和樣式表。

在 PDF 中使用 IronPDF 添加自定義 HTML 標頭和頁腳的步驟

首先,您需要創建一個 ChromePdfRenderer 類的實例,它負責將 HTML 內容渲染為像素完美的 PDF 文檔。

接下來,使用 HtmlHeaderFooter 類定義頁腳,您需要指定 MaxHeight、頁腳的 HTML 內容(在我們的例子中包括頁碼)以及用於圖像解析的基本 URL。 頁腳的樣式設置為顯示居中的頁面信息。

為了避免頁腳與 PDF 的主要內容重疊,使用 MarginBottom 屬性設置底部邊距。 同樣地,使用 HtmlHeaderFooter 類創建包含圖像(如徽標)的標頭。 這裡我們設置了一個指向包含您圖像資產的目錄的 BaseUrl,以便在渲染期間正確解析圖像。

最後,使用 MarginTop 屬性設置頂部邊距,以防止標頭與內容重疊。 這個例子展示了如何輕鬆地在您的 PDF 文檔中實現自定義 HTML 標題和頁腳與 IronPDF。

學習如何使用 IronPDF 為 PDF 添加 HTML 標題和頁腳

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}
Install-Package IronPdf

有兩種方法可以將標頭和頁尾新增至 PDF 文件。 它們可以新增為經典的文字格式,並可選擇合併動態數據。 或者,它們可以透過更靈活的 HTML 格式新增,這使得開發人員可以通過其 HTML 內容渲染動態標頭和頁尾。

使用 IronPDF 向 PDF 新增標頭和頁尾的步驟

今天我們將看看您如何僅需幾個簡單的步驟就能將經典的文本標頭和頁尾新增到您的 PDF 文件中。 向 PDF 文件新增自定義標頭和頁尾的第一步是確保專案中包含 IronPDF 庫,使用 using IronPdf; 語句。 然後,實例化 ChromePdfRenderer,它提供了將您的 HTML 內容渲染為像素完美的 PDF 文件的功能。

接下來,配置標頭設置。 FirstPageNumber 屬性允許您指定起始頁碼,如果需要還可以考慮封面。 TextHeader 屬性使您能夠自定義外觀,例如繪製分隔線、居中文本(在此情況下為文件 URL),選擇字體類型和大小,並在頁面的頂部為標頭創建邊距。

配置標頭後,使用 TextFooter 屬性設置頁尾。 與標頭類似,您可以繪製一條分隔線、選擇字體類型和大小,並包括動態內容,如當前日期、時間和包含總頁數的頁碼。 最後,在頁面的底部創建邊距以容納頁尾。

通過遵循這些步驟,您可以使用富有資訊的標頭和頁尾提升 PDF 文件的專業性和可讀性。

發現如何使用 IronPDF 新增標頭和頁尾

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
Install-Package IronPdf

IronPDF 提供 50多種功能 用於閱讀和編輯 PDF。 The most popular are merging PDFs, cloning pages, and extracting text from rotated content.

IronPDF 還允許用戶添加水印、旋轉頁面、添加註釋、數字簽名 PDF 頁面、創建新 PDF 文檔、附上封面頁、自定義 PDF 大小,以及在生成和格式化 PDF 文件時進行更多操作。 此外,它支持將 PDF 轉換為所有常規圖像文件類型,包括 JPG、BMP、JPEG、GIF、PNG、TIFF 等。

閱讀 C# PDF 編輯教程 以了解如何充分利用 IronPDF 修改 PDF 文檔以最佳滿足項目要求。


class="hsg-featured-snippet">

如何在 C# 中編輯 PDF 文件

  1. 安裝可編輯 PDF 文件的 C# 庫
  2. 利用 `FromFile` 方法導入多個 PDF 文件
  3. 使用 C# 中的直觀 API 訪問和修改 PDF 文件
  4. 使用 C# 將更新的版本保存為新的 PDF
  5. 查看新編輯的 PDF 文件

學習如何使用 IronPDF 在 PDF 中添加頁眉和頁腳

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")
Install-Package IronPdf

IronPDF為開發人員提供強大的PDF安全選項,支持自定義和設置PDF元數據、密碼、許可權等。 通過IronPDF的密碼、安全性和元數據選項,您可以創建自定義許可權和安全級別,以滿足PDF文件的需要。 這是通過使用類如SecuritySettingsMetaData類實現的。 一些選項包括限制PDF文件不可打印、設置為只讀以及128位加密及密碼保護您的PDF文件。

設置自定義元數據通過實現MetaData類訪問各種PDF元數據選項,並用您自定義的值進行設置。 這包括更改作者、關鍵字、修改數據等。 設置自定義安全設置包括能設置自定義用戶和所有者密碼、打印許可權、只讀模式等。

class="examples__featured-snippet">

設置PDF密碼、元數據和安全的5個步驟

  1. var pdf = PdfDocument.FromFile("encrypted.pdf", "password");
  2. System.Collections.Generic.List<string> metadatakeys = pdf.MetaData.Keys;
  3. var metadatakeys = pdf.MetaData.Keys;
  4. pdf.MetaData.Author = "Satoshi Nakamoto";
  5. pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");

要開始自定義您的PDF文件的安全性,您必須首先加載現有的PDF或創建新的PDF。 在這裡,我們加載了一個現有的密碼保護PDF文件,並輸入了打開PDF文件所需的密碼。 PDF加載後,我們使用pdf.MetaData.Keys來獲取PDF的當前元數據。 要刪除現有的PDF元數據值,請使用RemoveMetaDataKey方法。 要開始設置新的元數據值,請使用pdf.MetaData.metadataField(例如,pdf.MetaData.Keywords),然後將新值分配給它。 像標題和關鍵字這樣的元數據字段接受字符串值,而修改數據字段接受日期時間值。

接下來,我們使用SecuritySettings類設置了新的安全設置。 如您所見,您可以在此處設置多樣的設置。 這讓您可以完全控制每個PDF文件的許可權和安全級別。 要訪問這些設置,您只需確保使用pdf.SecuritySettings,然後調整您想要的設置。例如,MakePdfDocumentReadOnly方法將PDF文件設置為只讀,以128位加密內容。 其他SecuritySettings的選項包括:

  • AllowUserAnnotations: 控制用戶是否可以註解PDF。
  • AllowUserPrinting: 控制文件的打印許可權。
  • AllowUserFormData: 設置用戶是否可以填寫表單的許可權。
  • OwnerPassword: 為PDF設置擁有者密碼,用於禁用或啟用其他安全設置。
  • UserPassword: 為PDF設置用戶密碼,必須輸入才能打開或打印文件。

一旦您為PDF文件設置了自定義元數據、密碼和安全設置,請使用pdf.SaveAs方法將您的PDF保存到指定位置。

學習如何使用IronPDF處理PDF元數據

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("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("watermarked.pdf")
Install-Package IronPdf

IronPDF 提供方法用 HTML 為 PDF 文件設置『水印』。

使用 ApplyStamp 方法,開發人員可以將基於 HTML 的水印添加到 PDF 文件中。 如上例所示,HTML 代碼作為方法的第一個參數用於水印。 傳遞給 ApplyStamp 的其他參數控制水印的旋轉、不透明度和位置。

利用 ApplyStamp 方法代替 ApplyWatermark 方法來更精細地控制水印位置。 例如,使用 ApplyStamp 來:

  • 向 PDF 添加文字、圖像或 HTML 水印
  • 將相同的水印應用於 PDF 的每一頁
  • 為特定 PDF 頁面應用不同的水印
  • 調整水印在頁面副本的前面或後面的位置
  • 調整水印的不透明度、旋轉角度和對齊以獲得更高精度

class="hsg-featured-snippet">

如何在 C# 中向 PDF 文件添加水印

  1. 從 NuGet 下載並安裝 IronPDF 庫。
  2. 創建一個新的 PdfDocument 或使用現有的 PdfDocument 文件。
  3. 調用 ApplyStamp 方法以向 PDF 添加水印。
  4. 通過調用 SaveAs 導出 PDF 文件。

使用 IronPDF 應用水印的 C# 代碼示例

確保您在項目中已安裝 IronPDF 庫。 您可以在 IronPDF NuGet 套件頁面 找到更詳細的說明。

代碼解釋:

  • 我們首先導入 IronPdf 庫,它提供了所有 PDF 操作所需的類和方法。
  • 使用 PdfDocument.FromFile 創建或加載一個 PDF 文件,指定現有 PDF 的文件路徑。
  • 為水印定義 HTML 內容。 在這種情況下,水印顯示為『機密』,具有特定的樣式。
  • 使用 ApplyStamp 方法將水印覆蓋在 PDF 上。 此方法允許進行詳細自定義:
    • rotationDegrees:指定水印旋轉的度數。
    • lefttop:指定水印的 X 和 Y 位置,從左上角測量。
    • opacity:確定水印的透明度。
    • pageRange:指定應接收水印的頁面,允許多樣化的位置策略。
  • 最後,SaveAs 方法將更改的 PDF 導出到一個新文件。

總之,IronPDF ApplyStamp 方法允許精確控制使用 HTML 的 PDF 文件水印。 這種方法靈活,適應不同的自定義需求以定位、樣式化和應用水印到特定頁面。

探索使用 IronPDF 的自定義水印

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("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("complete.pdf")
Install-Package IronPdf

You may want to use a specific background and foreground as you create and render your PDF documents in IronPDF. In such a case, you can use an existing or rendered PDF as the background or foreground for another PDF document. This is particularly useful for design consistency and templating.

This example shows you how to use a PDF document as the background or foreground of another PDF document.

You can do this in C# by loading or creating a multi-page PDF as an IronPdf.PdfDocument object.

You can add backgrounds using PdfDocument.AddBackgroundPdf. For more details on background insertion methods, refer to the IronPDF.PdfDocument background documentation; it describes several background insertion methods and their overrides. This adds a background to each page of your working PDF. The background is copied from a page in another PDF document.

You can add foregrounds, also known as "Overlays," using PdfDocument.AddForegroundOverlayPdfToPage. For detailed information on foreground insertion methods, consult the IronPDF.PdfDocument overlay documentation.

This code illustrates how to integrate additional design elements on top of a base PDF using IronPDF. Always refer to the official documentation for more advanced techniques and additional options.

Explore our Guide on Adding Backgrounds and Foregrounds

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")
Install-Package IronPdf

role="alert"> 您的企業在 PDF 安全性和合規性方面的年度訂閱支出過高。考慮 IronSecureDoc,綜合 PDF 安全解決方案,它提供數位簽名、編輯、加密和保護等 SaaS 服務管理方案,一次性支付即可。 探索 IronSecureDoc 文件

您可以像處理普通文件一樣輕鬆地使用 IronPDF 建立可編輯的 PDF 文件。 PdfForm 類是 PDF 文件中的一組用戶可編輯的表單欄位。 它可以實現到您的 PDF 渲染中,以製作成表單或可編輯的文件。

這個例子將展示如何在 IronPDF 中創建可編輯的 PDF 表單。

具有可編輯表單的 PDF 可以只需在文件部分中添加 <form><input><textarea> 標籤即可從 HTML 創建。

PdfDocument.Form.FindFormField 方法可用來讀取和寫入任何表單欄位的值。 該欄位的名稱將與您 HTML 中為該欄位指定的'name'屬性相同。

PdfDocument.Form 對象可以有兩種使用方式:

  • 填充預設值:這可以用來為表單欄位設置預設值,這些值將顯示在像 Adobe Reader 這樣的 PDF 查看器中。
  • 讀取用戶輸入:在用戶填寫表單後,表單欄位可以被訪問,並將數據讀回應用程式中。

在上面的例子中,我們首先導入 IronPdf 庫並定義一個方法 CreateEditablePdfDocument。 此方法包含一個簡單表單的 HTML 結構,其中有用戶名和評論的輸入欄位。 使用 HtmlToPdf 渲染器,我們將此 HTML 內容轉換為 PDF 文件。

然後使用 pdfDocument.Form 來訪問和操作表單欄位。 我們設置預設值,這些值將在文件於 PDF 查看器中開啟時顯示。 最後,文件將以 "EditableForm.pdf" 的名稱保存,允許其與嵌入的可編輯欄位一起存儲或共享。

學習使用 IronPDF 配合指南進行 PDF 表單編輯

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()
Install-Package IronPdf

若要將 PDF 文件轉換為圖像,請在 PdfDocument 物件上調用 IronPDF 的 RasterizeToImageFiles 方法。 可以使用 PdfDocument.FromFile 方法或現有的 .NET Core PDF 生成方法之一來載入 PDF 文件。

RasterizeToImageFiles 將 PDF 的每一頁呈現為光柵化圖像。 第一個參數指定每個圖像要使用的命名模式。 可以使用可選參數來自定義每個圖像的質量和尺寸。 另一個選項允許方法將所選的 PDF 頁面轉換為圖像。

特色代碼範例的第 24 行展示了 ToBitMap 方法。 在任意 PdfDocument 物件上調用此方法以快速將 PDF 轉換為可以儲存為文件或按需操作的 AnyBitmap 對象。


class="hsg-featured-snippet">

如何在 C# 中將 PDF 轉換為圖像

  1. 安裝 PDF 到圖像的 C# 庫
  2. 使用 FromFile 方法導入現有的 PDF 文件
  3. 使用 RasterizeToImageFiles 方法將 PDF 轉換為圖像
  4. 指定保存目錄和圖像大小
  5. 檢查輸出圖像

學習如何使用 IronPDF 將 PDF 光柵化為圖像

C# VB PDF .NET : 数字签名 PDF 数字签名 PDF
using IronPdf;
using IronPdf.Signing;

// Cryptographically sign an existing PDF in 1 line of code!
new IronPdf.Signing.PdfSignature("Iron.p12", "123456").SignPdfFile("any.pdf");

/***** Advanced example for more control *****/

// 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

' Cryptographically sign an existing PDF in 1 line of code!
Call (New IronPdf.Signing.PdfSignature("Iron.p12", "123456")).SignPdfFile("any.pdf")

'''*** Advanced example for more control ****

' Step 1. Create a PDF
Dim renderer = New ChromePdfRenderer()
Dim 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

Dim 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")
Install-Package IronPdf

role="alert"> 您的企業在年度訂閱PDF安全性和合規性方面花費過高。考慮使用IronSecureDoc,它提供數位簽名、遮罩、加密和保護等SaaS服務的管理解決方案,且只需一次性付款。探索IronSecureDoc文檔

數位簽署PDF文件可協助確保文件的完整性,藉此為PDF本身添加驗證方式。 使用IronPDF,您在簽署新或現有PDF文件時有多種選擇。這些選擇包括使用證書數位簽署PDF文件、在PDF上添加手寫簽名的圖形版本、在PDF上蓋上證書圖像,或僅僅在PDF上創建簽名表單域以提示用戶簽署。

使用IronPDF數位簽署PDF的步驟

此過程的第一步是載入或創建我們要簽署的PDF。 在此示例中,我們從HTML內容創建新的PDF文件。 為此,您首先需要創建一個新的ChromePdfRenderer實例。 這是IronPDF的強大渲染引擎,用於將HTML、CSS和JavaScript渲染為高品質PDF。 然後我們使用RenderHtmlAsPdf方法將我們的HTML字串渲染為準備簽署的高品質PDF文件。 生成的PDF存儲在doc變量中。

接下來,我們需要創建我們的簽名。 在此示例中,我們使用證書對PDF文件進行簽署。 PdfSignature代表用於簽署PDF的數位簽名對象,並需要提供我們想使用的.pfx文件路徑以及訪問該文件所需的密碼。我們包含了三個可選屬性:SigningContact將電子郵件或聯繫信息添加到簽名元數據,SigningLocation代表文件簽署地點,SigningReason提供簽署文件的原因。

接下來,我們用創建的PdfSignature對象簽署PDF文件。 透過調用Sign方法,我們將簽名應用於PDF文件,這是一個簡單的步驟。可以使用此方法將多個簽名證書應用於PDF文件。

最後,我們使用SaveAs方法保存簽署的PDF文件,將其保存到指定的文件位置。

了解如何使用IronPDF安全地簽署PDF。

HTML 到 PDF 在 ASP .NET 中

什麼是 IronPDF for .NET?

我們的 .NET PDF 函式庫解決方案是開發者的夢想,特別是使用 C# 的軟體工程師。您可以輕鬆創建一個核心 PDF 函式庫用於 .NET。

IronPDF 使用 .NET Chromium 引擎將 HTML 頁面渲染為 PDF 文件。無需使用複雜的 API 來定位或設計 PDF。IronPDF 支援標準的網頁文件如 HTML、ASPX、JS、CSS 和圖像。

它讓您可以使用 HTML5、CSS、JavaScript 以及圖像創建 .NET PDF 函式庫。您可以輕鬆地編輯、蓋章,並向 PDF 添加頁眉和頁腳。它也使閱讀 PDF 文本和提取圖像變得容易!

開始使用
.NET PDF 库功能使用 IronPDF

.NET PDF 库功能使用 IronPDF

我們從未見過更準確的 HTML 到 PDF 轉換器!我們的業界領先的 PDF 函式庫有很多功能和一個渲染引擎,允許在 Chrome / Webkit 中的無縫和嵌入性。無需安裝。

創建

  • 從 HTML 4 和 5、CSS 和 JavaScript 創建 PDF 文檔
  • 從 URL 生成 PDF 文檔
  • 使用自定義網絡登錄憑據、UserAgents、代理、Cookie、HTTP 標頭、表單變量加載 URL,允許在 HTML 登錄表單後登錄
    • 支持主流圖標字體(Fontello、Bootstrap、FontAwesome)
    • 程式化地加載外部樣式表和資產(HTTP、HTTPS 或文件系統)
  • 單線程和多線程渲染
  • 具有可定制方向、邊距和顏色組分的自定義 ISO 紙張大小

無需 Adobe Acrobat 編輯現有 PDF 文檔

  • 閱讀和填寫表單字段數據
  • 從 PDF 中提取圖像和文本
  • 添加、編輯、更新大綱和書籤,程式註釋帶有便條
  • 從 HTML 或 PDF 資產添加前景或背景疊加
  • 向任何現有 PDF 頁面添加新 HTML 內容
  • 添加邏輯或 HTML 頁眉和頁腳

操控現有 PDF 文檔

  • 加載和解析現有 PDF 文檔
  • 合併和拆分 PDF 文檔中的內容
  • 添加頁眉、頁腳、註解、書籤、浮水印、文字和圖像資產
  • 用文字、圖像和 HTML 背景添加蓋章和浮水印
  • 旋轉頁面

從多種格式轉換

  • 將圖像轉換為 PDF 文件——從主流圖像文件用一行代碼轉換,JPG、PNG、GIF、BMP、TIFF、系統圖形和 SVG 到 PDF
  • ASPX WebForms——用三行代碼轉換 ASP.NET webforms 成可下載的瀏覽器中查看的 PDF
  • HTML 文檔——將 HTML 轉換為 PDF
  • 自訂「基礎 URL」以允許跨網路的可訪問資產文件
  • 通過虛擬 Viewport(寬和高)實現響應布局
  • 可隨比例調整的自定義縮放功能:
    • 將 HTML 內容轉換為保持品質的維度
    • 輸出解析度(DPI)
  • 將系統圖形圖像資產嵌入 HTML 字串中,使用 ImagetoDataURI
  • 啟用 JavaScript 支援,包括可選的渲染延遲
  • 接受任何主要文件編碼(默認為 UTF-8)編碼的 HTML

匯出

  • MVC 視圖——匯出 ASP.NET MVC 視圖為 PDF
  • 合併頁面和圖像
  • 使用支援的字體將文件匯出到任何格式

保存

  • 從文件、二進制数據或 MemoryStreams 中保存和加載。

安全

  • 通過更新用戶密碼、元數據、安全權限和可驗證的數位簽章選項提高安全性

打印

  • 螢幕或打印 CSS 媒體類型
  • 將 PDF 文件轉換為 PrintDocument 對象並在無 Adobe 最少代碼下打印

查看功能
在 C# VB .NET 中编辑 PDF

您在 PDF 文件中需要的一切

隨時創建、合併、拆分、編輯和操控 PDF 文件,您想要的方式輕而易舉。運用您的 C# 開發技能來利用 IronPDF 的擴展功能列表。

若要開始使用 IronPDF 進行專案,下載免費的 NuGet Package Installer 或直接下載 DLL。然後,您可以繼續創建 PDF 文件、編輯和操控現有的文件格式,或以不需 Adobe Acrobat 的情況匯出為任何格式。

我們的支持從免費且詳盡的教程到 24/7 在線支持,全方位延伸。

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

用熟悉的 HTML 文件設計

IronPDF 讓您可以操作主流 HTML 文件格式並在 ASP.NET Web 應用中將其轉換為 PDF。應用多種設置,包括設置文件行為和名稱,添加頁眉和頁腳,變更打印選項,添加分頁符,組合異步和多線程等。

類似地,您可以將 C# MVC HTML 轉換為 ASP .NET 應用的 PDF,將 MVC 視圖打印為 PDF 文件格式,支持 HTML、CSS、JavaScript 和圖像。

此外,創建 PDF 文件並在 ASP .NET C# 應用和網站中將當前的 HTML 頁面轉換為 PDF(C# html 到 pdf 轉換器)。豐富的 HTML 作為 PDF 內容使用,並有能力使用 IronPDF 的生成功能進行編輯和操控。

有了 IronPDF,對解析度的擔憂已成為過去的問題。IronPDF 的輸出 PDF 文件與 Google Chrome 網頁瀏覽器中的 PDF 功能像素相同。

為 .NET 製作, C#, VB, MVC, IronPDF 庫安裝, ASP.NET, .NET Core

幾分鐘即可開始
在 Visual Studio 中的简单安装 <br/>

现在使用 NuGet 试试

好处显而易见!有了 IronPDF,您可以更加轻松地做到更多。我们的产品非常适合需要制作、管理和编辑 PDF 库的任何人,包括房地产、出版、金融和企业的业务。我们的解决方案的价格也非常具有竞争力。
准备好看看 IronPDF 能为您的项目和业务做什么了吗?立即试用

使用 NuGet 安装适用于 .NET 立即下載
支持:
  • 支持 C#、VB 在 .NET Framework 4.0 及以上
  • NuGet 安装支持 Visual Studio
  • .NET Core 2 及以上
  • .NET 开发 IDE - Microsoft Visual Studio。
  • 适用于 .NET 云托管的 Azure
  • JetBrains ReSharper C# 兼容

IronPDF 許可證

免费 用于开发目的。部署许可证从 749 美元起。

项目 C# + VB.NET 库许可

項目

組織 C# + VB.NET 庫授權

組織

SaaS C# + VB.NET 庫授權

SaaS

OEM C# + VB.NET 庫授權

OEM

開發者 C# + VB.NET 庫授權

開發者

代理 C# + VB.NET 庫授權

代理

IronPDF 的部署许可  

PDF C# / VB 教程适用于 .NET

C# HTML 到 PDF | C# 和 VB.NET 教程

C# PDF HTML

Jean Ashberg .NET 軟件工程師

教程 | CSharp 和 VB .NET HTML 到 PDF

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

查看 Jean 的 HTML 到 PDF 教程
ASPX 轉 PDF | ASP.NET 教程

C# PDF .NET IronPDF 庫安裝

Jacob Müller 軟件產品設計師 @ Team Iron

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

看看如何轻松地将 ASPX 页面转换为使用 C# 或 VB .NET 的 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 用於...

會計和財務系統

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

商務數字化

  • # 文件
  • # 訂單和標籤
  • # 紙質替代
C# 商務數字化用例

企業內容管理

  • # 內容生產
  • # 文档管理
  • # 內容分發
.NET CMS PDF 支持

數據和報告應用

  • # 性能跟踪
  • # 趨勢映射
  • # 報告
C# PDF 報告
IronPDF 组件软件库客户

在公司、政府部门和自由职业者工作的开发人员正在使用 IronPDF。

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

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