跳至页脚内容
产品比较

IronPDF & ComPDFKit之间的比较

IronPDF在C# PDF生成方面优于ComPDFKit,具有本地Chromium引擎的HTML渲染、完整的Bootstrap支持、完整的文档以及出色的.NET集成,而ComPDFKit需要通过外部API调用进行HTML转换,并缺乏高级CSS框架兼容性。

PDF,是便携文档格式的缩写,由Adobe创建,以确保文件共享中的统一性。 此格式在各类设备和操作系统上保持一致的布局、文本和图像。 PDF提供安全、交互功能和紧凑的文件大小,是分发不易被篡改文档的理想选择。

使用C#的开发者可以通过PDF库来处理PDF文件。 这些库支持文档创建、内容修改以及文本和图像的提取。 它们支持诸如表单处理、数字签名和跨平台兼容性等功能。 这些库旨在提升性能,支持高效的PDF处理。

此文章比较了两个C# PDF库:IronPDFComPDFKit。 比较内容包括功能、特性、代码示例和授权。 通过研究这些方面,开发者可以确定哪个库最适合他们的PDF项目。

快速比较概述

在深入详细分析之前,这里是关键特性的完整对比:

特征 IronPDF ComPDFKit
HTML 到 PDF 本地Chromium引擎 需要外部API
Bootstrap支持 完整的CSS3/Flexbox支持 有限的CSS框架支持
安装 单个 NuGet 软件包 需要多个软件包
文档 丰富的500多个例子 基础文档
支持 24/5专门工程支持 标准电子邮件支持
定价模式 永久许可证起价$749 基于报价的定价
跨平台 Windows、Linux、macOS、Docker、Azure Windows、Linux、macOS
性能 优化的异步/多线程 标准同步处理
企业特性 PDF/A、PDF/UA、HSM签名 基础PDF/A支持
学习曲线 最小 - 直观的API 适中 - 复杂的API结构
  1. PDF浏览:ComPDFKit提供了一个强大的PDF浏览器,可让用户以高保真度查看PDF文档。 查看器支持平滑滚动、缩放和导航,确保无缝的用户体验。
  2. 注释:库包含流畅集成PDF注释的工具。 用户可以突出显示文本、添加评论和创建各种类型的注释,这是协作工作流程所必需的。
  3. 表单处理:库提供广泛的交互式表单支持。 开发人员可以创建、填写和从PDF表单中提取数据,该功能非常适合需要表单处理的应用程序。
  4. PDF编辑:ComPDFKit允许对PDF进行广泛的编辑功能,包含修改文本、图像和PDF文件中的其他内容。 此功能对需要更新或自定义现有PDF文档的应用程序非常有用。
  5. 转换:库支持将PDF文件转换为多种格式的文件,如Word、Excel、PPT和图像。 这种灵活性对于需要为不同用途转换PDF内容的应用程序至关重要。
  6. 安全:ComPDFKit包含强大的安全特性,如加密和权限管理。 开发人员能够保护PDF文档,防止敏感信息被未经授权访问。
  7. 光学字符识别(OCR):库具备OCR功能,可将扫描的文档转换为可编辑和搜索的PDF。 此功能对于将纸质文档数字化并使其可以电子方式访问是必不可少的。

ComPDFKit主页展示其完整的PDF SDK解决方案,为开发者提供注释功能的截图和展示PDF操作能力的代码示例。

ComPDFKit PDF SDK是一个可靠的C# PDF SDK,允许开发者将完整的PDF功能集成到他们的应用程序中。 该库支持处理PDF文件所需的多种PDF功能。 它被设计用于多种环境,包括网络、桌面和移动平台,使其成为开发跨平台项目的开发人员的多功能工具。 示例解决方案包含多个函数,开发者可以进行选择和测试。

ComPDFKit提供了哪些关键特性?

核心能力:

  • PDF浏览:提供一个高效的浏览器,支持平滑滚动、缩放和导航功能
  • 注释:包含突出显示文本、添加评论和创建各种注释类型的工具
  • 表单处理:支持创建、填充和从交互式PDF表单中提取数据
  • PDF编辑:允许修改现有PDF文件中的文本、图像和其他内容
  • 转换:支持将PDF文件转换为Word、Excel、PowerPoint及图像格式
  • 安全:包含加密和权限管理,保护敏感信息
  • 光学字符识别(OCR):将扫描的文档转换为可编辑和搜索的PDF

为何考虑ComPDFKit的架构?

  1. HTML到PDF转换:IronPDF在将HTML、CSS和JavaScript内容转换为高质量PDF文档方面表现出色。 此功能支持将HTML字符串转换为PDF,URL,ASPX webforms和MVC视图,使其成为适用于各种基于网络的内容的灵活解决方案。
  2. PDF编辑:库提供了广泛的编辑功能,包括添加、复制和删除页面,合并和拆分PDF,以及操作文本和图像。 开发人员还可以向PDF文档添加页眉,页脚,水印和数字签名。
  3. 表单处理:IronPDF支持智能表单创建,并可以编程方式填充PDF表单。 此功能对于需要动态表单生成和从用户提交表单中提取数据的应用程序来说是至关重要的。
  4. 安全特征:IronPDF提供强大的安全选项,例如设置密码和权限、加密文档和添加数字签名。 这些功能确保PDF文档中的敏感信息得到保护免受未经授权的访问。
  5. OCR和数据提取:库包含光学字符识别(OCR)功能,允许将扫描的文档转换为可编辑和搜索的PDF。 此外,IronPDF可以从现有的PDF中提取文本、图像和其他数据,方便内容重用和分析。
  6. 图像转换:IronPDF支持将各种图像格式,包括JPG、PNG、GIF、BMP和SVG,转换为PDF文档。 它还提供将PDF页面呈现为图像的功能,这对于需要PDF内容的视觉预览的应用程序非常有用。
  7. 跨平台兼容性:IronPDF兼容多个.NET平台,包括.NET Core、.NET Framework和.NET Standard。 它支持在Windows、Linux、macOS和Azure上部署,使其成为在各种不同环境中工作的开发人员的多功能选择。
  8. 性能优化:库设计为高性能,支持多线程和异步操作。 这确保即使在高负载应用中,PDF处理任务也能高效执行。
  9. 全面的文档和支持:IronPDF提供详细的文档和大量的代码示例,方便开发者快速上手并实现其功能。 此外,它提供技术支持以帮助解决开发过程中可能出现的任何问题。

对于需要可靠注释功能的企业应用程序,ComPDFKit提供了基本功能。 先进的表单创建能力可能需要额外的编程工作。 尽管在OCR任务中功能正常,希望获得高级文本识别的开发者应考虑像IronOCR这样精度更高的替代方案。

ComPDFKit的局限性是什么?

尽管具有完整的功能集,ComPDFKit在企业开发方面存在一些局限性:

  • HTML渲染:没有本地HTML到PDF的转换 - 需要外部API调用
  • CSS支持:现代CSS框架兼容性有限
  • 性能:缺少内置的异步/多线程优化
  • 文档:基础示例,没有完整的故障排除指南
  • 集成复杂性:完整功能需要多个包

什么是IronPDF库?

IronPDF主页展示C# PDF库接口,含HTML到PDF转换的代码示例,突出展示1000多万次下载量及福布斯500强企业的采用。

IronPDF 是一个用于.NET的多功能PDF库,允许开发人员使用C#创建、编辑和管理PDF文档。 它通过简化的API提供完整的PDF功能。库通过从HTML、CSS、JavaScript以及各种图像格式渲染PDF,擅长于PDF生成。 这使它成为开发者在.NET应用程序中集成可靠PDF功能的理想工具。

IronPDF提供了哪些关键特性?

高级功能:

为何选择IronPDF用于生产系统?

IronPDF的架构优先考虑生产环境中的性能和可靠性:

IronPDF为何已准备好企业使用?

IronPDF通过针对生产的特性脱颖而出:

如何创建一个新的Visual Studio项目?

在探索代码示例之前,开发者应创建新的Visual Studio项目。 此指南概述了在Visual Studio中设置一个C#控制台应用程序。

为何需要安装Visual Studio?

