如何使用C#在PDF文件中嵌入UTF-8字符
从PDF Duo .NET迁移到IronPDF可将您的.NET PDF工作流从一个缺乏文档的利基库(无最新发布版本)转移到一个稳定、文档丰富并积极维护的解决方案。 本指南提供一个逐步的迁移路径,解决了依赖不活跃组件的风险,同时可以访问PDF Duo文档的API未涵盖的功能。
为什么要从 PDF Duo 迁移到 IronPDF.
PDF 双风险问题
PDF Duo .NET(DuoDimension Software)是一个用于.NET的利基HTML到PDF组件。 虽然它可能吸引了寻求自包含DLL的团队,但一些特点使其不适合当前的生产应用程序:
-
供应商和出处:由DuoDimension Software(duodimension.com)发布,这是一个没有公共路线图和GitHub代码库的小型ISV。
-
文档稀缺:一页供应商产品页面、少量示例代码片段,以及2010年的新闻稿。 没有API参考网站,没有有意义的Stack Overflow存在。
-
有效上被遗弃:最后的公共版本是v2.4,日期为2010年12月10日——大约15年没有新版本。
-
窄文档化表面:公共API本质上是
SavePDF(...)。 没有用于水印、加密、签名、表单填写、文本提取或PDF合并的本地API文档。 -
渲染引擎未透露:供应商材料描述了一个自包含的组件,没有Office或Acrobat依赖,但未公布使用了什么HTML/CSS引擎。 CSS3、现代JavaScript、网络字体和flex/grid布局未被声称。
- 早期.NET目标:文档支持的是.NET Framework 1.1到3.5,适用于Windows XP / Vista / 7 / 2000 / 2003。没有记录支持.NET Framework 4.x,.NET Core,.NET 5+,Linux或Docker。
PDF Duo 与IronPDF对比
| 方面 | PDF Duo .NET | IronPDF |
|---|---|---|
| 最后发布 | v2.4(2010年12月) | 活动,定期发布 |
| 分发 | 从duodimension.com下载DLL(无NuGet) | NuGet IronPdf |
| 运行时支持 | .NET Framework 1.1 – 3.5,仅适用于Windows | .NET FX 4.6.2+,.NET 6/7/8/9/10,Linux,macOS,Docker |
| 文档 | 一页供应商产品页面 | 全面的文档+API参考 |
| 支持 | 没有可见的 | 专业的支持团队 |
| 社区 | 可忽略 | 41M+ NuGet下载(Iron Software栈) |
| 渲染 | 引擎未披露 | 现代 Chromium |
| 译文特点 | 仅HTML到PDF | HTML到PDF,合并,安全性,签名,OCR,表格,水印 |
| 许可 | 根据供应商定价页面 | 商业的,永久或订阅 |
对于使用现代.NET的团队,IronPDF提供一个稳定的基础,进行积极开发,并有全面的文档来代替最后发布版本为2010年12月的v2.4的组件。
开始之前
前提条件
- .NET 环境: .NET Framework 4.6.2+ 或 .NET Core 3.1+ / .NET 5/6/7/8/9+
- NuGet 访问权限:能够安装 NuGet 包
- IronPDF 许可证:请从ironpdf.com获取您的许可证密钥。
包/引用更改
PDF Duo .NET 不是通过NuGet分发的。 移除它是一个手动步骤:
# In Visual Studio: References -> remove PDFDuo.dll (and any associated
# PDF Duo files) and delete the vendored binary from your /lib folder.
# Install IronPDF
dotnet add package IronPdf
# In Visual Studio: References -> remove PDFDuo.dll (and any associated
# PDF Duo files) and delete the vendored binary from your /lib folder.
# Install IronPDF
dotnet add package IronPdf
许可配置
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
确定 PDF Duo 的用途
# Find all PDF Duo references
grep -r "DuoDimension\|HtmlToPdf\b\|OpenHTML\|SavePDF" --include="*.cs" .
# Find all PDF Duo references
grep -r "DuoDimension\|HtmlToPdf\b\|OpenHTML\|SavePDF" --include="*.cs" .
API参考
供应商的文档化根命名空间是DuoDimension。 公共表面本质上是SavePDF(...)。 IronPDF下方显示的子命名空间反映了IronPDF的结构; PDF Duo .NET未记录子命名空间。
命名空间变更
| PDF Duo .NET | IronPDF |
|---|---|
using DuoDimension; |
using IronPdf; |
| (没有记录的子命名空间) | using IronPdf.Rendering; |
HTML 到 PDF 转换映射
| PDF Duo .NET | IronPDF |
|---|---|
new DuoDimension.HtmlToPdf() |
new ChromePdfRenderer() |
conv.OpenHTML(htmlFile); conv.SavePDF(path); |
renderer.RenderHtmlFileAsPdf(htmlFile).SaveAs(path) |
conv.OpenHTML(url); conv.SavePDF(path); |
renderer.RenderUrlAsPdf(url).SaveAs(path) |
(将字符串写入临时.html,然后OpenHTML) |
renderer.RenderHtmlAsPdf(html).SaveAs(path) |
页面配置映射
DuoDimension.HtmlToPdf未记录涉及纸张大小、方向或页边距的设置对象。 下方的IronPDF列显示了明确的RenderingOptions等价物。
| PDF Duo .NET | IronPDF |
|---|---|
| (没有记录的页面大小选项) | RenderingOptions.PaperSize = PdfPaperSize.A4 |
| (没有记录的页面大小选项) | RenderingOptions.PaperSize = PdfPaperSize.Letter |
| (没有记录的方向选项) | RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape |
| (没有记录的边距对象) | 个别边距属性 |
边距映射
| PDF Duo .NET | IronPDF |
|---|---|
| (没有记录的边距对象) | 个别属性 |
| (无对等词) | RenderingOptions.MarginTop |
| (无对等词) | RenderingOptions.MarginRight |
| (无对等词) | RenderingOptions.MarginBottom |
| (无对等词) | RenderingOptions.MarginLeft |
文档操作映射
PDF Duo .NET只是一个HTML到PDF转换器。 供应商产品页面未记录在DuoDimension.HtmlToPdf上的加载、字节或合并API。 下方的行展示了使用PDF Duo时,团队通常在相邻库中检索的内容,以及IronPDF调用来合并该工作的方式。
| 需要 | PDF Duo .NET | IronPDF |
|---|---|---|
| 加载现有 PDF | 非本地—与iTextSharp 4.x或类似组合 | PdfDocument.FromFile(path) |
| 保存 PDF | conv.SavePDF(path) |
pdf.SaveAs(path) |
| 获取PDF字节 | not native | pdf.BinaryData |
| 合并 PDF | 非本地—与iTextSharp 4.x或类似组合 | PdfDocument.Merge(pdf1, pdf2) |
在PDF Duo的已记录API中不可用的新功能
| 特征 | IronPDF |
|---|---|
| 页眉/页脚 | RenderingOptions.HtmlHeader, HtmlFooter |
| 页码 | {total-pages}占位符 |
| 水印 | pdf.ApplyWatermark(html) |
| 密码保护 | pdf.SecuritySettings |
| 表格填写 | pdf.Form.Fields |
| 数字签名 | pdf.SignWithFile() |
| 文本提取 | pdf.ExtractAllText() |
| 将 PDF 转换为图像 | pdf.RasterizeToImageFiles() |
代码迁移示例
示例 1:HTML 到 PDF 的转换
之前(PDF Duo):
//PDF Duo .NETis not on NuGet — reference PDFDuo.dll from the vendor download.
using DuoDimension;
using System;
using System.IO;
class Program
{
static void Main()
{
// OpenHTML accepts a file path, URL, or stream; there is no documented
// "convert HTML string" call, so write the markup to a temp file first.
var tempHtml = Path.GetTempFileName() + ".html";
File.WriteAllText(tempHtml, "<h1>Hello World</h1><p>This is a PDF document.</p>");
var conv = new HtmlToPdf();
conv.OpenHTML(tempHtml);
conv.SavePDF("output.pdf");
Console.WriteLine("PDF created successfully!");
}
}
//PDF Duo .NETis not on NuGet — reference PDFDuo.dll from the vendor download.
using DuoDimension;
using System;
using System.IO;
class Program
{
static void Main()
{
// OpenHTML accepts a file path, URL, or stream; there is no documented
// "convert HTML string" call, so write the markup to a temp file first.
var tempHtml = Path.GetTempFileName() + ".html";
File.WriteAllText(tempHtml, "<h1>Hello World</h1><p>This is a PDF document.</p>");
var conv = new HtmlToPdf();
conv.OpenHTML(tempHtml);
conv.SavePDF("output.pdf");
Console.WriteLine("PDF created successfully!");
}
}
Imports DuoDimension
Imports System
Imports System.IO
Module Program
Sub Main()
' OpenHTML accepts a file path, URL, or stream; there is no documented
' "convert HTML string" call, so write the markup to a temp file first.
Dim tempHtml As String = Path.GetTempFileName() & ".html"
File.WriteAllText(tempHtml, "<h1>Hello World</h1><p>This is a PDF document.</p>")
Dim conv As New HtmlToPdf()
conv.OpenHTML(tempHtml)
conv.SavePDF("output.pdf")
Console.WriteLine("PDF created successfully!")
End Sub
End Module
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var htmlContent = "<h1>Hello World</h1><p>This is a PDF document.</p>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully!");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var htmlContent = "<h1>Hello World</h1><p>This is a PDF document.</p>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully!");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim htmlContent = "<h1>Hello World</h1><p>This is a PDF document.</p>"
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF created successfully!")
End Sub
End Class
这里的根本区别在于 API 模式。 PDF Duo的SavePDF(path)写入磁盘。 IronPDF的SaveAs()保存。
这种面向对象的方法提供了额外的灵活性:在保存之前,您可以操作PDF(添加水印、合并文件、添加安全性、提取文本)——这些都不是PDF Duo .NET已记录的API的一部分。 有关其他渲染选项,请参阅 HTML to PDF 文档。
示例 2:URL 到 PDF 的转换
之前(PDF Duo):
//PDF Duo .NETis not on NuGet — reference PDFDuo.dll from the vendor download.
using DuoDimension;
using System;
class Program
{
static void Main()
{
var conv = new HtmlToPdf();
conv.OpenHTML("https://www.example.com");
conv.SavePDF("webpage.pdf");
Console.WriteLine("Webpage converted to PDF!");
}
}
//PDF Duo .NETis not on NuGet — reference PDFDuo.dll from the vendor download.
using DuoDimension;
using System;
class Program
{
static void Main()
{
var conv = new HtmlToPdf();
conv.OpenHTML("https://www.example.com");
conv.SavePDF("webpage.pdf");
Console.WriteLine("Webpage converted to PDF!");
}
}
Imports DuoDimension
Imports System
Module Program
Sub Main()
Dim conv As New HtmlToPdf()
conv.OpenHTML("https://www.example.com")
conv.SavePDF("webpage.pdf")
Console.WriteLine("Webpage converted to PDF!")
End Sub
End Module
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("webpage.pdf");
Console.WriteLine("Webpage converted to PDF!");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("webpage.pdf");
Console.WriteLine("Webpage converted to PDF!");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://www.example.com")
pdf.SaveAs("webpage.pdf")
Console.WriteLine("Webpage converted to PDF!")
End Sub
End Class
PDF Duo使用相同的SavePDF(path)。 IronPDF使用PdfDocument对象。
一个关键优势是,IronPDF的基于Chromium的渲染引擎提供现代的CSS3和JavaScript支持,而PDF Duo的供应商材料没有透露使用了哪个HTML/CSS引擎。 了解有关 URL 至 PDF 转换的更多信息。
示例 3:PDF 合并
之前(PDF Duo):
PDF Duo .NET不提供本地PDF合并API。 记录的表面仅是HTML到PDF,因此需要合并的团队通常都先使用PDF Duo渲染每个PDF,然后使用单独的库(通常是2010年代项目中的iTextSharp 4.x)对它们进行连接:
//PDF Duo .NETis not on NuGet — reference PDFDuo.dll from the vendor download.
using DuoDimension;
using System;
class Program
{
static void Main()
{
// Render each source HTML to its own PDF
var conv = new HtmlToPdf();
conv.OpenHTML("page1.html");
conv.SavePDF("document1.pdf");
conv = new HtmlToPdf();
conv.OpenHTML("page2.html");
conv.SavePDF("document2.pdf");
// Merging into a single PDF requires another library (e.g., iTextSharp).
Console.WriteLine("PDF Duo has no native merge — combine output with another library.");
}
}
//PDF Duo .NETis not on NuGet — reference PDFDuo.dll from the vendor download.
using DuoDimension;
using System;
class Program
{
static void Main()
{
// Render each source HTML to its own PDF
var conv = new HtmlToPdf();
conv.OpenHTML("page1.html");
conv.SavePDF("document1.pdf");
conv = new HtmlToPdf();
conv.OpenHTML("page2.html");
conv.SavePDF("document2.pdf");
// Merging into a single PDF requires another library (e.g., iTextSharp).
Console.WriteLine("PDF Duo has no native merge — combine output with another library.");
}
}
Imports DuoDimension
Imports System
Module Program
Sub Main()
' Render each source HTML to its own PDF
Dim conv As New HtmlToPdf()
conv.OpenHTML("page1.html")
conv.SavePDF("document1.pdf")
conv = New HtmlToPdf()
conv.OpenHTML("page2.html")
conv.SavePDF("document2.pdf")
' Merging into a single PDF requires another library (e.g., iTextSharp).
Console.WriteLine("PDF Duo has no native merge — combine output with another library.")
End Sub
End Module
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
Console.WriteLine("PDFs merged successfully!");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
Console.WriteLine("PDFs merged successfully!");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
Console.WriteLine("PDFs merged successfully!")
End Sub
End Class
这个例子显示了一个基本的架构差异。 PDF Duo .NET根本没有合并API——在PDF Duo工作流中的合并历史上意味着与第二个库(如iTextSharp 4.x)配对。
IronPDF将此整合为一个单一依赖项:使用PdfDocument.Merge()方法将它们合并。 这会生成一个新的SaveAs()单独保存。
IronPDF的方法还允许您在合并之前对任何PDF进行操作、在合并结果中添加水印、应用安全设置等等。 要合并多个文件,可以使用 LINQ:
var paths = new[] { "document1.pdf", "document2.pdf", "document3.pdf" };
var pdfs = paths.Select(PdfDocument.FromFile).ToList();
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("merged.pdf");
var paths = new[] { "document1.pdf", "document2.pdf", "document3.pdf" };
var pdfs = paths.Select(PdfDocument.FromFile).ToList();
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("merged.pdf");
Dim paths = {"document1.pdf", "document2.pdf", "document3.pdf"}
Dim pdfs = paths.Select(AddressOf PdfDocument.FromFile).ToList()
Dim merged = PdfDocument.Merge(pdfs)
merged.SaveAs("merged.pdf")
了解有关 合并和拆分 PDF 的更多信息。
迁移后的新功能
迁移到IronPDF后,您将获得 PDF Duo 无法提供的功能:
带页码的页眉和页脚
using IronPdf;
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
HtmlFragment = "<div style='text-align:center; font-size:10px;'>Company Report</div>",
MaxHeight = 25
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
HtmlFragment = "<div style='text-align:center; font-size:10px;'>Page {page} of {total-pages}</div>",
MaxHeight = 25
};
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("report.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
HtmlFragment = "<div style='text-align:center; font-size:10px;'>Company Report</div>",
MaxHeight = 25
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
HtmlFragment = "<div style='text-align:center; font-size:10px;'>Page {page} of {total-pages}</div>",
MaxHeight = 25
};
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("report.pdf");
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter With {
.HtmlFragment = "<div style='text-align:center; font-size:10px;'>Company Report</div>",
.MaxHeight = 25
}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter With {
.HtmlFragment = "<div style='text-align:center; font-size:10px;'>Page {page} of {total-pages}</div>",
.MaxHeight = 25
}
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("report.pdf")
PDF Duo 不支持页眉或页脚--没有相应的功能。IronPDF提供全面的 HTML/CSS 支持,并为页码等动态内容提供内置占位符。 请参见页眉和页脚指南。
水印
using IronPdf;
using IronPdf.Editing;
var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark(
"<h1 style='color:red; opacity:0.3;'>CONFIDENTIAL</h1>",
45,
VerticalAlignment.Middle,
HorizontalAlignment.Center);
pdf.SaveAs("watermarked.pdf");
using IronPdf;
using IronPdf.Editing;
var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark(
"<h1 style='color:red; opacity:0.3;'>CONFIDENTIAL</h1>",
45,
VerticalAlignment.Middle,
HorizontalAlignment.Center);
pdf.SaveAs("watermarked.pdf");
Imports IronPdf
Imports IronPdf.Editing
Dim pdf = PdfDocument.FromFile("document.pdf")
pdf.ApplyWatermark("<h1 style='color:red; opacity:0.3;'>CONFIDENTIAL</h1>", 45, VerticalAlignment.Middle, HorizontalAlignment.Center)
pdf.SaveAs("watermarked.pdf")
PDF Duo 不支持水印。IronPDF提供基于 HTML 的水印,并完全支持 CSS 样式。
密码保护
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SecuritySettings.UserPassword = "userpassword";
pdf.SecuritySettings.OwnerPassword = "ownerpassword";
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
pdf.SaveAs("secured.pdf");
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SecuritySettings.UserPassword = "userpassword";
pdf.SecuritySettings.OwnerPassword = "ownerpassword";
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
pdf.SaveAs("secured.pdf");
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SecuritySettings.UserPassword = "userpassword"
pdf.SecuritySettings.OwnerPassword = "ownerpassword"
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights
pdf.SaveAs("secured.pdf")
PDF Duo 不支持密码保护或安全设置。
文本提取
var pdf = PdfDocument.FromFile("document.pdf");
string text = pdf.ExtractAllText();
var pdf = PdfDocument.FromFile("document.pdf");
string text = pdf.ExtractAllText();
Dim pdf = PdfDocument.FromFile("document.pdf")
Dim text As String = pdf.ExtractAllText()
PDF Duo 不支持文本提取。
关键迁移说明
PDF Duo的HtmlToPdf无页面布局选项
DuoDimension.HtmlToPdf未记录涵盖纸张大小、方向或页边距的设置对象。 IronPDF在RenderingOptions上明确公开它们:
// PDF Duo: no documented per-instance settings — OpenHTML / SavePDF only.
// IronPDF:
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.MarginTop = 20;
renderer.RenderingOptions.MarginRight = 15;
renderer.RenderingOptions.MarginBottom = 20;
renderer.RenderingOptions.MarginLeft = 15;
// PDF Duo: no documented per-instance settings — OpenHTML / SavePDF only.
// IronPDF:
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.MarginTop = 20;
renderer.RenderingOptions.MarginRight = 15;
renderer.RenderingOptions.MarginBottom = 20;
renderer.RenderingOptions.MarginLeft = 15;
' PDF Duo: no documented per-instance settings — OpenHTML / SavePDF only.
' IronPDF:
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
renderer.RenderingOptions.MarginTop = 20
renderer.RenderingOptions.MarginRight = 15
renderer.RenderingOptions.MarginBottom = 20
renderer.RenderingOptions.MarginLeft = 15
保存方法命名
不同的方法名称用于写入文件:
// PDF Duo:
conv.SavePDF("output.pdf");
// IronPDF:
pdf.SaveAs("output.pdf");
// PDF Duo:
conv.SavePDF("output.pdf");
// IronPDF:
pdf.SaveAs("output.pdf");
' PDF Duo:
conv.SavePDF("output.pdf")
' IronPDF:
pdf.SaveAs("output.pdf")
加载现有PDFs
PDF Duo .NET只写PDFs——没有记录的"加载现有PDF"调用。 要操作现有的PDF,您必须转移到IronPDF(或其他库):
// PDF Duo: no equivalent.
// IronPDF:
var pdf = PdfDocument.FromFile("document.pdf");
// PDF Duo: no equivalent.
// IronPDF:
var pdf = PdfDocument.FromFile("document.pdf");
Imports IronPdf
Dim pdf = PdfDocument.FromFile("document.pdf")
HTML字符串输入
PDF Duo的OpenHTML未记录"渲染此HTML字符串"的调用。 团队首先将标记写入临时文件。IronPDF直接渲染字符串:
// PDF Duo:
File.WriteAllText("temp.html", html);
var conv = new DuoDimension.HtmlToPdf();
conv.OpenHTML("temp.html");
conv.SavePDF("output.pdf");
// IronPDF:
var renderer = new ChromePdfRenderer();
renderer.RenderHtmlAsPdf(html).SaveAs("output.pdf");
// PDF Duo:
File.WriteAllText("temp.html", html);
var conv = new DuoDimension.HtmlToPdf();
conv.OpenHTML("temp.html");
conv.SavePDF("output.pdf");
// IronPDF:
var renderer = new ChromePdfRenderer();
renderer.RenderHtmlAsPdf(html).SaveAs("output.pdf");
' PDF Duo:
File.WriteAllText("temp.html", html)
Dim conv = New DuoDimension.HtmlToPdf()
conv.OpenHTML("temp.html")
conv.SavePDF("output.pdf")
' IronPDF:
Dim renderer = New ChromePdfRenderer()
renderer.RenderHtmlAsPdf(html).SaveAs("output.pdf")
功能对比
| 特征 | PDF Duo .NET | IronPDF |
|---|---|---|
| HTML 至 PDF | 是的(引擎未披露) | 完整的 CSS3、JavaScript |
| URL 至 PDF | 是 | 完全支持授权 |
| PDF 合并 | 在记录的API中没有 | 是 |
| 页眉/页脚 | 在记录的API中没有 | 完全支持 HTML |
| 页码 | 在记录的API中没有 | 内置占位符 |
| 水印 | 在记录的API中没有 | 基于 HTML |
| 密码保护 | 在记录的API中没有 | 全面的安全选项 |
| 表格填写 | 在记录的API中没有 | 是 |
| 数字签名 | 在记录的API中没有 | 是 |
| 文本提取 | 在记录的API中没有 | 是 |
| 将 PDF 转换为图像 | 在记录的API中没有 | 是 |
| 异步支持 | 在记录的API中没有 | 完整的Async/Await |
| .NET Core/5+ | 在记录的运行时列表中没有 | 支持 |
迁移清单
迁移前
- 在代码库中查找所有 PDF Duo 引用
- 记录当前设置(页面大小、页边距等) 列出所有已使用的 PDF 操作
- 寻找新功能(标题、水印、安全)的机会
- 获取IronPDF许可证密钥
软件包变更
- 删除对
PDFDuo.dll的项目引用(PDF Duo .NET不在NuGet上)并删除供应商提供的二进制文件。 - 安装
IronPdfNuGet包:dotnet add package IronPdf - 更新从
using IronPdf;的命名空间导入
代码更改
- 在启动时添加许可证密钥配置
- 将
ChromePdfRenderer - 将
RenderHtmlFileAsPdf(path).SaveAs(path) - 将HTML字符串的临时文件绕行替换为
RenderHtmlAsPdf(html).SaveAs(path) - 将
RenderUrlAsPdf(url).SaveAs(path) - 使用
PdfDocument.Merge()替换任何外部合并步骤 - 通过
RenderingOptions明确设置页面大小和边距(无PDF Duo等价物) - 将
SaveAs() - 对于任何"加载现有PDF"工作流程,使用
PdfDocument.FromFile()(无PDF Duo等价物)
后迁移
- 运行回归测试,比较 PDF 输出
- 核实页面尺寸和边距是否一致
- 使用复杂的 HTML/CSS 进行测试(IronPDF 的现代引擎应该能更好地处理这种情况)
- 添加新功能(页眉、页脚、水印、安全功能)
- 更新文档

