在实际环境中测试
在生产中测试无水印。
随时随地为您服务。
作为一名C#开发人员,我经常面临生成和操作方面的挑战。 PDF 文件 在我的项目中。 在我们的领域中,对高效、可靠且易于集成的PDF解决方案的需求是一个常见的痛点。 这就是为什么我决定探索 APITemplate 和 IronPDF,两个流行的工具承诺可以简化C#应用程序中的PDF相关任务。
在本文中,我将分享我对 APITemplate 和 IronPDF 的实践经验,并比较它们的功能、性能和集成能力。 我旨在为您提供清晰、公正的分析,以帮助您为下一个项目做出明智的决定。 当我第一次接触到APITemplate和IronPDF时,我对它们在C#开发中解决PDF相关挑战的潜力感到好奇。 让我们分析每个工具提供的功能。
APITemplate 是一个云服务,专注于从模板生成 PDF 和图像。 它提供了一个API,允许开发人员通过将JSON数据发送到预定义的模板来创建文档和图形。 在我最初的测试中,我发现APITemplate使用简单明了。 我可以使用他们的网页界面创建一个模板,然后使用他们的API从我的C#应用程序填充数据。
APITemplate的核心优势在于其基于模板的方法。 我可以为文档和图像创建可重复使用的模板,这为我节省了大量重复任务的时间。 它还提供一个用于生成PDF的Markdown模板编辑器同步功能。 您可以通过与Zapier和其他第三方集成的可重复使用的模板生成PDF。
JSON 数据集成是我经常使用的一个功能。 它使您能够用JSON数据填充模板。 这使得与我的C#应用程序集成变得非常容易,因为我可以将对象序列化为JSON并发送到API。
API 控制台功能为我节省了大量时间。 通过它,我可以直接在他们的网站上预览和测试 API 调用,帮助我在将请求实现到我的 C# 代码中之前进行调试和微调。
能够在我的PDF中添加自定义页眉和页脚非常有价值,特别是在创建专业报告或发票时。 我可以轻松添加页码、日期或公司徽标。
IronPDF另一方面,是一个专门为C#应用程序中的PDF操作而设计的.NET库。 它提供广泛的功能,包括PDF创建、编辑和转换。 其突出功能之一是能够从HTML生成PDF文件,这对于基于网络的应用程序非常有用。
我第一次使用IronPDF的经历是通过NuGet安装它,并将其直接集成到我的C#项目中。 它的API集成过程非常顺畅,这意味着我能够迅速在我的项目中启动并运行。我对能够轻松地以编程方式创建PDF文档,而无需依赖外部服务感到印象深刻。
我注意到的关键区别是,APITemplate擅长从预定义的模板创建文档,而IronPDF在你的C#代码中提供了更灵活的自定义PDF操作。 APITemplate 的云端性质意味着您无需担心用于生成 PDF 的服务器资源,但它确实需要网络连接。 IronPDF作为本地库,可以离线工作,但会使用您的服务器资源。
IronPDF 擅长于 从HTML内容生成PDF文件. 我广泛使用此功能动态生成报告和文档。 只需将 HTML 字符串或甚至 URL 传递给该库即可。 IronPDF 对现代网页标准的广泛支持意味着我从 HTML 内容生成的每个 PDF 都呈现为高质量的文档。
此功能允许我 编辑 现有的PDF文件以编程方式。 我可以向PDF文档中添加文本、图像,甚至新页面,这对于更新报告或表格非常有用。
我发现这个功能在处理大文档时特别方便。 IronPDF 使其变得简单 结合 将多个PDF合并成一个或 (意见) 分歧 将单个PDF分成多个文件。
当我需要从PDF中提取文本内容用于分析或索引时,IronPDF的文本提取功能非常有用。 它能很好地处理各种PDF布局,使数据提取变得轻而易举。
对于涉及自动化表单填写的项目,IronPDF 表单填写 功能非常有用。 我可以通过编程填充PDF表单,从而节省手动输入数据的时间。
在我的许多项目中,安全性至关重要。 IronPDF 允许我添加 数字签名 转换为PDF,提高文档的真实性和安全性。
当处理敏感文件时,我使用IronPDF来添加 密码保护 到PDF。 这对确保我的机密信息保持安全非常有帮助。
有时我需要转换 将 PDF 页面转换为图像 用于预览或缩略图。 IronPDF使这个过程变得简单,只需要我写几行代码,并支持多种图像格式。
作为从事跨平台项目的.NET开发人员,我很欣赏IronPDF能够在不同操作系统上无缝运行,这要归功于其对.NET Standard的支持。
在C#项目中设置这些工具是相当简单的。 我将根据我的经验为您讲解 IronPDF 和 APITemplate 的流程。
要在我的 C# 项目中设置 IronPDF,我遵循以下步骤:
在 Visual Studio 中打开我的项目。
使用 NuGet 包管理器安装 IronPDF。 我使用NuGet包管理器或包管理器控制台。
Install-Package IronPdf
Install-Package IronPdf
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'Install-Package IronPdf
using IronPdf;
using IronPdf;
Imports IronPdf
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY-HERE"
就是这样! 现在我可以在我的代码中开始使用IronPDF。
对于APITemplate,由于它是基于网络的API,设置过程有些不同:
首先,我在他们的网站上注册了一个APITemplate账户。
注册后,我导航到 API 部分以获取我的 API 密钥。
在我的C#项目中,我不需要安装任何特定的软件包。 我通常使用内置的HttpClient进行API调用。
dotnet user-secrets set "APITemplate:ApiKey" "YOUR-API-KEY-HERE"
dotnet user-secrets set "APITemplate:ApiKey" "YOUR-API-KEY-HERE"
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'dotnet user-secrets @set "APITemplate:ApiKey" "YOUR-API-KEY-HERE"
using System.Net.Http;
using System.Net.Http.Headers;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", Configuration["APITemplate:ApiKey"]);
using System.Net.Http;
using System.Net.Http.Headers;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", Configuration["APITemplate:ApiKey"]);
Imports System.Net.Http
Imports System.Net.Http.Headers
Private client = New HttpClient()
client.DefaultRequestHeaders.Add("X-API-KEY", Configuration("APITemplate:ApiKey"))
现在我已经准备好向APITemplate发起API调用。
对于这个项目,我将使用 APITemplate的官方示例GitHub项目 已配置好,只需添加模板键。 完成这些设置后,我可以在我的C#项目中开始使用IronPDF和APITemplate。 IronPDF在我的应用程序中本地运行,而APITemplate需要互联网连接才能与其服务器通信。
作为一名C#开发人员,我有机会深入了解IronPDF和APITemplate。 让我们来探索一些让我印象深刻的高级功能。
IronPDF 的 HTML 转 PDF 转换非常惊人。 它不仅可以渲染静态HTML,还能处理JavaScript。 这在处理动态网页内容时对我来说是一个革命性的改变。
以下是我如何使用它的一个简单示例:
var Renderer = new ChromePdfRenderer();
string htmlContent = @"
<html>
<body>
<h1>Dynamic Chart</h1>
<canvas id='myChart'></canvas>
<script src='https://cdn.jsdelivr.net/npm/chart.js'></script>
<script>
var ctx = document.getElementById('myChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
</body>
</html>";
var PDF = Renderer.RenderHtmlAsPdf(htmlContent);
PDF.SaveAs("dynamic_chart.pdf");
var Renderer = new ChromePdfRenderer();
string htmlContent = @"
<html>
<body>
<h1>Dynamic Chart</h1>
<canvas id='myChart'></canvas>
<script src='https://cdn.jsdelivr.net/npm/chart.js'></script>
<script>
var ctx = document.getElementById('myChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
</body>
</html>";
var PDF = Renderer.RenderHtmlAsPdf(htmlContent);
PDF.SaveAs("dynamic_chart.pdf");
Dim Renderer = New ChromePdfRenderer()
Dim htmlContent As String = "
<html>
<body>
<h1>Dynamic Chart</h1>
<canvas id='myChart'></canvas>
<script src='https://cdn.jsdelivr.net/npm/chart.js'></script>
<script>
var ctx = document.getElementById('myChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
</body>
</html>"
Dim PDF = Renderer.RenderHtmlAsPdf(htmlContent)
PDF.SaveAs("dynamic_chart.pdf")
此代码使用 Chart.js 生成一个带有动态图表的 PDF。 在PDF创建过程中执行JavaScript,生成包含渲染图表的PDF。 我使用这个工具来创建动态报告,其中数据经常变化,这让我不必手动更新图表和图形。
能够包括外部脚本,比如该示例中的Chart.js,意味着我可以利用强大的JavaScript库在我的PDF中创建丰富的动态内容。 此外,此功能使我可以在HTML中使用CSS和响应式设计技术,确保生成的PDF在各种设备和打印格式上都具有出色的外观。 我甚至使用了媒体查询,从相同的HTML源创建了针对屏幕查看和打印优化的PDF。
在许多项目中,安全性至关重要,尤其是在处理敏感信息时。 IronPDF 的加密和解密功能在这些情况下非常有价值。
var pdf = PdfDocument.FromFile("input.pdf");
// Set user password (for opening the document)
pdf.Password = "user_password";
// Set owner password (for editing, printing, etc.)
pdf.OwnerPassword = "owner_password";
// Set specific permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
pdf.SaveAs("highly_secured.pdf");
var pdf = PdfDocument.FromFile("input.pdf");
// Set user password (for opening the document)
pdf.Password = "user_password";
// Set owner password (for editing, printing, etc.)
pdf.OwnerPassword = "owner_password";
// Set specific permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
pdf.SaveAs("highly_secured.pdf");
Dim pdf = PdfDocument.FromFile("input.pdf")
' Set user password (for opening the document)
pdf.Password = "user_password"
' Set owner password (for editing, printing, etc.)
pdf.OwnerPassword = "owner_password"
' Set specific permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit
pdf.SaveAs("highly_secured.pdf")
这段代码不仅使用用户密码加密PDF,还通过所有者密码设置了精细控制。 权限. 我可以明确指定用户对PDF的权限,比如打印或复制内容。
对于解密,我经常使用这种方法:
try
{
var pdf = PdfDocument.FromFile("encrypted.pdf", "user_password");
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SaveAs("decrypted.pdf");
Console.WriteLine("PDF decrypted successfully!");
}
catch (Exception ex)
{
Console.WriteLine($"Decryption failed: {ex.Message}");
}
try
{
var pdf = PdfDocument.FromFile("encrypted.pdf", "user_password");
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SaveAs("decrypted.pdf");
Console.WriteLine("PDF decrypted successfully!");
}
catch (Exception ex)
{
Console.WriteLine($"Decryption failed: {ex.Message}");
}
Try
Dim pdf = PdfDocument.FromFile("encrypted.pdf", "user_password")
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SaveAs("decrypted.pdf")
Console.WriteLine("PDF decrypted successfully!")
Catch ex As Exception
Console.WriteLine($"Decryption failed: {ex.Message}")
End Try
此代码尝试使用用户密码打开加密的PDF,移除所有安全限制,并将其保存为新的未加密文件。try-catch块有助于处理密码可能不正确的情况。
我已在各种场景中使用这些功能,例如创建安全的文档管理系统,不同的用户对PDF具有不同的访问权限。 例如,在医疗记录系统中,我确保敏感的患者信息被加密,并且只能由授权人员访问。
在处理大量PDF文件时,文件大小成为一个关键因素。 IronPDF 的 压缩功能 在管理存储和带宽限制方面一直是救星。
这是一个我如何使用压缩的更高级示例:
using IronPdf;
using IronSoftware.Drawing;
using PdfToSvg;
using System;
using PdfDocument = IronPdf.PdfDocument;
#region LicenseKey
License.LicenseKey = "License-Key";
#endregion
var PDF = PdfDocument.FromFile(@"F:/Test.pdf");
// Compress images
PDF.CompressImages(80); // 80% quality
// Compress fonts
PDF.CompressStructTree();
// Save the compressed PDF
PDF.SaveAs(@"F:/highly_compressed.pdf");
// Compare file sizes
var originalSize = new FileInfo(@"F:/Test.pdf").Length;
var compressedSize = new FileInfo(@"F:/highly_compressed.pdf").Length;
var compressionRatio = (1 - (double)compressedSize / originalSize) * 100;
Console.WriteLine($"Original size: {originalSize / 1024} KB");
Console.WriteLine($"Compressed size: {compressedSize / 1024} KB");
Console.WriteLine($"Compression ratio: {compressionRatio:F2}%");
using IronPdf;
using IronSoftware.Drawing;
using PdfToSvg;
using System;
using PdfDocument = IronPdf.PdfDocument;
#region LicenseKey
License.LicenseKey = "License-Key";
#endregion
var PDF = PdfDocument.FromFile(@"F:/Test.pdf");
// Compress images
PDF.CompressImages(80); // 80% quality
// Compress fonts
PDF.CompressStructTree();
// Save the compressed PDF
PDF.SaveAs(@"F:/highly_compressed.pdf");
// Compare file sizes
var originalSize = new FileInfo(@"F:/Test.pdf").Length;
var compressedSize = new FileInfo(@"F:/highly_compressed.pdf").Length;
var compressionRatio = (1 - (double)compressedSize / originalSize) * 100;
Console.WriteLine($"Original size: {originalSize / 1024} KB");
Console.WriteLine($"Compressed size: {compressedSize / 1024} KB");
Console.WriteLine($"Compression ratio: {compressionRatio:F2}%");
Imports IronPdf
Imports IronSoftware.Drawing
Imports PdfToSvg
Imports System
Imports PdfDocument = IronPdf.PdfDocument
#Region "LicenseKey"
License.LicenseKey = "License-Key"
'#End Region
Dim PDF = PdfDocument.FromFile("F:/Test.pdf")
' Compress images
PDF.CompressImages(80) ' 80% quality
' Compress fonts
PDF.CompressStructTree()
' Save the compressed PDF
PDF.SaveAs("F:/highly_compressed.pdf")
' Compare file sizes
Dim originalSize = (New FileInfo("F:/Test.pdf")).Length
Dim compressedSize = (New FileInfo("F:/highly_compressed.pdf")).Length
Dim compressionRatio = (1 - CDbl(compressedSize) / originalSize) * 100
Console.WriteLine($"Original size: {originalSize \ 1024} KB")
Console.WriteLine($"Compressed size: {compressedSize \ 1024} KB")
Console.WriteLine($"Compression ratio: {compressionRatio:F2}%")
这是结果:
我发现这种技术组合在不显著影响质量的情况下能够有效地减少文件大小。
我在各种场景中使用了这个功能:
电子邮件附件:发送PDF文件时,我会压缩它们以确保它们不超过附件大小限制。
Web 应用程序:对于需要用户下载的 PDF,压缩有助于减少加载时间和带宽使用。
归档:在长期保存大量 PDF 文件时,压缩可以大大降低存储成本。
在一个项目中,我为一家律师事务所开发了一个文档管理系统。 他们有成千上万的案件文件是PDF格式,其中许多是大文件大小的扫描文档。 通过实施这种压缩技术,我们将他们的存储需求减少了超过60%,从而显著节省了他们的云存储费用。
添加 数字签名 PDF 是许多业务流程中必备的功能,以确保文档的真实性和不可否认性。 IronPDF使这个复杂的任务变得异常简单。 这是我如何实现数字签名的更详细示例:
using IronPdf;
using IronPdf.Signing;
var renderer = new ChromePdfRenderer();
var pdf = PdfDocument.FromFile(@"F:/Contract.pdf");
var signature = new IronPdf.Signing.PdfSignature(@"F:/Iron.pfx", "123")
{
// Step 3. Optional signing options and a handwritten signature graphic
SigningContact = "support@ironsoftware.com",
SigningLocation = "New York, USA",
SigningReason = "Signing PDF"
};
pdf.Sign(signature);
pdf.SaveAs(@"F:/signed.pdf");
using IronPdf;
using IronPdf.Signing;
var renderer = new ChromePdfRenderer();
var pdf = PdfDocument.FromFile(@"F:/Contract.pdf");
var signature = new IronPdf.Signing.PdfSignature(@"F:/Iron.pfx", "123")
{
// Step 3. Optional signing options and a handwritten signature graphic
SigningContact = "support@ironsoftware.com",
SigningLocation = "New York, USA",
SigningReason = "Signing PDF"
};
pdf.Sign(signature);
pdf.SaveAs(@"F:/signed.pdf");
Imports IronPdf
Imports IronPdf.Signing
Private renderer = New ChromePdfRenderer()
Private pdf = PdfDocument.FromFile("F:/Contract.pdf")
Private signature = New IronPdf.Signing.PdfSignature("F:/Iron.pfx", "123") With {
.SigningContact = "support@ironsoftware.com",
.SigningLocation = "New York, USA",
.SigningReason = "Signing PDF"
}
pdf.Sign(signature)
pdf.SaveAs("F:/signed.pdf")
我已在多个实际应用中使用了此功能:
合同管理系统:我们为一家需要以电子方式发送和接收签署合同的公司实施了此系统。 数字签名确保了合同的法律效力。
医疗记录系统:在一个医疗应用中,我们使用数字签名让医生签署患者记录和处方。
能力去 分割和合并 PDF 文件 是我在文档管理系统中经常使用的基本功能。 IronPDF 对这些功能的实现既强大又灵活。 以下是拆分和合并PDF的更高级示例:
using IronPdf;
class Program
{
static void Main(string[] args)
{
// Create first PDF with three pages
const string html_a = @"
<h1>Document A</h1>
<p>This is the first page of Document A.</p>
<div style='page-break-after: always;'></div>
<h2>Document A - Page 2</h2>
<p>This is the second page of Document A.</p>
<div style='page-break-after: always;'></div>
<h2>Document A - Page 3</h2>
<p>This is the third and final page of Document A.</p>";
// Create second PDF with two pages
const string html_b = @"
<h1>Document B</h1>
<p>Welcome to the first page of Document B.</p>
<div style='page-break-after: always;'></div>
<h2>Document B - Page 2</h2>
<p>This is the second and last page of Document B.</p>";
// Render HTML to PDF
var renderer = new ChromePdfRenderer();
var pdfdoc_a = renderer.RenderHtmlAsPdf(html_a);
var pdfdoc_b = renderer.RenderHtmlAsPdf(html_b);
// Merge PDFs
var merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
merged.SaveAs(@"F:/IronPdf/MergedDocument.pdf");
Console.WriteLine("Merged PDF created: MergedDocument.pdf");
// Load the merged PDF
var pdf = PdfDocument.FromFile(@"F:/IronPdf/MergedDocument.pdf");
// Extract the first page
var firstPage = pdf.CopyPage(0);
firstPage.SaveAs(@"F:/IronPdf/FirstPageOnly.pdf");
Console.WriteLine("First page extracted: FirstPageOnly.pdf");
// Extract pages 2 to 4 (note: index starts at 0)
var middlePages = pdf.CopyPages(1, 3);
middlePages.SaveAs(@"F:/IronPdf/Pages2to4.pdf");
Console.WriteLine("Pages 2 to 4 extracted: Pages2to4.pdf");
Console.WriteLine("Process completed. Press any key to exit.");
Console.ReadKey();
}
}
using IronPdf;
class Program
{
static void Main(string[] args)
{
// Create first PDF with three pages
const string html_a = @"
<h1>Document A</h1>
<p>This is the first page of Document A.</p>
<div style='page-break-after: always;'></div>
<h2>Document A - Page 2</h2>
<p>This is the second page of Document A.</p>
<div style='page-break-after: always;'></div>
<h2>Document A - Page 3</h2>
<p>This is the third and final page of Document A.</p>";
// Create second PDF with two pages
const string html_b = @"
<h1>Document B</h1>
<p>Welcome to the first page of Document B.</p>
<div style='page-break-after: always;'></div>
<h2>Document B - Page 2</h2>
<p>This is the second and last page of Document B.</p>";
// Render HTML to PDF
var renderer = new ChromePdfRenderer();
var pdfdoc_a = renderer.RenderHtmlAsPdf(html_a);
var pdfdoc_b = renderer.RenderHtmlAsPdf(html_b);
// Merge PDFs
var merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
merged.SaveAs(@"F:/IronPdf/MergedDocument.pdf");
Console.WriteLine("Merged PDF created: MergedDocument.pdf");
// Load the merged PDF
var pdf = PdfDocument.FromFile(@"F:/IronPdf/MergedDocument.pdf");
// Extract the first page
var firstPage = pdf.CopyPage(0);
firstPage.SaveAs(@"F:/IronPdf/FirstPageOnly.pdf");
Console.WriteLine("First page extracted: FirstPageOnly.pdf");
// Extract pages 2 to 4 (note: index starts at 0)
var middlePages = pdf.CopyPages(1, 3);
middlePages.SaveAs(@"F:/IronPdf/Pages2to4.pdf");
Console.WriteLine("Pages 2 to 4 extracted: Pages2to4.pdf");
Console.WriteLine("Process completed. Press any key to exit.");
Console.ReadKey();
}
}
Imports IronPdf
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Create first PDF with three pages
Const html_a As String = "
<h1>Document A</h1>
<p>This is the first page of Document A.</p>
<div style='page-break-after: always;'></div>
<h2>Document A - Page 2</h2>
<p>This is the second page of Document A.</p>
<div style='page-break-after: always;'></div>
<h2>Document A - Page 3</h2>
<p>This is the third and final page of Document A.</p>"
' Create second PDF with two pages
Const html_b As String = "
<h1>Document B</h1>
<p>Welcome to the first page of Document B.</p>
<div style='page-break-after: always;'></div>
<h2>Document B - Page 2</h2>
<p>This is the second and last page of Document B.</p>"
' Render HTML to PDF
Dim renderer = New ChromePdfRenderer()
Dim pdfdoc_a = renderer.RenderHtmlAsPdf(html_a)
Dim pdfdoc_b = renderer.RenderHtmlAsPdf(html_b)
' Merge PDFs
Dim merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b)
merged.SaveAs("F:/IronPdf/MergedDocument.pdf")
Console.WriteLine("Merged PDF created: MergedDocument.pdf")
' Load the merged PDF
Dim pdf = PdfDocument.FromFile("F:/IronPdf/MergedDocument.pdf")
' Extract the first page
Dim firstPage = pdf.CopyPage(0)
firstPage.SaveAs("F:/IronPdf/FirstPageOnly.pdf")
Console.WriteLine("First page extracted: FirstPageOnly.pdf")
' Extract pages 2 to 4 (note: index starts at 0)
Dim middlePages = pdf.CopyPages(1, 3)
middlePages.SaveAs("F:/IronPdf/Pages2to4.pdf")
Console.WriteLine("Pages 2 to 4 extracted: Pages2to4.pdf")
Console.WriteLine("Process completed. Press any key to exit.")
Console.ReadKey()
End Sub
End Class
以下是由代码生成的合并文档:
自动化 填表 在我的许多项目中, 已经节省了大量时间。 IronPDF 允许我以编程方式填写 PDF 表单,这对处理大量表单或创建个性化文档非常有价值。 这是一个更全面的表单填写示例:
using IronPdf;
using System;
// Load the combined form
PdfDocument pdf = PdfDocument.FromFile(@"F:/completeForm.pdf");
// Handle radio buttons
var radioForm = pdf.Form.FindFormField("traveltype");
radioForm.Value = "Airplane";
// Handle checkbox
var checkboxForm = pdf.Form.FindFormField("taskCompleted");
checkboxForm.Value = "Yes";
// Handle combobox
var comboboxForm = pdf.Form.FindFormField("priority");
comboboxForm.Value = "Low";
// Print out all the available choices for combobox
foreach (var choice in comboboxForm.Choices)
{
Console.WriteLine(choice);
}
// Handle text inputs
pdf.Form.FindFormField("firstname").Value = "John";
pdf.Form.FindFormField("lastname").Value = "Smith";
// Handle text area
pdf.Form.FindFormField("address").Value = "Iron Software LLC\r\n205 N. Michigan Ave.";
// Save the edited PDF
pdf.SaveAs(@"F:/completeFormEdited.pdf");
using IronPdf;
using System;
// Load the combined form
PdfDocument pdf = PdfDocument.FromFile(@"F:/completeForm.pdf");
// Handle radio buttons
var radioForm = pdf.Form.FindFormField("traveltype");
radioForm.Value = "Airplane";
// Handle checkbox
var checkboxForm = pdf.Form.FindFormField("taskCompleted");
checkboxForm.Value = "Yes";
// Handle combobox
var comboboxForm = pdf.Form.FindFormField("priority");
comboboxForm.Value = "Low";
// Print out all the available choices for combobox
foreach (var choice in comboboxForm.Choices)
{
Console.WriteLine(choice);
}
// Handle text inputs
pdf.Form.FindFormField("firstname").Value = "John";
pdf.Form.FindFormField("lastname").Value = "Smith";
// Handle text area
pdf.Form.FindFormField("address").Value = "Iron Software LLC\r\n205 N. Michigan Ave.";
// Save the edited PDF
pdf.SaveAs(@"F:/completeFormEdited.pdf");
Imports Microsoft.VisualBasic
Imports IronPdf
Imports System
' Load the combined form
Private pdf As PdfDocument = PdfDocument.FromFile("F:/completeForm.pdf")
' Handle radio buttons
Private radioForm = pdf.Form.FindFormField("traveltype")
radioForm.Value = "Airplane"
' Handle checkbox
Dim checkboxForm = pdf.Form.FindFormField("taskCompleted")
checkboxForm.Value = "Yes"
' Handle combobox
Dim comboboxForm = pdf.Form.FindFormField("priority")
comboboxForm.Value = "Low"
' Print out all the available choices for combobox
For Each choice In comboboxForm.Choices
Console.WriteLine(choice)
Next choice
' Handle text inputs
pdf.Form.FindFormField("firstname").Value = "John"
pdf.Form.FindFormField("lastname").Value = "Smith"
' Handle text area
pdf.Form.FindFormField("address").Value = "Iron Software LLC" & vbCrLf & "205 N. Michigan Ave."
' Save the edited PDF
pdf.SaveAs("F:/completeFormEdited.pdf")
我已在多个实际应用中使用了此功能:
HR 入职系统: 我们创建了一个系统,根据来自 HR 数据库的信息自动填写新员工的文件,从而节省了数小时的手动数据输入。
保险索赔处理: 对于一家保险公司,我们构建了一个系统,可以预先填写索赔表单上的投保人信息,从而显著加快索赔提交过程。
学校申请系统: 在一个教育项目中,我们实现了一个基于学生数据填写学校申请表的系统,使申请过程对学生和行政人员都更加简单。
税表生成: 对于一家会计公司,我们创建了一个基于客户财务数据自动填填写税表的系统,减少了错误并在报税季节节省了时间。
通过编程方式填写表单的能力一直是自动化许多业务流程的关键因素,从而显著节省时间并减少人工数据输入的错误。
添加 水印 将文件转换为PDF通常是出于品牌化、安全性或状态指示的需要。 IronPDF 提供灵活的水印功能,我发现它在许多项目中都很有用。 这是我如何使用水印的一个更详细的示例:
using IronPdf;
using IronSoftware.Drawing;
string watermarkHtml = @"
<img style='width: 250px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>");
// Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 90);
pdf.SaveAs("watermarkOpacity&Rotation.pdf");
using IronPdf;
using IronSoftware.Drawing;
string watermarkHtml = @"
<img style='width: 250px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>");
// Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 90);
pdf.SaveAs("watermarkOpacity&Rotation.pdf");
Imports IronPdf
Imports IronSoftware.Drawing
Private watermarkHtml As String = "
<img style='width: 250px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>"
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>")
' Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation:= 30, opacity:= 90)
pdf.SaveAs("watermarkOpacity&Rotation.pdf")
APITemplate的动态模板生成是一个强大的功能,它允许使用自定义JSON数据创建高度可定制的文档。 APITemplate 的 API 支持动态组件。 您可以获得代码的 PDF 和图像输出。 在 API 控制台中,我能够使用所见即所得编辑器轻松生成 PDF 文档。
让我们更深入地探讨我如何在我的项目中使用这一点。
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
class ReturnContent
{
public string download_url
{
get;
set;
}
public string status
{
get;
set;
}
}
class Program
{
static async Task Main(string[] args)
{
var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
var template_id = "bf077b23b4a407ae";
var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}";
var data = new
{
date = "15/05/2022",
invoice_no = "435568799",
sender_address1 = "3244 Jurong Drive",
sender_address2 = "Falmouth Maine 1703",
sender_phone = "255-781-6789",
sender_email = "dev@ironsoftware.com",
rece_addess1 = "2354 Lakeside Drive",
rece_addess2 = "New York 234562 ",
rece_phone = "34333-84-223",
rece_email = "info@ironsoftware.com",
items = new[] {
new {
item_name = "Oil",
unit = 1,
unit_price = 100,
total = 100
},
new {
item_name = "Rice",
unit = 2,
unit_price = 200,
total = 400
},
new {
item_name = "Orange",
unit = 7,
unit_price = 20,
total = 1400
}
},
total = "total",
footer_email = "info@ironsoftware.com"
};
var json_content = JsonSerializer.Serialize(data);
var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
var byteContent = new ByteArrayContent(buffer);
Console.WriteLine(json_content);
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
var response = await client.PostAsync(url, byteContent);
var ret = await response.Content.ReadAsStringAsync();
var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
if (returnContent.status == "success")
{
Console.WriteLine($"Downloading {returnContent.download_url}...");
var download_response = await client.GetAsync(returnContent.download_url);
using (var stream = await download_response.Content.ReadAsStreamAsync())
{
var fileInfo = new FileInfo(@"F:/generated_document.pdf");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
}
Console.WriteLine("PDF file has been downloaded and saved as 'generated_document.pdf'");
}
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
class ReturnContent
{
public string download_url
{
get;
set;
}
public string status
{
get;
set;
}
}
class Program
{
static async Task Main(string[] args)
{
var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
var template_id = "bf077b23b4a407ae";
var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}";
var data = new
{
date = "15/05/2022",
invoice_no = "435568799",
sender_address1 = "3244 Jurong Drive",
sender_address2 = "Falmouth Maine 1703",
sender_phone = "255-781-6789",
sender_email = "dev@ironsoftware.com",
rece_addess1 = "2354 Lakeside Drive",
rece_addess2 = "New York 234562 ",
rece_phone = "34333-84-223",
rece_email = "info@ironsoftware.com",
items = new[] {
new {
item_name = "Oil",
unit = 1,
unit_price = 100,
total = 100
},
new {
item_name = "Rice",
unit = 2,
unit_price = 200,
total = 400
},
new {
item_name = "Orange",
unit = 7,
unit_price = 20,
total = 1400
}
},
total = "total",
footer_email = "info@ironsoftware.com"
};
var json_content = JsonSerializer.Serialize(data);
var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
var byteContent = new ByteArrayContent(buffer);
Console.WriteLine(json_content);
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
var response = await client.PostAsync(url, byteContent);
var ret = await response.Content.ReadAsStringAsync();
var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
if (returnContent.status == "success")
{
Console.WriteLine($"Downloading {returnContent.download_url}...");
var download_response = await client.GetAsync(returnContent.download_url);
using (var stream = await download_response.Content.ReadAsStreamAsync())
{
var fileInfo = new FileInfo(@"F:/generated_document.pdf");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
}
Console.WriteLine("PDF file has been downloaded and saved as 'generated_document.pdf'");
}
}
}
}
Imports System
Imports System.IO
Imports System.Net.Http
Imports System.Text.Json
Imports System.Threading.Tasks
Namespace csharp
Friend Class ReturnContent
Public Property download_url() As String
Public Property status() As String
End Class
Friend Class Program
Shared Async Function Main(ByVal args() As String) As Task
Dim api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw="
Dim template_id = "bf077b23b4a407ae"
Dim url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}"
Dim data = New With {
Key .date = "15/05/2022",
Key .invoice_no = "435568799",
Key .sender_address1 = "3244 Jurong Drive",
Key .sender_address2 = "Falmouth Maine 1703",
Key .sender_phone = "255-781-6789",
Key .sender_email = "dev@ironsoftware.com",
Key .rece_addess1 = "2354 Lakeside Drive",
Key .rece_addess2 = "New York 234562 ",
Key .rece_phone = "34333-84-223",
Key .rece_email = "info@ironsoftware.com",
Key .items = {
New With {
Key .item_name = "Oil",
Key .unit = 1,
Key .unit_price = 100,
Key .total = 100
},
New With {
Key .item_name = "Rice",
Key .unit = 2,
Key .unit_price = 200,
Key .total = 400
},
New With {
Key .item_name = "Orange",
Key .unit = 7,
Key .unit_price = 20,
Key .total = 1400
}
},
Key .total = "total",
Key .footer_email = "info@ironsoftware.com"
}
Dim json_content = JsonSerializer.Serialize(data)
Dim buffer = System.Text.Encoding.UTF8.GetBytes(json_content)
Dim byteContent = New ByteArrayContent(buffer)
Console.WriteLine(json_content)
Dim client = New HttpClient()
client.DefaultRequestHeaders.Add("X-API-KEY", api_key)
Dim response = Await client.PostAsync(url, byteContent)
Dim ret = Await response.Content.ReadAsStringAsync()
Dim returnContent = JsonSerializer.Deserialize(Of ReturnContent)(ret)
If returnContent.status = "success" Then
Console.WriteLine($"Downloading {returnContent.download_url}...")
Dim download_response = Await client.GetAsync(returnContent.download_url)
Using stream = Await download_response.Content.ReadAsStreamAsync()
Dim fileInfo As New FileInfo("F:/generated_document.pdf")
Using fileStream = fileInfo.OpenWrite()
Await stream.CopyToAsync(fileStream)
End Using
End Using
Console.WriteLine("PDF file has been downloaded and saved as 'generated_document.pdf'")
End If
End Function
End Class
End Namespace
这是生成的PDF文档:
APITemplate 的批量 PDF 生成功能在一次 API 调用中创建多个文档时是一个革命性的改变。 以下是我如何使用它的更详细示例:
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace csharp
{
class ReturnContent
{
public string download_url { get; set; }
public string status { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
var template_id = "d4f77b23b4ab09fa";
var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}";
var membershipCards = new List<object>
{
new
{
name = "Iron Dev 1",
email = "dev1@ironsoftware.com",
membership_id = "M001",
expiry_date = "2024-12-31"
},
new
{
name = "Iron Dev 2",
email = "dev2@ironsoftware.com",
membership_id = "M002",
expiry_date = "2025-06-30"
},
new
{
name = "Iron Dev 3",
email = "dev3@ironsoftware.com",
membership_id = "M003",
expiry_date = "2024-09-15"
}
};
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
for (int i = 0; i < membershipCards.Count; i++)
{
var json_content = JsonSerializer.Serialize(membershipCards[i]);
var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
var byteContent = new ByteArrayContent(buffer);
Console.WriteLine($"Creating PDF for {((dynamic)membershipCards[i]).name}...");
var response = await client.PostAsync(url, byteContent);
var ret = await response.Content.ReadAsStringAsync();
var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
if (returnContent.status == "success")
{
Console.WriteLine($"Downloading {returnContent.download_url}...");
var download_response = await client.GetAsync(returnContent.download_url);
using (var stream = await download_response.Content.ReadAsStreamAsync())
{
var fileInfo = new FileInfo($"F:/membership_card_{i + 1}.pdf");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
}
Console.WriteLine($"PDF file has been downloaded and saved as 'membership_card_{i + 1}.pdf'");
}
else
{
Console.WriteLine($"Failed to create PDF for {((dynamic)membershipCards[i]).name}. Status: {returnContent.status}");
}
}
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace csharp
{
class ReturnContent
{
public string download_url { get; set; }
public string status { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
var template_id = "d4f77b23b4ab09fa";
var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}";
var membershipCards = new List<object>
{
new
{
name = "Iron Dev 1",
email = "dev1@ironsoftware.com",
membership_id = "M001",
expiry_date = "2024-12-31"
},
new
{
name = "Iron Dev 2",
email = "dev2@ironsoftware.com",
membership_id = "M002",
expiry_date = "2025-06-30"
},
new
{
name = "Iron Dev 3",
email = "dev3@ironsoftware.com",
membership_id = "M003",
expiry_date = "2024-09-15"
}
};
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
for (int i = 0; i < membershipCards.Count; i++)
{
var json_content = JsonSerializer.Serialize(membershipCards[i]);
var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
var byteContent = new ByteArrayContent(buffer);
Console.WriteLine($"Creating PDF for {((dynamic)membershipCards[i]).name}...");
var response = await client.PostAsync(url, byteContent);
var ret = await response.Content.ReadAsStringAsync();
var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
if (returnContent.status == "success")
{
Console.WriteLine($"Downloading {returnContent.download_url}...");
var download_response = await client.GetAsync(returnContent.download_url);
using (var stream = await download_response.Content.ReadAsStreamAsync())
{
var fileInfo = new FileInfo($"F:/membership_card_{i + 1}.pdf");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
}
Console.WriteLine($"PDF file has been downloaded and saved as 'membership_card_{i + 1}.pdf'");
}
else
{
Console.WriteLine($"Failed to create PDF for {((dynamic)membershipCards[i]).name}. Status: {returnContent.status}");
}
}
}
}
}
'INSTANT VB NOTE: 'Option Strict Off' is used here since dynamic typing is used:
Option Strict Off
Imports System
Imports System.IO
Imports System.Net.Http
Imports System.Text.Json
Imports System.Threading.Tasks
Imports System.Collections.Generic
Namespace csharp
Friend Class ReturnContent
Public Property download_url() As String
Public Property status() As String
End Class
Friend Class Program
Shared Async Function Main(ByVal args() As String) As Task
Dim api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw="
Dim template_id = "d4f77b23b4ab09fa"
Dim url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}"
Dim membershipCards = New List(Of Object) From {
New With {
Key .name = "Iron Dev 1",
Key .email = "dev1@ironsoftware.com",
Key .membership_id = "M001",
Key .expiry_date = "2024-12-31"
},
New With {
Key .name = "Iron Dev 2",
Key .email = "dev2@ironsoftware.com",
Key .membership_id = "M002",
Key .expiry_date = "2025-06-30"
},
New With {
Key .name = "Iron Dev 3",
Key .email = "dev3@ironsoftware.com",
Key .membership_id = "M003",
Key .expiry_date = "2024-09-15"
}
}
Dim client = New HttpClient()
client.DefaultRequestHeaders.Add("X-API-KEY", api_key)
For i As Integer = 0 To membershipCards.Count - 1
Dim json_content = JsonSerializer.Serialize(membershipCards(i))
Dim buffer = System.Text.Encoding.UTF8.GetBytes(json_content)
Dim byteContent = New ByteArrayContent(buffer)
'INSTANT VB NOTE: In the following line, Instant VB substituted 'Object' for 'dynamic' - this will work in VB with Option Strict Off:
Console.WriteLine($"Creating PDF for {CType(membershipCards(i), Object).name}...")
Dim response = Await client.PostAsync(url, byteContent)
Dim ret = Await response.Content.ReadAsStringAsync()
Dim returnContent = JsonSerializer.Deserialize(Of ReturnContent)(ret)
If returnContent.status = "success" Then
Console.WriteLine($"Downloading {returnContent.download_url}...")
Dim download_response = Await client.GetAsync(returnContent.download_url)
Using stream = Await download_response.Content.ReadAsStreamAsync()
Dim fileInfo As New FileInfo($"F:/membership_card_{i + 1}.pdf")
Using fileStream = fileInfo.OpenWrite()
Await stream.CopyToAsync(fileStream)
End Using
End Using
Console.WriteLine($"PDF file has been downloaded and saved as 'membership_card_{i + 1}.pdf'")
Else
'INSTANT VB NOTE: In the following line, Instant VB substituted 'Object' for 'dynamic' - this will work in VB with Option Strict Off:
Console.WriteLine($"Failed to create PDF for {CType(membershipCards(i), Object).name}. Status: {returnContent.status}")
End If
Next i
End Function
End Class
End Namespace
此代码通过单个API调用生成多个会员卡。 每张卡都附有个人会员信息。 这是由此代码生成的一张卡片:
虽然PDF生成是APITemplate的主要关注点,但其图像生成能力同样令人印象深刻。您可以在控制台中使用图像模板生成社交媒体图像。 它还提供响应式图像智能裁剪。横幅生成 API 与图像 API 相同。 这是我使用它的一个更复杂的示例:
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
class ReturnContent
{
public string download_url { get; set; }
public string status { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
var template_id = "f4377b23b4aeeed0";
var url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}";
var json_content = @"{
""overrides"": [
{
""name"": ""rect_image_bg"",
""stroke"": ""grey"",
""src"": ""https://images.unsplash.com/photo-1542401886-65d6c61db217?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHwzfHxkZXNlcnR8ZW58MHwwfHx8MTYyMTUxOTI2OA&ixlib=rb-1.2.1&q=80&w=1080""
},
{
""name"": ""rect_container"",
""stroke"": ""grey"",
""backgroundColor"": ""rgba(255, 255, 255, 0.62)""
},
{
""name"": ""text_quote"",
""text"": ""Just witnessed the most breathtaking sunset over the Sahara. The way the light dances on the dunes, painting the sky in shades of orange and purple, is truly magical. Nature's artistry at its finest! 🌅🐫 #DesertAdventures #SaharaSkies"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#414141""
},
{
""name"": ""text_footer"",
""text"": ""2024-07-30 - Twitter - iPhone 16 Pro"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#666666""
},
{
""name"": ""circle_profile"",
""stroke"": ""grey"",
""src"": ""https://images.unsplash.com/photo-1520998116484-6eeb2f72b5b9?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHw2Mnx8aGFwcHl8ZW58MHwwfHx8MTYyMTY5MjkwNw&ixlib=rb-1.2.1&q=80&w=1080""
},
{
""name"": ""text_name"",
""text"": ""Sarah Wanderlust"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#4E4E4E""
},
{
""name"": ""text_twitter"",
""text"": ""@sarahexplores"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#4E4E4E""
}
]
}";
var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
var byteContent = new ByteArrayContent(buffer);
Console.WriteLine(json_content);
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
var response = await client.PostAsync(url, byteContent);
var ret = await response.Content.ReadAsStringAsync();
var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
if (returnContent.status == "success")
{
Console.WriteLine($"Downloading {returnContent.download_url}...");
var download_response = await client.GetAsync(returnContent.download_url);
using (var stream = await download_response.Content.ReadAsStreamAsync())
{
var fileInfo = new FileInfo("image.jpeg");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
}
}
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
class ReturnContent
{
public string download_url { get; set; }
public string status { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
var template_id = "f4377b23b4aeeed0";
var url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}";
var json_content = @"{
""overrides"": [
{
""name"": ""rect_image_bg"",
""stroke"": ""grey"",
""src"": ""https://images.unsplash.com/photo-1542401886-65d6c61db217?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHwzfHxkZXNlcnR8ZW58MHwwfHx8MTYyMTUxOTI2OA&ixlib=rb-1.2.1&q=80&w=1080""
},
{
""name"": ""rect_container"",
""stroke"": ""grey"",
""backgroundColor"": ""rgba(255, 255, 255, 0.62)""
},
{
""name"": ""text_quote"",
""text"": ""Just witnessed the most breathtaking sunset over the Sahara. The way the light dances on the dunes, painting the sky in shades of orange and purple, is truly magical. Nature's artistry at its finest! 🌅🐫 #DesertAdventures #SaharaSkies"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#414141""
},
{
""name"": ""text_footer"",
""text"": ""2024-07-30 - Twitter - iPhone 16 Pro"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#666666""
},
{
""name"": ""circle_profile"",
""stroke"": ""grey"",
""src"": ""https://images.unsplash.com/photo-1520998116484-6eeb2f72b5b9?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHw2Mnx8aGFwcHl8ZW58MHwwfHx8MTYyMTY5MjkwNw&ixlib=rb-1.2.1&q=80&w=1080""
},
{
""name"": ""text_name"",
""text"": ""Sarah Wanderlust"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#4E4E4E""
},
{
""name"": ""text_twitter"",
""text"": ""@sarahexplores"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#4E4E4E""
}
]
}";
var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
var byteContent = new ByteArrayContent(buffer);
Console.WriteLine(json_content);
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
var response = await client.PostAsync(url, byteContent);
var ret = await response.Content.ReadAsStringAsync();
var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
if (returnContent.status == "success")
{
Console.WriteLine($"Downloading {returnContent.download_url}...");
var download_response = await client.GetAsync(returnContent.download_url);
using (var stream = await download_response.Content.ReadAsStreamAsync())
{
var fileInfo = new FileInfo("image.jpeg");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
}
}
}
}
}
Imports System
Imports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Namespace csharp
Friend Class ReturnContent
Public Property download_url() As String
Public Property status() As String
End Class
Friend Class Program
Shared Async Function Main(ByVal args() As String) As Task
Dim api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw="
Dim template_id = "f4377b23b4aeeed0"
Dim url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}"
Dim json_content = "{
""overrides"": [
{
""name"": ""rect_image_bg"",
""stroke"": ""grey"",
""src"": ""https://images.unsplash.com/photo-1542401886-65d6c61db217?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHwzfHxkZXNlcnR8ZW58MHwwfHx8MTYyMTUxOTI2OA&ixlib=rb-1.2.1&q=80&w=1080""
},
{
""name"": ""rect_container"",
""stroke"": ""grey"",
""backgroundColor"": ""rgba(255, 255, 255, 0.62)""
},
{
""name"": ""text_quote"",
""text"": ""Just witnessed the most breathtaking sunset over the Sahara. The way the light dances on the dunes, painting the sky in shades of orange and purple, is truly magical. Nature's artistry at its finest! 🌅🐫 #DesertAdventures #SaharaSkies"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#414141""
},
{
""name"": ""text_footer"",
""text"": ""2024-07-30 - Twitter - iPhone 16 Pro"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#666666""
},
{
""name"": ""circle_profile"",
""stroke"": ""grey"",
""src"": ""https://images.unsplash.com/photo-1520998116484-6eeb2f72b5b9?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHw2Mnx8aGFwcHl8ZW58MHwwfHx8MTYyMTY5MjkwNw&ixlib=rb-1.2.1&q=80&w=1080""
},
{
""name"": ""text_name"",
""text"": ""Sarah Wanderlust"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#4E4E4E""
},
{
""name"": ""text_twitter"",
""text"": ""@sarahexplores"",
""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
""color"": ""#4E4E4E""
}
]
}"
Dim buffer = System.Text.Encoding.UTF8.GetBytes(json_content)
Dim byteContent = New ByteArrayContent(buffer)
Console.WriteLine(json_content)
Dim client = New HttpClient()
client.DefaultRequestHeaders.Add("X-API-KEY", api_key)
Dim response = Await client.PostAsync(url, byteContent)
Dim ret = Await response.Content.ReadAsStringAsync()
Dim returnContent = JsonSerializer.Deserialize(Of ReturnContent)(ret)
If returnContent.status = "success" Then
Console.WriteLine($"Downloading {returnContent.download_url}...")
Dim download_response = Await client.GetAsync(returnContent.download_url)
Using stream = Await download_response.Content.ReadAsStreamAsync()
Dim fileInfo As New FileInfo("image.jpeg")
Using fileStream = fileInfo.OpenWrite()
Await stream.CopyToAsync(fileStream)
End Using
End Using
End If
End Function
End Class
End Namespace
此示例生成具有动态内容、自定义背景颜色和嵌入产品图像的产品宣传图片。
APITemplate 的内置二维码生成功能极大地提升了我的许多项目。 您可以将数据URL放入内容中以生成QR码。 这是我使用它的一个更复杂的示例:
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
class ReturnContent
{
public string download_url { get; set; }
public string status { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var api_key = "API-Key";
var template_id = "Template-Key";
var url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}";
var json_content = @"{
""overrides"": [
{
""name"": ""background-color"",
""stroke"": ""grey"",
""backgroundColor"": ""#FFFFFF""
},
{
""name"": ""qr_1"",
""content"": ""http://ironpdf.com/"",
""backgroundColor"": ""white"",
""color"": ""#000000""
}
]
}";
var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
var byteContent = new ByteArrayContent(buffer);
//Console.WriteLine(json_content);
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
var response = await client.PostAsync(url, byteContent);
var ret = await response.Content.ReadAsStringAsync();
var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
Console.WriteLine(returnContent.status);
if (returnContent.status == "success")
{
Console.WriteLine($"Downloading {returnContent.download_url}...");
var download_response = await client.GetAsync(returnContent.download_url);
using (var stream = await download_response.Content.ReadAsStreamAsync())
{
var fileInfo = new FileInfo(@"F:/QRimage.jpeg");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
}
}
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
class ReturnContent
{
public string download_url { get; set; }
public string status { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var api_key = "API-Key";
var template_id = "Template-Key";
var url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}";
var json_content = @"{
""overrides"": [
{
""name"": ""background-color"",
""stroke"": ""grey"",
""backgroundColor"": ""#FFFFFF""
},
{
""name"": ""qr_1"",
""content"": ""http://ironpdf.com/"",
""backgroundColor"": ""white"",
""color"": ""#000000""
}
]
}";
var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
var byteContent = new ByteArrayContent(buffer);
//Console.WriteLine(json_content);
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
var response = await client.PostAsync(url, byteContent);
var ret = await response.Content.ReadAsStringAsync();
var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
Console.WriteLine(returnContent.status);
if (returnContent.status == "success")
{
Console.WriteLine($"Downloading {returnContent.download_url}...");
var download_response = await client.GetAsync(returnContent.download_url);
using (var stream = await download_response.Content.ReadAsStreamAsync())
{
var fileInfo = new FileInfo(@"F:/QRimage.jpeg");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
}
}
}
}
}
Imports System
Imports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Namespace csharp
Friend Class ReturnContent
Public Property download_url() As String
Public Property status() As String
End Class
Friend Class Program
Shared Async Function Main(ByVal args() As String) As Task
Dim api_key = "API-Key"
Dim template_id = "Template-Key"
Dim url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}"
Dim json_content = "{
""overrides"": [
{
""name"": ""background-color"",
""stroke"": ""grey"",
""backgroundColor"": ""#FFFFFF""
},
{
""name"": ""qr_1"",
""content"": ""http://ironpdf.com/"",
""backgroundColor"": ""white"",
""color"": ""#000000""
}
]
}"
Dim buffer = System.Text.Encoding.UTF8.GetBytes(json_content)
Dim byteContent = New ByteArrayContent(buffer)
'Console.WriteLine(json_content);
Dim client = New HttpClient()
client.DefaultRequestHeaders.Add("X-API-KEY", api_key)
Dim response = Await client.PostAsync(url, byteContent)
Dim ret = Await response.Content.ReadAsStringAsync()
Dim returnContent = JsonSerializer.Deserialize(Of ReturnContent)(ret)
Console.WriteLine(returnContent.status)
If returnContent.status = "success" Then
Console.WriteLine($"Downloading {returnContent.download_url}...")
Dim download_response = Await client.GetAsync(returnContent.download_url)
Using stream = Await download_response.Content.ReadAsStreamAsync()
Dim fileInfo As New FileInfo("F:/QRimage.jpeg")
Using fileStream = fileInfo.OpenWrite()
Await stream.CopyToAsync(fileStream)
End Using
End Using
End If
End Function
End Class
End Namespace
作为一名经常处理PDF生成和操作的C#开发人员,我发现文档和支持的质量可以决定一个项目的成败。 让我们深入探讨我对IronPDF和APITemplate文档及支持的经验。
IronPDF 的文档全面且结构良好,这对我的项目有很大帮助。 以下是我经验的详细分解:IronPDF 文档可在https://ironpdf.com/docs/获取,其内容相当广泛。以下是我欣赏的一些关键方面:
入门指南: 文档以清晰的分步指南开始,指导您如何通过NuGet安装IronPDF并创建您的首个PDF。 这帮助我在最初的项目中迅速启动和运行。
API 参考: API 参考资料详尽,涵盖所有类和方法。 每个条目都包含C#示例,它们在实现特定功能时对我非常有价值。
代码示例:在整个文档中,有许多代码片段和完整示例。 当我需要实现更复杂的PDF操作时,这些特别有帮助。
教程和操作指南: IronPDF 提供了详细的教程,涵盖常见任务,如从 HTML 创建 PDF、添加水印或处理表单。 这些案例指导我了解更高级的用例。
IronPDF 的 联系 响应迅速,支持渠道在我的体验中非常有帮助:
电子邮件支持: 当我遇到复杂问题时,我曾使用他们的电子邮件支持。 响应时间通常在24小时内,支持团队对产品非常了解。
社区论坛: IronPDF 设有一个社区论坛,开发者可以在此提问并分享解决方案。 我既找到了我问题的答案,也基于我的经验贡献了解决方案。
Stack Overflow: IronPDF 团队积极监控 [ironpdf] 标签 在 Stack Overflow 上。 我在那儿发布的问题得到了有用的回复。
定期更新: IronPDF 经常发布包含错误修复和新功能的更新。 详细的更新日志帮助我了解每个版本的新功能或更改。
APITemplate的文档和支持结构与IronPDF不同,反映了其作为云服务的性质。这是我的经验:
APITemplate的文档可在https://docs.apitemplate.io/reference/api-reference.html获取,并重点介绍API的使用。 以下是要点:
API参考: 文档提供了清晰的API参考,详细说明了所有可用的端点、必需的参数和响应格式。 这是我在将APITemplate集成到我的C#应用程序时的首选资源。
APITemplate 的支持结构更侧重于电子邮件支持:
电子邮件支持: 当我遇到问题或有疑问时,我使用了他们的电子邮件支持。 响应时间通常在1-2个工作日内。
IronPDF提供多种定价等级以满足不同需求:
Lite:定价为 $749,适合单个开发人员进行单个项目开发。 这是一次性费用,使其成为小型项目或个人开发者的经济实惠选择。
Professional:售价为1,499美元,此选项支持最多10名开发人员、10个地点和10个项目。 该级别还包括一次性费用,为中小型团队提供更多灵活性。
无限:价格为2,999美元,此级别允许不限数量的开发人员、地点和项目。 这对于需要广泛使用且没有限制的大型团队和企业来说是理想的选择。
IronPDF还为较大的组织和需要将PDF功能集成到商业产品中的企业提供企业和OEM再发布许可证。 它还提供一个 免费试用 测试。
APITemplate 通过其基于API的PDF生成服务提供了不同的方法。定价通常基于API调用的次数,从而使其对于不同的使用模式更具灵活性:
基本计划:通常从较低的价格开始,每月有一定数量的API调用限制。 这适合有最低限度PDF生成需求的小项目或企业。
标准计划:此计划包括更多的 API 调用和附加功能,适合中型企业。
企业计划:为高流量用户量身定制,此计划提供最多的 API 调用和优质功能,如优先支持和自定义集成。
APITemplate的许可非常简单,通常与按月或按年的订阅模式相关联。
定价模式:IronPDF 使用一次性收费模式,从长远来看可以节省成本,特别适用于持续、高频使用。 另一方面,APITemplate 使用基于订阅的模式,随着使用量的增加可以更灵活和具有可扩展性。
IronPDF和APITemplate都提供从HTML内容生成PDF的功能,但IronPDF的实现更加健壮和灵活。 以下是比较:
using IronPdf;
var renderer = new ChromePdfRenderer();
var html = @"
<html>
<head>
<style>
body { font-family: Arial, sans-serif; }
.header { color: #0066cc; font-size: 24px; }
.content { margin-top: 20px; }
</style>
</head>
<body>
<div class='header'>Dynamic Report</div>
<div class='content'>
<p>This report was generated on: <script>document.write(new Date().toLocaleString());</script></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("IronPDF_report.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();
var html = @"
<html>
<head>
<style>
body { font-family: Arial, sans-serif; }
.header { color: #0066cc; font-size: 24px; }
.content { margin-top: 20px; }
</style>
</head>
<body>
<div class='header'>Dynamic Report</div>
<div class='content'>
<p>This report was generated on: <script>document.write(new Date().toLocaleString());</script></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("IronPDF_report.pdf");
Imports IronPdf
Private renderer = New ChromePdfRenderer()
Private html = "
<html>
<head>
<style>
body { font-family: Arial, sans-serif; }
.header { color: #0066cc; font-size: 24px; }
.content { margin-top: 20px; }
</style>
</head>
<body>
<div class='header'>Dynamic Report</div>
<div class='content'>
<p>This report was generated on: <script>document.write(new Date().toLocaleString());</script></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</body>
</html>"
Private pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("IronPDF_report.pdf")
using System.Net.Http;
using System.Text.Json;
var apiKey = "your_api_key";
var templateId = "your_template_id";
var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={templateId}";
var data = new
{
header = "Dynamic Report",
content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
date = DateTime.Now.ToShortDateString()
};
var json = JsonSerializer.Serialize(data);
var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", apiKey);
var response = await client.PostAsync(url, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("APITemplate_report.pdf", pdfBytes);
using System.Net.Http;
using System.Text.Json;
var apiKey = "your_api_key";
var templateId = "your_template_id";
var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={templateId}";
var data = new
{
header = "Dynamic Report",
content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
date = DateTime.Now.ToShortDateString()
};
var json = JsonSerializer.Serialize(data);
var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", apiKey);
var response = await client.PostAsync(url, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("APITemplate_report.pdf", pdfBytes);
Imports System.Net.Http
Imports System.Text.Json
Private apiKey = "your_api_key"
Private templateId = "your_template_id"
Private url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={templateId}"
Private data = New With {
Key .header = "Dynamic Report",
Key .content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
Key .date = DateTime.Now.ToShortDateString()
}
Private json = JsonSerializer.Serialize(data)
Private content = New StringContent(json, System.Text.Encoding.UTF8, "application/json")
Private client = New HttpClient()
client.DefaultRequestHeaders.Add("X-API-KEY", apiKey)
Dim response = Await client.PostAsync(url, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
File.WriteAllBytes("APITemplate_report.pdf", pdfBytes)
JavaScript 支持:IronPDF 完全支持在 HTML 中执行 JavaScript,允许动态内容生成。 (例如当前日期). APITemplate通常需要预先提供所有数据。
CSS 灵活性:使用 IronPDF,您可以在 HTML 中直接完全控制 CSS 样式。 APITemplate通常需要预定义的模板,并且自定义选项有限。
性能:IronPDF 本地处理 HTML,从而加快 PDF 生成速度,尤其适用于复杂文档。 APITemplate 的云端方法可能会引入延迟。
离线功能:IronPDF 可以离线工作,这对于互联网连接受限或有高安全性要求的应用程序非常有用。 APITemplate始终需要互联网连接。
动态内容:IronPDF允许即时生成更具动态性的内容,而APITemplate通常需要预定义的模板结构。
自定义:IronPDF 提供对 PDF 生成过程更细致的控制,包括页面大小、边距和其他 PDF 特定设置的选项。
在广泛使用IronPDF和APITemplate进行各种C#项目后,我开始欣赏每个工具的独特优势。 然而,对于我大多数与PDF相关的任务而言,IronPDF始终被证明是更优的选择。尽管APITemplate有其优点,特别是在简单的模板化文档生成方面,但我发现IronPDF的多功能性使其在处理这些任务时同样有效,同时还具备在需要时应对更复杂的PDF操作的能力。
总之,虽然这两种工具各有其作用,但IronPDF在C#开发中的PDF操作方面始终被证明是更强大、灵活且具有成本效益的解决方案。 其强大的功能集、出色的性能和全面的支持使其成为我处理任何与PDF相关任务的首选,从最简单的文档生成到最复杂的PDF处理。