Visual Studio提供改进的C#项目IDE。 请从Visual Studio下载页面下载。 IDE提供集成调试、IntelliSense和包管理,是PDF开发必不可少的。

什么项目配置最佳?

安装后,打开Visual Studio。 使用Visual Studio Community时,可登录也可不登录。 请按以下配置步骤进行:

  1. 单击"创建新项目"或导航到文件>新建>项目。

Visual Studio IDE显示文件菜单打开状态,具有创建新项目、打开文件和管理存储库的选项,突出显示的新建项目选项。

  1. 搜索控制台应用程序,并从搜索结果中选择控制台应用程序。

Visual Studio的创建新项目对话框显示控制台应用程序模板选择,带有C#、Linux、macOS、Windows和Console标签,突出显示交叉平台开发。

  1. 打开NuGet包管理器:在解决方案资源管理器中,右键单击"引用"并选择"管理NuGet包"。
  2. 搜索和安装:在NuGet包管理器中搜索"ComPDFKit"。 选择适当的包(例如, ComPDFKit.NetFrameworkComPDFKit.Conversion.NetFramework)然后点击"安装"。

什么是必要的项目设置?

  1. 验证安装:确保包出现在解决方案资源管理器的"引用"下。
  • 平台目标:设置为x64处理大文档
  • 输出类型:控制台应用程序用于测试,类库用于生产
  • 框架版本:.NET 6+推荐,以获得最佳性能
  • NuGet包管理:为依赖管理启用包还原
  1. 下载包:从ComPDFKit官网获取ComPDFKit.NetFramework.nupkg文件。
  2. 配置NuGet源:在项目目录中创建或编辑nuget.config文件,包括本地包的路径。

将IronPDF集成到项目中可以通过多种方法实现。 有关完整的安装概述,请参见官方文档。 该库支持多种安装方法,以满足不同的开发工作流程。

  1. 安装本地包:重新打开Visual Studio中的解决方案,进入"管理NuGet包",并选择本地包源。 从本地源安装ComPDFKit包。

  2. Visual Studio NuGet包管理器:在解决方案中右键单击"依赖项",然后选择"管理NuGet包"。在"浏览"选项卡中搜索"IronPDF",并安装最新版本。 有关高级NuGet安装选项,请咨询详细指南。

  3. 获取许可证:联系ComPDFKit团队以获取试用或完整许可证。
  4. 在代码中应用许可证:

  5. 包管理器控制台:通过工具>NuGet包管理器>包管理器控制台使用NuGet包管理器控制台。 执行命令:

_CODEBLOCK0

通过命令行界面提供了快速的库安装。

包管理器控制台窗口显示在C#测试板项目中安装IronPdf NuGet包版本2024.5.2,并确认安装成功。

  1. 直接下载方法:访问IronPDF NuGet包页面。 下载包文件,双击将其添加到项目中,然后重新加载解决方案。

  2. 手动安装:下载最新的IronPDF版本。 遵循提供的说明进行手动Visual Studio集成。 有关Windows特定的安装方法,请参见Windows安装指南

为何选择特定的安装方式?

不同的安装方法适用于各种场景:

  • NuGet Package Manager:最佳适用于具有互联网访问权限的Visual Studio用户
  • Package Manager Console:适合脚本化部署和CI/CD流水线
  • 直接下载:适合离线开发环境
  • 手动安装:需要自定义部署配置

这些方法能有效地将IronPDF集成到.NET项目中。 如需快速启动说明,请访问入门指南。平台特定指南涵盖F#集成VB.NET使用

如何安装ComPDFKit C#?

添加ComPDFKit到项目中有两种主要方法:NuGet包管理器或本地包安装。 与IronPDF的单一包方法相比,安装过程需要更多步骤。

何时应使用NuGet包管理器?

  1. 打开NuGet包管理器:在解决方案资源管理器中右键单击"引用",并选择"管理NuGet包"。
  2. 搜索和安装:在包管理器中搜索"ComPDFKit"。 选择合适的包(ComPDFKit.NetFramework),然后单击"安装"。

NuGet包管理器接口显示ComPDFKit搜索结果,其中列出了三种包:ComPDFKit.NetFramework、ComPDFKit.Conversion.NetFramework和compdfkit-api-dotnet,以用于不同的用例。

  1. 验证安装:确保包在解决方案资源管理器中的"引用"下出现。 可能需要多个包以实现完整的功能。

何时应使用本地包?

本地包安装适合受限环境:

  1. 下载包:从ComPDFKit官网获取ComPDFKit.NetFramework.nupkg。
  2. 配置NuGet源:在项目目录中创建或编辑nuget.config,包含本地包路径。

_CODEBLOCK1

  1. 安装本地包:重新打开解决方案,导航到"管理NuGet包",选择本地包源,并安装ComPDFKit。

如何应用我的许可证密钥?

不同库的许可证实现有显著差异:

  1. 获取许可证:联系ComPDFKit以获取试用或完整许可证。
  2. 在代码中应用许可证:

_CODEBLOCK2

添加此方法以验证许可证。 有关IronPDF简单许可证实现的信息,请参见许可证密钥文档。 IronPDF只需设置License.LicenseKey属性,简化了许可证过程。

如何将HTML转换为PDF?

将HTML转换为PDF是从网络内容中生成报告、发票或文档的常见需求。 IronPDF和ComPDFKit都提供解决方案,尽管它们的方法差别很大。 IronPDF提供本地转换,而ComPDFKit需要外部API调用。

IronPDF如何处理HTML到PDF的转换?

IronPDF使用基于Chrome的渲染引擎以获得高质量输出。 此过程将HTML、CSS和JavaScript精确地渲染到PDF格式中。 库支持HTML字符串HTML文件URL

基本HTML字符串到PDF转换示例:

using IronPdf;
using System;

class Program
{
    static void Main()
    {
        // Define your HTML string
        string htmlString = @"
            <h1>Hello, IronPDF!</h1>
            <p>This is a simple PDF created from an HTML string.</p>";

        var renderer = new ChromePdfRenderer();
        // Convert the HTML string to a PDF document
        PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlString);
        // Save the PDF document to a file
        string outputPath = "sample.pdf";
        pdf.SaveAs(outputPath);
        Console.WriteLine($"PDF created successfully and saved to {outputPath}");
    }
}
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        // Define your HTML string
        string htmlString = @"
            <h1>Hello, IronPDF!</h1>
            <p>This is a simple PDF created from an HTML string.</p>";

        var renderer = new ChromePdfRenderer();
        // Convert the HTML string to a PDF document
        PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlString);
        // Save the PDF document to a file
        string outputPath = "sample.pdf";
        pdf.SaveAs(outputPath);
        Console.WriteLine($"PDF created successfully and saved to {outputPath}");
    }
}
$vbLabelText   $csharpLabel

IronPDF输出展示了一个简单PDF,包含

IronPDF还直接转换HTML文件,支持CSS和JavaScript的包含:

using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        // Convert the HTML file to a PDF document
        PdfDocument pdf = renderer.RenderHtmlFileAsPdf("index.html");
        // Save the PDF document to a file
        string outputPath = "HTML File.pdf";
        pdf.SaveAs(outputPath);
        Console.WriteLine($"PDF created successfully and saved to {outputPath}");
    }
}
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        // Convert the HTML file to a PDF document
        PdfDocument pdf = renderer.RenderHtmlFileAsPdf("index.html");
        // Save the PDF document to a file
        string outputPath = "HTML File.pdf";
        pdf.SaveAs(outputPath);
        Console.WriteLine($"PDF created successfully and saved to {outputPath}");
    }
}
$vbLabelText   $csharpLabel

Sample invoice #123 showing website design services totaling $385, rendered as a PDF document with professional formatting and layout preserved from HTML source.

IronPDF支持哪些高级HTML功能?

IronPDF的Chromium引擎处理复杂的网络技术:

ComPDFKit如何处理HTML到PDF的转换?

  1. 发送HTML内容:创建到ComPDFKit API端点的HTTP POST请求,附带HTML内容。
  2. 接收PDF输出:API处理HTML内容并返回生成的PDF文件。

