安装概述

This article was translated from English: Does it need improvement?
Translated
View the article in English

适用于所有平台的 IronPDF 安装与配置完整指南。

  1. 使用 NuGet 包管理器安装 https://www.nuget.org/packages/IronPdf

    PM > Install-Package IronPdf
  2. 复制并运行这段代码。

    IronPdf.ChromePdfRenderer
           .StaticRenderHtmlAsPdf("<p>Hello World</p>")
           .SaveAs("pixelperfect.pdf");
  3. 部署到您的生产环境中进行测试

    通过免费试用立即在您的项目中开始使用IronPDF

    arrow pointer

1. 平台要求

平台 .NET 版本 硬件 附加要求、兼容性
Logo Table Windows related to 1. 平台要求
Windows
.NET 10、9、8、7、6、5、.NET Core、.NET Standard 和 .NET Framework。
  • 最低配置:1 核处理器及 1.75 GB 内存
  • 推荐配置:2 核处理器及 8 GB 内存或更高
  • Windows 10、11 和 Windows Server
  • Visual C++ 再发行包 (x86 和 x64)
Logo Table Linux related to 1. 平台要求
Linux
  • 64 位 Linux 操作系统:Ubuntu 22、Ubuntu 20、Ubuntu 18、Ubuntu 16、Debian 10-11、CentOS 8、Fedora Linux 33、Amazon、AWS、Linux 2
  • IronCefSubprocess
  • Chrome 依赖项
Logo Table Mac related to 1. 平台要求
macOS
2020 年以来的所有 macOS 版本

2. 安装方法

您可以通过两种方式安装 IronPDF:本机模式和远程引擎。默认情况下,建议使用本机模式。 若要使用 Docker/Kubernetes 部署到生产服务器,请使用远程引擎模式。

远程引擎模式: 通过 gRPC 协议独立处理 PDF。
  • 最适合:云和容器化部署,支持旧版操作系统。
  • 软件包:IronPdf.Slim
  • 体积:更轻量,仅占用几MB空间。
  • 要求:需要配置与主机的连接。

3. 安装选项

安装 C# PDF 库只需不到 5 分钟。 可通过 NuGet 免费获取或直接下载,并立即在 Visual Studio 中开始使用。

NuGet 包
手册下载
远程 IronPdfEngine

访问 IronPDF NuGet 库(或 Visual Studio 中的"包管理器控制台")

  1. 在"解决方案资源管理器"中,右键单击"引用"
  2. 选择"管理 NuGet 包" > "浏览" > 搜索 IronPDF
  3. 选择软件包并安装。
Install-Package IronPdf
  1. 下载适用于您平台的 IronPDF DLL 软件包:Windows、Linux、macOS
  2. 将适用于您操作系统的 ZIP 文件解压到解决方案目录内的某个位置。
  3. 在 Visual Studio 的"解决方案资源管理器"中,右键单击"依赖项"。
  4. '添加项目引用' > 选择 '浏览' 以包含从 ZIP 文件中提取的所有 DLL 文件。

请注意请注意:每个 IronPDF 版本都需要匹配的 IronPdfEngine 版本。不支持跨版本使用。 例如,IronPDF 2024.2.2 必须译为 IronPdfEngine 2024.2.2.
using NuGet 安装 IronPDF。

Install-Package IronPdf.Slim

4. 其他配置

管理许可证
Path & Permission
远程引擎

购买 IronPDF 或注册 30 天试用版后,请查收发送到您邮箱的许可证密钥。

请在应用程序开头添加您的许可证密钥。

IronPdf.License.LicenseKey = "KEY";
IronPdf.License.LicenseKey = "KEY";
Imports IronPdf

IronPdf.License.LicenseKey = "KEY"
$vbLabelText   $csharpLabel

检查许可证状态。

bool valid = IronPdf.License.IsLicensed;
bool valid = IronPdf.License.IsLicensed;
Imports IronPdf

Dim valid As Boolean = IronPdf.License.IsLicensed
$vbLabelText   $csharpLabel

设置 IronPdf.Installation 对象的 TempFolderPath 属性。

IronPdf.Installation.TempFolderPath = @"C:\My\Safe\Path";
IronPdf.Installation.TempFolderPath = @"C:\My\Safe\Path";
IronPdf.Installation.TempFolderPath = "C:\My\Safe\Path"
$vbLabelText   $csharpLabel

提示请务必清除开发环境和服务器上的所有临时文件夹及缓存文件夹,然后在更新路径后重新部署应用程序的干净版本。

在应用程序范围内设置临时文件夹环境变量。

using IronPdf;