要使用ComPDFKit的HTML到PDF API:

  1. 发送HTML内容:创建HTTP POST请求,附带HTML内容
  2. 接收PDF输出:API处理内容并返回生成的PDF

C#中的API请求示例结构:

using System;
using System.Net.Http;
using System.Threading.Tasks;

public class HtmlToPdfExample
{
    public static async Task ConvertHtmlToPdfAsync()
    {
        using (var client = new HttpClient())
        {
            var content = new StringContent("<h1>Hello World</h1>");
            var response = await client.PostAsync("___PROTECTED_URL_137___", content);
            var pdfBytes = await response.Content.ReadAsByteArrayAsync();
            System.IO.File.WriteAllBytes("output.pdf", pdfBytes);
        }
    }
}
using System;
using System.Net.Http;
using System.Threading.Tasks;

public class HtmlToPdfExample
{
    public static async Task ConvertHtmlToPdfAsync()
    {
        using (var client = new HttpClient())
        {
            var content = new StringContent("<h1>Hello World</h1>");
            var response = await client.PostAsync("___PROTECTED_URL_137___", content);
            var pdfBytes = await response.Content.ReadAsByteArrayAsync();
            System.IO.File.WriteAllBytes("output.pdf", pdfBytes);
        }
    }
}
$vbLabelText   $csharpLabel

API转换的局限性是什么?

ComPDFKit的API方法带来了几个挑战:

  • 网络依赖性:需联网完成基本操作
  • 延迟问题:API往返增加了处理时间
  • 控制有限:无法自定义渲染引擎行为
  • 安全问题:敏感数据上传到外部服务器
  • 速率限制:API配额可能会限制高容量处理
  • 文档缺乏:C#实施示例有限

Bootstrap CSS与PDF生成兼容吗?

现代电商和商业应用广泛使用Bootstrap以实现一致的UI设计。 生成发票、收据和报告为PDF时,保持Bootstrap样式确保品牌一致性。 IronPDF的Chromium引擎提供完整Bootstrap支持,而ComPDFKit的基于API的方法在复杂CSS框架上表现有限。

IronPDF如何处理Bootstrap样式?

IronPDF使用Chromium的渲染引擎,提供对所有版本(Bootstrap 5、4和3)的像素完美支持。 该库无缝支持 Flexbox 布局、CSS 网格、响应式工具和自定义组件。 有关高级CSS渲染的详细信息,请参见渲染选项指南

using IronPdf;

// Set license
IronPdf.License.LicenseKey = "License-Key";

var renderer = new ChromePdfRenderer();

// Bootstrap 5 e-commerce invoice example
string bootstrapInvoice = @"
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link href='___PROTECTED_URL_138___ rel='stylesheet'>
    <style>
        @page { margin: 20mm; }
        .invoice-header { border-bottom: 3px solid #0d6efd; }
        .product-row { border-bottom: 1px solid #dee2e6; }
        .total-section { background-color: #f8f9fa; }
    </style>
</head>
<body>
    <div class='container-fluid p-4'>

        <div class='row invoice-header pb-4 mb-4'>
            <div class='col-8'>
                <h1 class='display-4 text-primary'>INVOICE</h1>
                <p class='text-muted mb-0'>TechStore Inc.</p>
                <p class='text-muted mb-0'>123 Commerce Street, Tech City, TC 12345</p>
                <p class='text-muted'>Email: sales@techstore.com | Phone: (555) 123-4567</p>
            </div>
            <div class='col-4 text-end'>
                <p class='mb-1'><strong>Invoice #:</strong> INV-2024-1089</p>
                <p class='mb-1'><strong>Date:</strong> October 27, 2024</p>
                <p class='mb-1'><strong>Due Date:</strong> November 27, 2024</p>
                <span class='badge bg-success'>PAID</span>
            </div>
        </div>

        <div class='row mb-4'>
            <div class='col-6'>
                <h5 class='text-primary'>Bill To:</h5>
                <p class='mb-1'><strong>Acme Corporation</strong></p>
                <p class='mb-1'>456 Business Ave</p>
                <p class='mb-1'>Enterprise City, EC 67890</p>
                <p class='mb-0'>contact@acmecorp.com</p>
            </div>
            <div class='col-6 text-end'>
                <h5 class='text-primary'>Payment Method:</h5>
                <p class='mb-1'>Credit Card ending in 4242</p>
                <p class='mb-0'>Transaction ID: TXN-9876543210</p>
            </div>
        </div>

        <div class='row mb-4'>
            <div class='col-12'>
                <table class='table'>
                    <thead class='table-primary'>
                        <tr>
                            <th scope='col'>#</th>
                            <th scope='col'>Product</th>
                            <th scope='col'>Description</th>
                            <th scope='col' class='text-center'>Qty</th>
                            <th scope='col' class='text-end'>Unit Price</th>
                            <th scope='col' class='text-end'>Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class='product-row'>
                            <td>1</td>
                            <td><strong>IronPDF Pro License</strong></td>
                            <td>Professional developer license with 1 year support</td>
                            <td class='text-center'>1</td>
                            <td class='text-end'>$2,999.00</td>
                            <td class='text-end'><strong>$2,999.00</strong></td>
                        </tr>
                        <tr class='product-row'>
                            <td>2</td>
                            <td><strong>Priority Support</strong></td>
                            <td>24/7 priority technical support package</td>
                            <td class='text-center'>1</td>
                            <td class='text-end'>$999.00</td>
                            <td class='text-end'><strong>$999.00</strong></td>
                        </tr>
                        <tr class='product-row'>
                            <td>3</td>
                            <td><strong>Training Package</strong></td>
                            <td>On-site developer training (2 days)</td>
                            <td class='text-center'>1</td>
                            <td class='text-end'>$1,500.00</td>
                            <td class='text-end'><strong>$1,500.00</strong></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <div class='row justify-content-end mb-4'>
            <div class='col-md-6'>
                <div class='card total-section'>
                    <div class='card-body'>
                        <div class='row mb-2'>
                            <div class='col-6'><strong>Subtotal:</strong></div>
                            <div class='col-6 text-end'>$5,498.00</div>
                        </div>
                        <div class='row mb-2'>
                            <div class='col-6'><strong>Tax (8.5%):</strong></div>
                            <div class='col-6 text-end'>$467.33</div>
                        </div>
                        <div class='row mb-2'>
                            <div class='col-6 text-success'><strong>Discount (10%):</strong></div>
                            <div class='col-6 text-end text-success'>-$549.80</div>
                        </div>
                        <hr>
                        <div class='row'>
                            <div class='col-6'><h4 class='text-primary'>Total:</h4></div>
                            <div class='col-6 text-end'><h4 class='text-primary'>$5,415.53</h4></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class='row mb-4'>
            <div class='col-12'>
                <div class='alert alert-info' role='alert'>
                    <h6 class='alert-heading'>Payment Terms</h6>
                    <p class='mb-0'>Payment is due within 30 days. Late payments may incur a 1.5% monthly interest charge. Thank you for your business!</p>
                </div>
            </div>
        </div>

        <div class='row border-top pt-3'>
            <div class='col-12 text-center text-muted'>
                <small>TechStore Inc. | Tax ID: 12-3456789 | All prices in USD</small>
            </div>
        </div>
    </div>
</body>
</html>";

// Render PDF with optimized settings
var pdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);

// Add metadata for document management
pdf.MetaData.Title = "Invoice INV-2024-1089";
pdf.MetaData.Author = "TechStore Inc.";
pdf.MetaData.Subject = "Sales Invoice";
pdf.MetaData.Keywords = "invoice, payment, e-commerce";

// Save the invoice
pdf.SaveAs("invoice-with-bootstrap.pdf");
using IronPdf;

// Set license
IronPdf.License.LicenseKey = "License-Key";

var renderer = new ChromePdfRenderer();

// Bootstrap 5 e-commerce invoice example
string bootstrapInvoice = @"
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link href='___PROTECTED_URL_138___ rel='stylesheet'>
    <style>
        @page { margin: 20mm; }
        .invoice-header { border-bottom: 3px solid #0d6efd; }
        .product-row { border-bottom: 1px solid #dee2e6; }
        .total-section { background-color: #f8f9fa; }
    </style>
</head>
<body>
    <div class='container-fluid p-4'>

        <div class='row invoice-header pb-4 mb-4'>
            <div class='col-8'>
                <h1 class='display-4 text-primary'>INVOICE</h1>
                <p class='text-muted mb-0'>TechStore Inc.</p>
                <p class='text-muted mb-0'>123 Commerce Street, Tech City, TC 12345</p>
                <p class='text-muted'>Email: sales@techstore.com | Phone: (555) 123-4567</p>
            </div>
            <div class='col-4 text-end'>
                <p class='mb-1'><strong>Invoice #:</strong> INV-2024-1089</p>
                <p class='mb-1'><strong>Date:</strong> October 27, 2024</p>
                <p class='mb-1'><strong>Due Date:</strong> November 27, 2024</p>
                <span class='badge bg-success'>PAID</span>
            </div>
        </div>

        <div class='row mb-4'>
            <div class='col-6'>
                <h5 class='text-primary'>Bill To:</h5>
                <p class='mb-1'><strong>Acme Corporation</strong></p>
                <p class='mb-1'>456 Business Ave</p>
                <p class='mb-1'>Enterprise City, EC 67890</p>
                <p class='mb-0'>contact@acmecorp.com</p>
            </div>
            <div class='col-6 text-end'>
                <h5 class='text-primary'>Payment Method:</h5>
                <p class='mb-1'>Credit Card ending in 4242</p>
                <p class='mb-0'>Transaction ID: TXN-9876543210</p>
            </div>
        </div>

        <div class='row mb-4'>
            <div class='col-12'>
                <table class='table'>
                    <thead class='table-primary'>
                        <tr>
                            <th scope='col'>#</th>
                            <th scope='col'>Product</th>
                            <th scope='col'>Description</th>
                            <th scope='col' class='text-center'>Qty</th>
                            <th scope='col' class='text-end'>Unit Price</th>
                            <th scope='col' class='text-end'>Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class='product-row'>
                            <td>1</td>
                            <td><strong>IronPDF Pro License</strong></td>
                            <td>Professional developer license with 1 year support</td>
                            <td class='text-center'>1</td>
                            <td class='text-end'>$2,999.00</td>
                            <td class='text-end'><strong>$2,999.00</strong></td>
                        </tr>
                        <tr class='product-row'>
                            <td>2</td>
                            <td><strong>Priority Support</strong></td>
                            <td>24/7 priority technical support package</td>
                            <td class='text-center'>1</td>
                            <td class='text-end'>$999.00</td>
                            <td class='text-end'><strong>$999.00</strong></td>
                        </tr>
                        <tr class='product-row'>
                            <td>3</td>
                            <td><strong>Training Package</strong></td>
                            <td>On-site developer training (2 days)</td>
                            <td class='text-center'>1</td>
                            <td class='text-end'>$1,500.00</td>
                            <td class='text-end'><strong>$1,500.00</strong></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <div class='row justify-content-end mb-4'>
            <div class='col-md-6'>
                <div class='card total-section'>
                    <div class='card-body'>
                        <div class='row mb-2'>
                            <div class='col-6'><strong>Subtotal:</strong></div>
                            <div class='col-6 text-end'>$5,498.00</div>
                        </div>
                        <div class='row mb-2'>
                            <div class='col-6'><strong>Tax (8.5%):</strong></div>
                            <div class='col-6 text-end'>$467.33</div>
                        </div>
                        <div class='row mb-2'>
                            <div class='col-6 text-success'><strong>Discount (10%):</strong></div>
                            <div class='col-6 text-end text-success'>-$549.80</div>
                        </div>
                        <hr>
                        <div class='row'>
                            <div class='col-6'><h4 class='text-primary'>Total:</h4></div>
                            <div class='col-6 text-end'><h4 class='text-primary'>$5,415.53</h4></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class='row mb-4'>
            <div class='col-12'>
                <div class='alert alert-info' role='alert'>
                    <h6 class='alert-heading'>Payment Terms</h6>
                    <p class='mb-0'>Payment is due within 30 days. Late payments may incur a 1.5% monthly interest charge. Thank you for your business!</p>
                </div>
            </div>
        </div>

        <div class='row border-top pt-3'>
            <div class='col-12 text-center text-muted'>
                <small>TechStore Inc. | Tax ID: 12-3456789 | All prices in USD</small>
            </div>
        </div>
    </div>
</body>
</html>";

// Render PDF with optimized settings
var pdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);

// Add metadata for document management
pdf.MetaData.Title = "Invoice INV-2024-1089";
pdf.MetaData.Author = "TechStore Inc.";
pdf.MetaData.Subject = "Sales Invoice";
pdf.MetaData.Keywords = "invoice, payment, e-commerce";

// Save the invoice
pdf.SaveAs("invoice-with-bootstrap.pdf");
$vbLabelText   $csharpLabel

展示的关键 Bootstrap 功能:

  • 网格系统:col-*类用于响应式布局结构
  • 排版:h5用于分级文本样式
  • 表格:table-hover用于结构化数据展示
  • 卡片:card-body用于有背景样式的总计部分
  • 徽章:badge bg-success用于支付状态指示
  • 警报:alert alert-info用于支付条件通知
  • 实用工具:pb-</em>间距工具
  • 自定义样式:与Bootstrap类结合实现特定设计的发票

IronPDF的Chromium引擎确保完美的Bootstrap组件渲染:

  • 网格系统col-*类用于响应式布局
  • 排版h5用于分级样式
  • 表格table-hover用于结构化数据
  • 卡片card-body用于样式化部分
  • 徽章badge bg-success用于状态指示
  • 警报alert alert-info用于通知
  • 实用工具text-center、间距工具
  • 自定义样式:与Bootstrap结合设计发票

对于网络字体和图标,IronPDF提供完整的自定义字体支持。 在解决Bootstrap布局问题时,请参阅Bootstrap Flex CSS排错。 有关viewport和缩放设置的详细信息,正确的配置确保响应式布局正确渲染。

ComPDFKit在Bootstrap方面的局限性是什么?

ComPDFKit 的 HTML 到 PDF 转换依赖于外部 API 调用而不是嵌入式渲染。 此方法处理基础Bootstrap样式,但引入了几个限制:

  • 网络依赖性:需要HTTP请求到外部服务
  • CSS框架支持:可能无法完全支持复杂的Flexbox或CSS网格布局
  • 渲染一致性:结果可随API服务实施而异
  • 自定义样式:对Bootstrap组件渲染的控制有限
  • 性能:网络延迟为文档生成增加了开销

对于需要可靠的 Bootstrap 渲染并对样式和布局有完全控制的应用程序,原生 Chromium 渲染提供了更好的结果。 IronPDF的集成方法消除了外部依赖性,同时保持了完整的CSS框架兼容性。

如何为PDF添加水印?

为PDF添加水印有助于保护文档完整性、主张所有权并增强安全性。 水印可以是文本、徽标或图像,并出现在背景或前景。 它们可阻止未经授权的使用和分发,同时传达有关文档状态或创建者身份的重要信息。

如何使用IronPDF添加水印?

IronPDF提供简单的水印应用以编程方式添加到PDF文档。 此功能集成到库中,让开发者可以使用C#代码应用水印。 有关背景和前景位置,IronPDF提供灵活的位置选项。

using IronPdf;
using IronPdf.Editing;

class Program
{
    static void Main()
    {
        License.LicenseKey = "License-Code";

        string watermarkHtml = @"
            <img style='width: 500px;' src='C:\Users\Tayyab Ali\Desktop\watermark.png'>
            <h1>IronPDF Watermark</h1>";

        ChromePdfRenderer renderer = new ChromePdfRenderer();
        PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>It's a PDF with a watermark</h1>");
        // Apply watermark with 30 degrees rotation and 50% opacity
        pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 50);
        pdf.SaveAs("Confidential.pdf");
    }
}
using IronPdf;
using IronPdf.Editing;

class Program
{
    static void Main()
    {
        License.LicenseKey = "License-Code";

        string watermarkHtml = @"
            <img style='width: 500px;' src='C:\Users\Tayyab Ali\Desktop\watermark.png'>
            <h1>IronPDF Watermark</h1>";

        ChromePdfRenderer renderer = new ChromePdfRenderer();
        PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>It's a PDF with a watermark</h1>");
        // Apply watermark with 30 degrees rotation and 50% opacity
        pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 50);
        pdf.SaveAs("Confidential.pdf");
    }
}
$vbLabelText   $csharpLabel

PDF页面显示红色

此示例使用ChromePdfRenderer从HTML创建PDF。 ApplyWatermark方法应用包含图像和标题的水印。 旋转设为30度,50%不透明度,确保可见性而不覆盖内容。 生成的PDF保存到指定路径。

有哪些高级水印选项?

IronPDF提供完整的水印功能:

  • 基于HTML的水印: 使用完整HTML/CSS进行复杂设计
  • 定位控制: 3x3网格布局系统
  • 透明度设置: 细调透明度级别
  • 旋转选项: 应用任意角度以用于对角水印
  • 页面选择: 应用于所有页面或特定范围
  • 多个水印: 根据需要分层不同的水印

有关高级技术,请参阅文本和图像盖章高效添加多个盖章新内容盖章指南展示了动态水印生成。

如何使用ComPDFKit添加水印?

ComPDFKit提供了使用库方法以编程方式添加水印的功能。 该代码示例演示了如何添加文本水印:

static private bool AddTextWatermark(CPDFDocument document)
{
    CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
    watermark.SetText("test");
    watermark.SetFontName("Helvetica"); 
    watermark.SetPages("0-3");
    byte[] color = { 255, 0, 0 };
    watermark.SetTextRGBColor(color);
    watermark.SetScale(2);
    watermark.SetRotation(0);
    watermark.SetOpacity(120);
    watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER);
    watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER);
    watermark.SetVertOffset(0);
    watermark.SetHorizOffset(0);
    watermark.SetFront(true);
    watermark.SetFullScreen(true);
    watermark.SetVerticalSpacing(10);
    watermark.SetHorizontalSpacing(10);
    watermark.CreateWatermark();
    string path = "AddTextWatermarkTest.pdf";
    if (!document.WriteToFilePath(path))
    {
        return false;
    }
    Console.WriteLine("Browse the changed file in " + path);
    return true;
}