// Adjusts System.IO.Path.GetTempFileName and System.IO.Path.GetTempPath behavior for the application
var MyTempPath = @"C:\Safe\Path\";
Environment.SetEnvironmentVariable("TEMP", MyTempPath, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("TMP", MyTempPath, EnvironmentVariableTarget.Process);

// Set IronPDF Temp Path
IronPdf.Installation.TempFolderPath = System.IO.Path.Com/bine(MyTempPath, "IronPdf");

// Your PDF Generation and editing code
var Renderer = new IronPdf.ChromePdfRenderer();
using var Doc = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
Doc.SaveAs("example.pdf");
using IronPdf;

// Adjusts System.IO.Path.GetTempFileName and System.IO.Path.GetTempPath behavior for the application
var MyTempPath = @"C:\Safe\Path\";
Environment.SetEnvironmentVariable("TEMP", MyTempPath, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("TMP", MyTempPath, EnvironmentVariableTarget.Process);

// Set IronPDF Temp Path
IronPdf.Installation.TempFolderPath = System.IO.Path.Com/bine(MyTempPath, "IronPdf");

// Your PDF Generation and editing code
var Renderer = new IronPdf.ChromePdfRenderer();
using var Doc = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
Doc.SaveAs("example.pdf");
Imports IronPdf

' Adjusts System.IO.Path.GetTempFileName and System.IO.Path.GetTempPath behavior for the application
Dim MyTempPath As String = "C:\Safe\Path\"
Environment.SetEnvironmentVariable("TEMP", MyTempPath, EnvironmentVariableTarget.Process)
Environment.SetEnvironmentVariable("TMP", MyTempPath, EnvironmentVariableTarget.Process)

' Set IronPDF Temp Path
IronPdf.Installation.TempFolderPath = System.IO.Path.Combine(MyTempPath, "IronPdf")

' Your PDF Generation and editing code
Dim Renderer As New IronPdf.ChromePdfRenderer()
Using Doc = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>")
    Doc.SaveAs("example.pdf")
End Using
$vbLabelText   $csharpLabel

提示在受限服务器上,请为 IIS 用户 (IUSER) 授予对安装路径文件夹、Windows 文件夹以及 Temp 文件夹的读写权限。

[远程 IronPdfEngine] 安装 IronPdf.Slim 包后,请在应用程序启动时或在调用任何 IronPDF 方法之前,连接到引擎容器并配置连接。

假设 IronPdfEngine 在 123.456.7.8:33350 上远程运行:

Installation.Co/nnectToIronPdfHost(
    IronPdf.GrpcLayer.IronPdfConnectionConfiguration.RemoteServer("123.456.7.8:33350")
);
Installation.Co/nnectToIronPdfHost(
    IronPdf.GrpcLayer.IronPdfConnectionConfiguration.RemoteServer("123.456.7.8:33350")
);
$vbLabelText   $csharpLabel

[Linux] 启用 IronPDF 以自动安装所有必需的 Linux 依赖项。 首次将 HTML 转换为 PDF 的操作可能比平时耗时更长。

Installation.LinuxAndDockerDependenciesAutoConfig = true;
Installation.LinuxAndDockerDependenciesAutoConfig = true;
Installation.LinuxAndDockerDependenciesAutoConfig = True
$vbLabelText   $csharpLabel

[Docker] 预初始化 Chrome 引擎,以预加载必要组件并加快 Docker 中的首次使用速度。

IronPdf.Installation.Initialize();
IronPdf.Installation.Initialize();
IronPdf.Installation.Initialize()
$vbLabelText   $csharpLabel

5. 部署场景

Logo Azure related to 5. 部署场景

在以下环境中运行并部署 IronPDF .NET:

Azure Function
Logo Aws related to 5. 部署场景

在以下环境中运行并部署 IronPDF .NET:

AWS Lambda
Logo Linux related to 5. 部署场景

在以下环境中运行 IronPDF:

Linux Docker 容器
Logo Remote related to 5. 部署场景

以IronPDF为模板,运行IronPDF

远程容器

后续步骤


常见问题解答

我如何设置IronPDFEngine进行远程PDF生成?

要设置IronPDFEngine进行远程PDF生成,请从NuGet安装IronPdf.Slim包,并使用IronPDFConnectionConfiguration类配置连接设置。此设置允许您将应用程序远程连接到IronPDFEngine实例。

使用IronPDFEngine与我的应用程序的主要好处是什么?

在应用程序中使用IronPDFEngine可以远程执行PDF任务,帮助避免平台特定的兼容性问题,特别是在旧系统和移动平台上。此外,它在执行期间不需要.NET运行时。

为什么我可能选择使用IronPDFEngine而不是本地PDF库?

您可能选择使用IronPDFEngine来远程运行性能密集型的PDF功能,减少与不同操作系统的兼容性问题,并通过利用与Chrome相同的渲染器提高HTML到PDF转换的性能。

IronPDFEngine支持水平扩展吗?

不,IronPDFEngine目前不支持水平扩展,这意味着由于服务器内存中PDF文件二进制文件的处理方式,它无法负载均衡到多个实例。

IronPDFEngine可以在不同操作系统上运行吗?

IronPDFEngine设计用于使用Docker容器在Linux系统上运行。然而,二进制文件是平台特定的,因此您需要确保使用适合您操作系统的版本。

如果使用IronPDFEngine时我的PDF输出不同,我该怎么办?

由于不同操作系统的行为,PDF输出可能会略有不同。为了减少差异,请确保您使用正确的Docker镜像,并检查可能影响渲染的任何操作系统特定设置。

我如何确保我的应用程序使用正确版本的IronPDFEngine?

为了确保兼容性,每个版本的IronPDF都需要匹配版本的IronPDFEngine。请确保同时更新两个组件,以避免跨版本问题。

在Windows上使用IronPDFEngine有哪些限制?

在Windows上使用IronPDFEngine时,您需要Linux Containers for Docker,并必须确保服务器端口可访问。二进制文件是平台特定的,需要切换到Linux Containers。

如何配置IronPDF以连接到远程IronPDFEngine服务器?

要为远程服务器配置IronPDF,请使用Installation.ConnectToIronPDFHost方法中的IronPdf.GrpcLayer.IronPDFConnectionConfiguration.RemoteServer,指定服务器的IP和端口详细信息。

使用IronPDFEngine时应该使用哪个包以最小化应用程序大小?

您应使用NuGet中的IronPdf.Slim包,因为它仅包含运行IronPDF与IronPDFEngine所需的组件,从而减少应用程序大小。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 18,918,602 | 版本: 2026.5 just released
Still Scrolling Icon

还在滚动吗?

想快速获得证据? PM > Install-Package IronPdf
运行示例看着你的HTML代码变成PDF文件。