CPDFDocument document = CPDFDocument.InitWithFilePath("SamplePDF.pdf");
if (AddTextWatermark(document))
{
    Console.WriteLine("Add text watermark done.");
}
else
{
    Console.WriteLine("Add text watermark failed.");
}
static private bool AddTextWatermark(CPDFDocument document)
{
    CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
    watermark.SetText("test");
    watermark.SetFontName("Helvetica"); 
    watermark.SetPages("0-3");
    byte[] color = { 255, 0, 0 };
    watermark.SetTextRGBColor(color);
    watermark.SetScale(2);
    watermark.SetRotation(0);
    watermark.SetOpacity(120);
    watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER);
    watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER);
    watermark.SetVertOffset(0);
    watermark.SetHorizOffset(0);
    watermark.SetFront(true);
    watermark.SetFullScreen(true);
    watermark.SetVerticalSpacing(10);
    watermark.SetHorizontalSpacing(10);
    watermark.CreateWatermark();
    string path = "AddTextWatermarkTest.pdf";
    if (!document.WriteToFilePath(path))
    {
        return false;
    }
    Console.WriteLine("Browse the changed file in " + path);
    return true;
}

CPDFDocument document = CPDFDocument.InitWithFilePath("SamplePDF.pdf");
if (AddTextWatermark(document))
{
    Console.WriteLine("Add text watermark done.");
}
else
{
    Console.WriteLine("Add text watermark failed.");
}
$vbLabelText   $csharpLabel

PDF页面,带有红色'测试'水印文本和ComPDFKit徽标,中心显示ComPDFKit的水印输出。

此示例使用CPDFDocument打开一个现有PDF。 AddTextWatermark方法初始化一个文本水印,设置文字内容、字体、颜色、缩放、旋转、不透明度、对齐和间距等属性。 水印应用于指定页面并保存到定义路径。 对于图像水印,需要不同的方法,增加了实现的复杂性。

如何创建符合PDF/A标准的文档?

PDF/A是一种为长期数字保存而设计的标准化PDF版本。 确保PDF/A的合规性可以保证未来的可靠查看及复制。 本节探讨使用这两个库创建符合PDF/A标准的文档。

IronPDF如何创建PDF/A文档?

IronPDF简化了标准PDF到PDF/A合规格式的转换。 该库支持多种PDF/A标准,包括PDF/A-1、PDF/A-2和PDF/A-3。有关PDF/A里程碑更新支持ZUGFeRD的PDF/A-3的信息,请参阅产品公告。

using IronPdf;
using System;

class Program
{
    static void Main()
    {
        License.LicenseKey = "License-Key";
        PdfDocument pdf = PdfDocument.FromFile("Source.pdf");
        pdf.SaveAsPdfA("pdfa-compliant.pdf", PdfAVersions.PdfA3);
    }
}
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        License.LicenseKey = "License-Key";
        PdfDocument pdf = PdfDocument.FromFile("Source.pdf");
        pdf.SaveAsPdfA("pdfa-compliant.pdf", PdfAVersions.PdfA3);
    }
}
$vbLabelText   $csharpLabel

该过程包括:

  1. 初始化IronPDF:首先导入IronPDF库并设置您的许可证密钥。
  2. 加载PDF:使用PdfDocument.FromFile加载您来源的PDF文件。
  3. 转换并保存:通过指定所需的PDF/A版本并保存生成的文档来将加载的PDF转换为PDF/A。

为什么选择PDF/A用于文档归档?

PDF/A对于长期保存提供了多种优势:

  • 自包含文档: 所有字体和资源均嵌入
  • 无外部依赖: 消除对外部内容的依赖
  • 标准化格式: 为归档目的ISO认证
  • 元数据保存: 保持文档属性
  • 视觉可复现性: 确保长期外观一致

IronPDF还支持PDF/UA格式以满足无障碍标准,确保文档符合508节合规标准。

ComPDFKit如何创建PDF/A文档?

ComPDFKit通过文档初始化、输出路径定义和转换方法调用提供可靠的PDF/A转换。

static public bool CovertToPDFA1a(CPDFDocument document)
{
    string convertToPDFA1aPath = "ConvertToPDFA1aTest.pdf";
    if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath))
    {
        return false;
    }
    Console.WriteLine("Browse the changed file in " + convertToPDFA1aPath);
    return true;
}

CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
if (CovertToPDFA1a(document))
{
    Console.WriteLine("Convert to PDF/A-1a done.");
}
else
{
    Console.WriteLine("Convert to PDF/A-1a failed.");
}
static public bool CovertToPDFA1a(CPDFDocument document)
{
    string convertToPDFA1aPath = "ConvertToPDFA1aTest.pdf";
    if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath))
    {
        return false;
    }
    Console.WriteLine("Browse the changed file in " + convertToPDFA1aPath);
    return true;
}

CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
if (CovertToPDFA1a(document))
{
    Console.WriteLine("Convert to PDF/A-1a done.");
}
else
{
    Console.WriteLine("Convert to PDF/A-1a failed.");
}
$vbLabelText   $csharpLabel

步骤包括:

  1. 初始化文档:使用CPDFDocument.InitWithFilePath加载PDF文档。
  2. 设置输出目录:确保输出目录存在或必要时创建。
  3. 转换为PDF/A:使用指定的PDF/A类型的WritePDFAToFilePath进行转换并保存文件。

如何为PDF添加数字签名?

数字签名验证文档的真实性和完整性。 本节展示了使用这两个库添加数字签名。 欲了解完整数字签名实现,IronPDF提供了详尽的文档。

如何使用IronPDF签署PDF?

IronPDF提供简便且有效的数字签名应用。 该库支持X.509证书和HSM集成以满足企业安全需求。

using IronPdf;
using IronPdf.Signing;

class Program
{
    static void Main(string[] args)
    {
        var simpleSignature = new PdfSignature("MyCert.p12", "newpassword");
        simpleSignature.SignPdfFile("sample.pdf");
    }
}
using IronPdf;
using IronPdf.Signing;

class Program
{
    static void Main(string[] args)
    {
        var simpleSignature = new PdfSignature("MyCert.p12", "newpassword");
        simpleSignature.SignPdfFile("sample.pdf");
    }
}
$vbLabelText   $csharpLabel

该过程包括:

  1. 初始化IronPDF:导入必要的IronPDF库。
  2. 创建签名:使用证书文件和密码初始化PdfSignature对象。
  3. 签署PDF:使用SignPdfFile将签名应用于PDF。

IronPDF提供了哪些高级签名选项?

IronPDF提供完整的数字签名功能:

  • 多种签名类型: 基于证书、可视和表单字段签名
  • HSM支持: 硬件安全模块集成
  • 时间戳服务器: 为签名添加可信时间戳
  • 签名外观: 自定义视觉签名表示
  • 验证支持: 以编程方式验证现有签名
  • 修订控制: 维护签名修订历史

有关签名问题的故障排除,请参阅数字签名故障排除指南

如何使用ComPDFKit签署PDF?

ComPDFKit提供完整的数字签名创建,并具有广泛的自定义选项。

private static void CreateDigitalSignature(CPDFDocument document, string certificatePath, string password)
{
    Console.WriteLine("--------------------");
    Console.WriteLine("Create digital signature.");
    CPDFSignatureCertificate certificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path("Certificate.pfx", "ComPDFKit");
    CPDFPage page = document.PageAtIndex(0);
    CPDFSignatureWidget signatureField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
    signatureField.SetRect(new CRect(28, 420, 150, 370));
    signatureField.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
    signatureField.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
    signatureField.UpdateAp();
    string name = GetGrantorFromDictionary(certificate.SubjectDict) + "\n";
    string date = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
    string reason = "I am the owner of the document.";
    string location = certificate.SubjectDict["C"];
    string DN = certificate.Subject;

    CPDFSignatureConfig signatureConfig = new CPDFSignatureConfig
    {
        Text = GetGrantorFromDictionary(certificate.SubjectDict),
        Content =
            "Name: " + name + "\n" +
            "Date: " + date + "\n" +
            "Reason: " + reason + " \n" +
            "Location: " + location + "\n" +
            "DN: " + DN + "\n",
        IsContentAlignLeft = false,
        IsDrawLogo = true,
        LogoBitmap = new Bitmap("Logo.png"),
        TextColor = new float[] { 0, 0, 0 },
        ContentColor = new float[] { 0, 0, 0 }
    };
    string filePath = document.FileName + "_Signed.pdf";
    signatureField.UpdataApWithSignature(signatureConfig);
    if (document.WriteSignatureToFilePath(signatureField,
        filePath,
        certificatePath, password,
        location,
        reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone))
    {
        Console.WriteLine("File saved in " + filePath);
        Console.WriteLine("Create digital signature done.");
    }
    else
    {
        Console.WriteLine("Create digital signature failed.");
    }
    Console.WriteLine("--------------------");
}
private static void CreateDigitalSignature(CPDFDocument document, string certificatePath, string password)
{
    Console.WriteLine("--------------------");
    Console.WriteLine("Create digital signature.");
    CPDFSignatureCertificate certificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path("Certificate.pfx", "ComPDFKit");
    CPDFPage page = document.PageAtIndex(0);
    CPDFSignatureWidget signatureField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
    signatureField.SetRect(new CRect(28, 420, 150, 370));
    signatureField.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
    signatureField.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
    signatureField.UpdateAp();
    string name = GetGrantorFromDictionary(certificate.SubjectDict) + "\n";
    string date = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
    string reason = "I am the owner of the document.";
    string location = certificate.SubjectDict["C"];
    string DN = certificate.Subject;

    CPDFSignatureConfig signatureConfig = new CPDFSignatureConfig
    {
        Text = GetGrantorFromDictionary(certificate.SubjectDict),
        Content =
            "Name: " + name + "\n" +
            "Date: " + date + "\n" +
            "Reason: " + reason + " \n" +
            "Location: " + location + "\n" +
            "DN: " + DN + "\n",
        IsContentAlignLeft = false,
        IsDrawLogo = true,
        LogoBitmap = new Bitmap("Logo.png"),
        TextColor = new float[] { 0, 0, 0 },
        ContentColor = new float[] { 0, 0, 0 }
    };
    string filePath = document.FileName + "_Signed.pdf";
    signatureField.UpdataApWithSignature(signatureConfig);
    if (document.WriteSignatureToFilePath(signatureField,
        filePath,
        certificatePath, password,
        location,
        reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone))
    {
        Console.WriteLine("File saved in " + filePath);
        Console.WriteLine("Create digital signature done.");
    }
    else
    {
        Console.WriteLine("Create digital signature failed.");
    }
    Console.WriteLine("--------------------");
}
$vbLabelText   $csharpLabel

步骤包括:

  1. 初始化文档和证书:加载PDF文档并使用CPDFPKCS12CertHelper检索证书。
  2. 创建并配置签名字段:向PDF添加签名字段,设置其属性并配置签名详细信息。
  3. 应用签名:使用WriteSignatureToFilePath应用签名并保存签名后的PDF。

如何从 PDF 中提取文本?

从PDF文档中提取文本对数据处理和分析至关重要。 本节解释了使用这两个库的文本提取。

IronPDF如何提取文本?

IronPDF提供了从PDF文档中轻松提取文本的方法。 该库提供了提取所有文本或特定页面内容的方法。 对于解析PDF内容,IronPDF支持结构化的提取。 当访问PDF DOM对象时,开发人员可以检索详细的内容信息。

using IronPdf;
using System.IO;

PdfDocument pdf = PdfDocument.FromFile("PDF File With Text.pdf");
string text = pdf.ExtractAllText();
File.WriteAllText("PDF Text.txt", text);
using IronPdf;
using System.IO;

PdfDocument pdf = PdfDocument.FromFile("PDF File With Text.pdf");
string text = pdf.ExtractAllText();
File.WriteAllText("PDF Text.txt", text);
$vbLabelText   $csharpLabel

该过程包括:

  1. 初始化IronPDF:导入IronPDF库。
  2. 加载PDF:使用PdfDocument.FromFile加载PDF文件。
  3. 提取文本:调用ExtractAllText来检索PDF中的所有文本内容。
  4. 将文本保存到文件:使用标准文件I/O操作将提取的文本写入文件。

有哪些高级文本提取功能?

IronPDF提供了复杂的文本提取功能:

  • 页面特定提取: 从单个页面提取文本
  • 结构化内容: 访问具有格式信息的文本
  • 查找和替换: 在PDF中查找和替换文本
  • 正则表达式支持: 基于模式的文本提取
  • 基于坐标的提取: 从特定区域提取文本
  • 语言支持: 处理UTF-8和国际字符

要查看完整的文本读取示例,请参阅阅读PDF文本文档

ComPDFKit如何提取文本?

ComPDFKit提供从PDF文档中灵活提取文本的方法。

static private bool PDFToText(CPDFDocument document)
{
    string path = "//PDFToText.txt";
    if (!document.PdfToText("1-" + document.PageCount.ToString(), path))//Page ranges are counted from 1
    {
        return false;
    }
    Console.WriteLine("Browse the generated file in " + path);
    return true;
}

static void Main(string[] args)
{
    Console.WriteLine("Running PDFPage test sample…\r\n");
    SDKLicenseHelper.LicenseVerify();
    CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");

    if (PDFToText(document))
    {
        Console.WriteLine("PDF to text done.");
    }
    else
    {
        Console.WriteLine("PDF to text failed.");
    }
    Console.WriteLine("--------------------");
    Console.WriteLine("Done!");
    Console.WriteLine("--------------------");
    Console.ReadLine();
}
static private bool PDFToText(CPDFDocument document)
{
    string path = "//PDFToText.txt";
    if (!document.PdfToText("1-" + document.PageCount.ToString(), path))//Page ranges are counted from 1
    {
        return false;
    }
    Console.WriteLine("Browse the generated file in " + path);
    return true;
}

static void Main(string[] args)
{
    Console.WriteLine("Running PDFPage test sample…\r\n");
    SDKLicenseHelper.LicenseVerify();
    CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");

    if (PDFToText(document))
    {
        Console.WriteLine("PDF to text done.");
    }
    else
    {
        Console.WriteLine("PDF to text failed.");
    }
    Console.WriteLine("--------------------");
    Console.WriteLine("Done!");
    Console.WriteLine("--------------------");
    Console.ReadLine();
}
$vbLabelText   $csharpLabel

步骤如下

  1. 初始化文档:使用CPDFDocument.InitWithFilePath加载PDF文档。
  2. 提取并保存文本:使用PdfToText从指定的页面范围提取文本并将其保存到文件中。

真实世界用例场景

了解何时使用每个库有助于开发人员根据项目要求做出明智决策。 以下场景展示了每个库在哪些实用应用场景中表现出色。

什么时候应该选择IronPDF?

企业文档生成系统 一家金融服务公司需要生成50,000多个带有复杂布局、图表和法规合规性要求的月度报表。

IronPDF的优势:

SaaS发票生成平台 一个多租户SaaS平台,为数千名客户创建品牌发票,并提供定制模板。

IronPDF的优势:

  • HTML/CSS支持: 全方位Bootstrap兼容品牌模板
  • 性能: Docker部署提供可扩展的架构
  • 自定义: 页眉/页脚水印用于品牌化
  • API设计: 简化的API减少了开发时间
  • 云就绪: 原生AzureAWS支持

什么时候考虑使用ComPDFKit?

基本PDF查看器应用 一款桌面应用需要PDF查看和基本注释功能,而无需HTML转换。

ComPDFKit的优势:

  • 查看器组件: 内置查看功能
  • 注释工具: 原生注释支持
  • 简单集成: 无需HTML的直接PDF操作
  • 离线操作: 核心功能无网络依赖

文档归档系统 一个专注于PDF组织和基础编辑的内部文档管理系统。

ComPDFKit的优势:

  • 文件操作: 强大的PDF合并/拆分功能
  • 基本编辑: 文本和图像修改工具
  • 传统方法: 熟悉的以PDF为中心的API设计

有哪些许可选项?

IronPDF和ComPDFKit的许可模式在方法和使用条款上有所不同。 理解这些差异帮助开发人员选择适合项目需求和预算的工具。

IronPDF提供了哪些许可选项?

IronPDF pricing page showing three license tiers (Lite $749, Plus $1,499, Professional $2,999) with Professional selected, displaying 10 developers/locations/projects coverage and $4,998 total with extended support and upgrade protection.

IronPDF采用透明的商业许可模式:

许可证类型:

  • Lite License($749): 1个开发者,1个地点,1个项目
  • Plus License($1,499): 3个开发人员,3个地点,3个项目
  • Professional License($2,999): 10个开发者,10个地点,10个项目
  • Enterprise/OEM: 无限部署的定制定价

关键好处:

  • 永久许可证: 一次性支付终身使用
  • 免版税再分发: 无运行时费用
  • 源码可用: 可选购买用于安全审计
  • 灵活的升级: 许可扩展升级可用
  • 试用期: 免费试用许可证用于评估

IronPDF的商业模式确保企业获得专门的支持、完整的文档及用于专业PDF生成和操作的高级功能。 透明的定价结构消除了隐藏成本,并提供了预算可预测性。

ComPDFKit提供了哪些许可选项?

ComPDFKit采用灵活的许可证以满足不同的业务需求:

许可证选项:

  • 永久许可证: 一次性付款终身SDK访问
  • 订阅许可证: 定期付款,持续更新
  • 报价定价: 根据项目需求的定制定价

考虑因素:

  • 可变成本: 定价需要直接联系报价
  • 更新费用: 可选版本更新费用
  • 支持包: 需要单独的支持协议
  • API使用限制: HTML转换API附加费用

有哪些文档和支持可用?

IronPDF提供了哪些支持?

IronPDF提供文档和支持基础设施:

文档资源:

支持渠道:

  • 24/5 工程支持:直接访问开发团队
  • 响应时间: 优先支持,保证响应时间
  • 代码审查: 工程团队审查复杂实现
  • 定制解决方案: 独特需求协助
  • 定期更新: 产品更新里程碑功能

有关请求工程支持的详细指南确保高效解决。 支持基础设施包括各种平台的部署帮助

ComPDFKit提供了什么支持?

ComPDFKit提供基础文档和支持资源:

文档:

  • 入门指南: 基本设置说明
  • API参考: 标准方法文档
  • 示例代码: 核心功能的有限示例
  • 平台文档: 基本平台集成指南

支持选项:

  • 电子邮件支持: 标准办公时间响应
  • 技术协助: 基本故障排除帮助
  • 社群论坛: 用户主导的支持社群

虽然这两个库都提供文档和支持,但IronPDF提供了更完整的资源、更快的响应时间及适用于生产部署的直接工程支持。

性能和优化考虑事项

性能影响生产系统的可行性。 了解每个库的优化能力有助于架构师设计高效的解决方案。

IronPDF如何优化性能?

IronPDF提供大量性能优化功能

架构优势:

  • 原生Chrome引擎: 优化的C++渲染引擎
  • 内存管理: 高效处理大型文档
  • 线程安全: 为并发Web应用而建
  • 资源池化: 可重用的渲染实例

性能特点:

基准测试(50页文档生成):

  • 单线程:平均2.3秒
  • 多线程(8核):每份文件0.4秒
  • 内存用量:峰值180MB
  • 并发请求:100+同时渲染

ComPDFKit的性能特征是什么?

ComPDFKit提供标准性能以满足基础操作:

性能概况:

  • 同步处理: 传统阻塞操作
  • 内存使用: 复杂文档的高消耗
  • 并发性: 有限的同时操作支持
  • HTML转换: 网络延迟增加1-3秒

限制:

  • 无内置异步支持
  • 有限的线程文档
  • API调用引入网络开销
  • 资源管理需要手动实现

企业集成模式

生产系统需要特定的架构模式以实现可靠性和可扩展性。 了解集成方法有助于团队实施可靠的解决方案。

如何在微服务中实现IronPDF?

IronPDF支持现代架构模式:

容器化PDF服务:

// Dockerfile forIronPDFmicroservice
FROM mcr.microsoft.com/dotnet/aspnet:6.0
RUN apt-get update && apt-get install -y \
    libgdiplus \
    libc6-dev \
    libx11-6
COPY . /app
WORKDIR /app
ENTRYPOINT ["dotnet", "PdfService.dll"]
// Dockerfile forIronPDFmicroservice
FROM mcr.microsoft.com/dotnet/aspnet:6.0
RUN apt-get update && apt-get install -y \
    libgdiplus \
    libc6-dev \
    libx11-6
COPY . /app
WORKDIR /app
ENTRYPOINT ["dotnet", "PdfService.dll"]
$vbLabelText   $csharpLabel

可扩展API实现:

[ApiController]
[Route("api/[controller]")]
public class PdfController : ControllerBase
{
    private readonly ChromePdfRenderer _renderer;

    public PdfController()
    {
        _renderer = new ChromePdfRenderer();
        // Configure for production
        _renderer.RenderingOptions.EnableJavaScript = true;
        _renderer.RenderingOptions.RenderDelay = 500;
    }

    [HttpPost("generate")]
    public async Task<IActionResult> GeneratePdf([FromBody] PdfRequest request)
    {
        try
        {
            var pdf = await _renderer.RenderHtmlAsPdfAsync(request.Html);

            // Apply security if needed
            if (request.RequirePassword)
            {
                pdf.SecuritySettings.SetPassword(request.Password);
            }

            var stream = pdf.Stream;
            return File(stream, "application/pdf", request.FileName);
        }
        catch (Exception ex)
        {
            //完成error handling
            return StatusCode(500, new { error = ex.Message });
        }
    }
}
[ApiController]
[Route("api/[controller]")]
public class PdfController : ControllerBase
{
    private readonly ChromePdfRenderer _renderer;

    public PdfController()
    {
        _renderer = new ChromePdfRenderer();
        // Configure for production
        _renderer.RenderingOptions.EnableJavaScript = true;
        _renderer.RenderingOptions.RenderDelay = 500;
    }

    [HttpPost("generate")]
    public async Task<IActionResult> GeneratePdf([FromBody] PdfRequest request)
    {
        try
        {
            var pdf = await _renderer.RenderHtmlAsPdfAsync(request.Html);

            // Apply security if needed
            if (request.RequirePassword)
            {
                pdf.SecuritySettings.SetPassword(request.Password);
            }

            var stream = pdf.Stream;
            return File(stream, "application/pdf", request.FileName);
        }
        catch (Exception ex)
        {
            //完成error handling
            return StatusCode(500, new { error = ex.Message });
        }
    }
}
$vbLabelText   $csharpLabel

好处:

  • 水平扩展: 根据需要添加实例
  • 故障隔离: 服务故障不影响系统
  • 资源控制: 容器限制可防止资源耗尽
  • 部署灵活性: 可与Kubernetes、Docker Swarm配合使用

ComPDFKit企业集成怎样?

ComPDFKit需要传统的集成方法:

  • 单体设计: 库与应用紧密耦合
  • 有限扩展: 仅支持垂直扩展
  • 资源共享: 在多租户场景下可能产生冲突
  • API依赖性: 外部服务需求使架构复杂化

安全和合规功能

企业应用需要可靠的安全功能来满足法规合规和数据保护要求。

IronPDF如何处理安全性?

IronPDF提供完整的安全功能

加密选项:

  • AES 256位加密: 军用级别的安全性
  • 用户/所有者密码: 独立的访问级别
  • 权限控制: 细粒度的操作限制
  • 数字签名: 基于证书的认证
  • HSM支持: 硬件安全模块集成

合规功能:

实现示例:

// Secure document generation
var pdf = renderer.RenderHtmlAsPdf(htmlContent);

// Apply complete security
pdf.SecuritySettings.SetPassword("user123");
pdf.SecuritySettings.SetOwnerPassword("owner456");
pdf.SecuritySettings.MakePdfDocumentReadOnly();
pdf.SecuritySettings.SetPdfSecuritySettings(
    canPrint: true,
    canCopy: false,
    canModify: false
);

// Add digital signature
var signature = new PdfSignature("cert.pfx", "password");
pdf.SignWithSignature(signature);

// Ensure compliance
pdf.SaveAsPdfA("secure-compliant.pdf", PdfAVersions.PdfA3);
// Secure document generation
var pdf = renderer.RenderHtmlAsPdf(htmlContent);

// Apply complete security
pdf.SecuritySettings.SetPassword("user123");
pdf.SecuritySettings.SetOwnerPassword("owner456");
pdf.SecuritySettings.MakePdfDocumentReadOnly();
pdf.SecuritySettings.SetPdfSecuritySettings(
    canPrint: true,
    canCopy: false,
    canModify: false
);

// Add digital signature
var signature = new PdfSignature("cert.pfx", "password");
pdf.SignWithSignature(signature);

// Ensure compliance
pdf.SaveAsPdfA("secure-compliant.pdf", PdfAVersions.PdfA3);
$vbLabelText   $csharpLabel

ComPDFKit提供什么样的安全性?

ComPDFKit提供基础的安全功能:

  • 密码保护: 基本的用户/所有者密码
  • 加密: 标准PDF加密
  • 权限: 有限的权限设置
  • 数字签名: 基于证书的签名

然而,像HSM支持、清理和完整的合规性工具等高级功能需要额外的实现。

我应该选择哪个PDF库?

IronPDF与ComPDFKit的比较揭示了不同用例和需求的明显区别。

为什么IronPDF在企业应用中表现出色

对于需要以下功能的生产系统来说,IronPDF是更好选择:

技术卓越性:

  • 原生HTML渲染: Chromium引擎确保完美转换
  • 性能: 异步/多线程用于高数据量处理
  • 可靠性: 用于Web应用的线程安全架构
  • 集成: 简化的API缩短开发时间

商业价值:

  • 总拥有成本: 无隐藏费用的透明定价
  • 支持基础设施: 24/5工程支持最小化停机时间
  • 文档: 500+示例加速开发
  • 前瞻性: 定期更新和新功能

真实开发者反馈: "IronPDF变革了发票生成系统。 开发者每月处理100,000+份文档,无渲染问题。 Bootstrap支持节省了数周的开发时间。" - Fortune 500零售商的.NET高级架构师

"在评估多个库后,IronPDF的性能和支持使其成为明显的选择。异步功能将处理时间减少了75%。" - 金融服务的技术主管

什么情况下ComPDFKit可能足够

ComPDFKit在以下情况下可能足够:

  • 简单PDF查看: 基本桌面应用程序
  • 有限的范围: 无需HTML转换的项目
  • 预算限制: 当外部API成本可以接受时
  • 基本操作: 简单的合并/拆分需求

最终建议

对于构建以性能、可靠性和架构模式优先的生产系统的.NET高级开发人员,IronPDF提供了完整解决方案。 其技术能力、企业功能和优越的支持基础设施的结合确保成功的项目交付。

关键决策因素:

要求 IronPDF ComPDFKit 胜者
HTML 至 PDF 本地 Chromium 外部API IronPDF
表现 异步/多线程 同步 IronPDF
CSS 支持 完整Bootstrap/Flexbox 有限的 IronPDF
文档 500+示例 基本的 IronPDF
支持 24/5工程 仅邮件支持 IronPDF
企业功能 完成 有限的 IronPDF
总费用 透明 变量 IronPDF

IronPDF提供免费试用许可证以测试库及其功能。 IronPDF许可从$749开始。此外,Iron Software仅花费两种价格打包九个库,包括IronXLIronOCR以及IronPDF。

对于需要企业支持的专业PDF生成的团队,IronPDF提供了完整的解决方案。 其在Fortune 500公司的可靠记录、完整的功能集和致力于开发成功使其成为谨慎.NET应用程序的最佳选择。

请注意ComPDFKit是其各自所有者的注册商标。 本站与ComPDFKit没有任何关系、认可或赞助。 所有产品名称、徽标和品牌均为各自所有者的财产。 比较仅供参考,反映撰写时公开可用的信息。)}]

常见问题解答

如何在C#中将HTML转换为PDF?

您可以使用 IronPDF 的RenderHtmlAsPdf方法将 HTML 字符串转换为 PDF。此方法适用于将 HTML、CSS 和 JavaScript 转换为高质量的 PDF 文档。

使用 C# PDF 库的好处是什么?

像 IronPDF 和 ComPDFKit 这样的 C# PDF 库支持 PDF 创建、修改和文本/图像提取。它们支持如表单处理、数字签名和安全性等功能,提供不同平台上的灵活性。

我可以在 C# 中为PDF 添加安全性吗?

是的,使用 IronPDF,您可以通过设置密码、加密文档和添加数字签名来增强 PDF 的安全性,以保护敏感信息。

ComPDFKit 如何处理 PDF 编辑和转换?

ComPDFKit 提供强大的 PDF 编辑功能和转换为各种格式的功能,包括用于长期数字保存的 PDF/A,使其在跨平台项目中具有很强的适应性。

C# PDF 库有哪些授权选项可用?

IronPDF 提供永续授权的商业授权模式,而 ComPDFKit 提供永续和订阅两种授权选项,使其能够根据业务需求灵活选择。

使用这些库的开发者有哪些支持和资源可用?

IronPDF 提供全面的文档和响应迅速的客户支持,使其适用于企业级应用。ComPDFKit 同样提供详细的文档和技术支持。

在 HTML 到 PDF 转换方面,IronPDF 和 ComPDFKit 如何比较?

IronPDF 在 HTML 到 PDF 转换方面表现优秀,支持 HTML 字符串、URL、ASPX Web 表单和 MVC 视图,而 ComPDFKit 提供更广泛的 PDF 编辑和转换功能。

Curtis Chau
技术作家

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

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

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me