产品比较 IronPDF与EvoPdf:2025年哪个.NET PDF库提供更好的价值? Jacob Mellor 已更新:八月 5, 2025 Download IronPDF NuGet 下载 DLL 下载 Windows 安装程序 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article 当构建需要PDF功能的现代.NET应用程序时,选择合适的库可以显著影响您的开发速度、应用程序性能以及长期维护成本。 IronPDF和EvoPdf代表了在.NET生态系统中PDF生成和操作的两种不同的方法,各自具有独特的优势,能够满足不同的开发场景。 这个全面的比较在关键维度上对两个库进行了检查,包括渲染精确度、API设计、性能指标、平台兼容性以及总拥有成本。无论您是在构建高容量文档处理系统、为合规性实施数字签名,还是仅仅将HTML报告转换为PDF,了解这些区别将帮助您做出符合您的技术需求和预算限制的明智决策。 IronPDF和EvoPdf一览比较如何? 在深入进行详细比较之前,以下是这些库如何在.NET开发人员最关心的关键类别中进行比较的综合概述: class="product__comprehensive-comparison-table"> class="table-container"> class="table-number">产品比较概述 class="table-title">IronPDF和EvoPdf在.NET PDF生成中的比较 类别 功能/方面 IronPDF EvoPdf 主要优势 核心架构 设计哲学 简单至上,直观的API 功能丰富,传统的PDF方法 IronPDF: 更快的开发 API复杂性 简单方法如RenderHtmlAsPdf() 多类方法,更多设置 IronPDF: 代码量减少60% 学习曲线 通常1-2天 通常3-5天 IronPDF: 更快适应 平台支持 跨平台 原生支持,无需额外配置 需要平台特定的设置 IronPDF: 更简单的部署 .NET版本 .NET 10, 9, 8, 7, 6, 5, Core 3.1+, Framework 4.6.2+ .NET 8, 7, 6, 5, Standard 2.0+, Framework 4.0+ 两者: 支持现代框架 操作系统 Windows, Linux, macOS, Docker 原生 Windows, Linux, macOS, Azure IronPDF: 优化的Docker支持 HTML到PDF 渲染引擎 完整的Chrome V8引擎 定制的HTML渲染引擎 IronPDF: 超过98%的浏览器保真度 CSS3/HTML5支持 全面支持 良好支持(90%覆盖) IronPDF: 现代网页标准 JavaScript执行 完整的JavaScript支持,带等待 良好的JavaScript支持 IronPDF: 动态内容就绪 渲染速度 常见1.2-1.8秒(复杂页面) 常见0.8-1.2秒 EvoPdf: 对简单HTML更快 安全与加密 加密级别 AES-256,自定义处理器 AES-256标准 两者: 行业标准 权限选项 超过15种细粒度权限 8种标准权限 IronPDF: 更精细的控制 数字签名 集成的视觉签名 基础签名支持 IronPDF: 更简单的签名 内容操作 编辑方法 真实内容删除,一行API 无内置编辑 IronPDF: 准备就绪的合规性 水印 基于HTML/CSS,完整样式化 基于模板的水印 IronPDF: 丰富的水印 盖章 统一的盖章类 与水印功能相同 IronPDF: 专用工具 文件转换 从DOCX到PDF 内置DocxToPdfRenderer 需要Evo Word to PDF ($450)+) IronPDF: 无额外费用 开发者体验 代码示例 100+个现成的样例 50+个示例 IronPDF: 广泛的资源 文档 教程,操作指南,视频,API参考 API文档和示例 IronPDF: 多种学习路径 错误信息 描述性,可操作的 标准错误报告 IronPDF: 更好的调试 性能指标 大文档处理 每分钟1000页水印 每分钟700页水印 IronPDF: 快30% 线程支持 本地异步/等待优化 多线程支持 IronPDF: 更好的可扩展性 许可与定价 入门级别 Lite: 9(1开发者,1项目) 部署: 0(1服务器,1应用程序) EvoPdf: 更低的初始成本 团队许可证 Plus: ,499(3开发者,3项目) 公司: $1,200(无限开发者) EvoPdf: 更适合大团队 再分发 +,999免版税 包含在公司许可中 EvoPdf: 内置再分发 套装选项 Iron Suite: $1,498(9个产品) EVO PDF工具包: ,400 IronPDF: 包含更多产品 支持 包含支持 是的,5天24小时工程支持 是的,第一年标准支持 IronPDF: 直接的工程访问 最佳用途 使用场景 现代网络应用,复杂的PDF,合规性 简单的HTML到PDF,基础转换 视情况而定 class="table-note"> 注意。 EvoPdf为大团队提供了具有竞争力的定价,但缺乏一些高级功能,如编辑。IronPDF提供了更多功能齐全的内置文档转换支持。 了解IronPDF和EvoPdf:核心优势和理念 是什么让IronPDF在.NET PDF库市场中脱颖而出? IronPDF代表了一个以开发者生产力为核心设计的全面PDF解决方案。 在不牺牲功能的情况下,基于简单性构建,IronPDF使.NET开发人员能够使用直观的API创建、编辑和操纵PDF文档,这些API模拟了熟悉的网页开发模式。 该库的突出功能是其基于Chrome的渲染引擎,确保了像素级精确的HTML到PDF转换,并且支持最新的网页标准,包括CSS3、JavaScript框架和网页字体。 该库在需要高保真文档渲染、复杂PDF操作和企业级安全特性时表现出色。 Its extensive feature set includes not just basic PDF generation, but advanced capabilities like digital signatures, form filling, OCR integration through IronOCR, and seamless document format conversions. IronPDF的跨平台兼容性不仅局限于简单的框架支持,还提供了在Windows、Linux、macOS、Docker容器以及像Azure和AWS这样的云平台上的原生性能。 EvoPdf如何以不同的方式处理PDF生成? EvoPdf采用了更传统的方法来进行PDF操作,主要专注于HTML到PDF的转换,强调定制化和控制。 该库提供了开发人员对转换过程的细粒度控制,允许对渲染参数、页面布局和转换设置进行微调。 EvoPdf的架构围绕为标准网页到PDF转换场景提供可靠和一致的结果而构建。 EvoPdf在其轻量级的占用空间和处理简单HTML文档时的更快渲染速度方面尤其出色。 对于不含复杂JavaScript或CSS3特征的简单HTML页面,EvoPdf通常可以在0.8-1.2秒内完成转换,使其适合批处理简单文件的高容量处理。 该库还为ASP.NET环境中的服务器端渲染提供了良好的支持,并针对网页应用场景进行了优化。 库之间的跨平台能力比较如何? IronPDF的现代跨平台架构 IronPDF提供了无缝的跨平台兼容性,不仅仅是框架支持。 该库可在以下平台上原生运行: .NET版本支持: .NET 10, 9, 8, 7, 6, 5和Core 3.1+ .NET Standard 2.0+ .NET Framework 4.6.2+ 完全支持C#、VB.NET和F# 操作系统兼容性: Windows(x86, x64, ARM) Linux(Ubuntu, Debian, CentOS, Alpine) macOS(Intel和Apple Silicon) Docker容器,包含预配置的镜像 云平台集成: Azure App Service、Functions和VMs AWS Lambda和EC2 谷歌云平台 Kubernetes部署 使IronPDF与众不同的是其零配置的部署模型。 与许多需要额外依赖或运行时安装的PDF库不同,IronPDF将所有必要的组件包含在NuGet包中。 这种自包含的方法极大地减少了部署复杂性,并消除了常见的“在我的电脑上能用”问题。 EvoPdf的平台要求和限制 EvoPdf支持相似范围的.NET版本,但对于跨平台场景需要更为仔细的配置: .NET框架支持: .NET 8, 7, 6和5 .NET Standard 2.0+ .NET Framework 4.8.1, 4.7.2, 4.6.1和4.0+ 平台考虑: 主要优化针对Windows环境 Linux支持需额外配置 通过.NET Core支持macOS 云部署需要平台特定的调整 对于跨平台部署,EvoPdf用户常需要处理特定平台的依赖和配置,尤其是在Windows和Linux环境之间移动时。 这种额外的设置复杂性可能会影响开发时间线并增加维护负担。 哪种库为常见任务提供了更好的PDF功能? HTML到PDF转换:渲染质量和性能 两个库最基本的功能都是HTML到PDF的转换,但其方法和结果差异显著。 IronPDF HTML到PDF示例 using IronPdf; // Initialize the Chrome-based renderer with advanced options var renderer = new ChromePdfRenderer { // Configure rendering options for optimal quality RenderingOptions = new ChromePdfRenderOptions { // Set high-quality rendering at 300 DPI for print-ready PDFs DPI = 300, // Enable JavaScript execution with custom timeout EnableJavaScript = true, RenderDelay = 2000, // Wait 2 seconds for dynamic content // Configure page layout MarginTop = 20, MarginBottom = 20, MarginLeft = 15, MarginRight = 15, // Enable modern web features CssMediaType = PdfCssMediaType.Print, ViewPortWidth = 1920, // Optimize for web fonts and images CreatePdfFormsFromHtml = true, FitToPaperMode = FitToPaperModes.Automatic } }; // Convert complex HTML with CSS3 and JavaScript var htmlContent = @" <!DOCTYPE html> <html> <head> <link href='https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap' rel='stylesheet'> <style> body { font-family: 'Roboto', sans-serif; } .chart-container { width: 100%; height: 400px; } @media print { .no-print { display: none; } .page-break { page-break-after: always; } } </style> <script src='https://cdn.jsdelivr.net/npm/chart.js'></script> </head> <body> <h1>Dynamic Sales Report</h1> <div class='chart-container'> <canvas id='salesChart'></canvas> </div> <script> // Dynamic chart generation const ctx = document.getElementById('salesChart').getContext('2d'); new Chart(ctx, { type: 'line', data: { labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'], datasets: [{ label: 'Sales 2025', data: [65, 78, 90, 81, 96], borderColor: 'rgb(75, 192, 192)', tension: 0.4 }] } }); </script> </body> </html>"; // Generate PDF with full JavaScript chart rendering var pdf = renderer.RenderHtmlAsPdf(htmlContent); // Apply post-processing optimizations pdf.CompressImages(90); pdf.SaveAs("sales-report.pdf"); using IronPdf; // Initialize the Chrome-based renderer with advanced options var renderer = new ChromePdfRenderer { // Configure rendering options for optimal quality RenderingOptions = new ChromePdfRenderOptions { // Set high-quality rendering at 300 DPI for print-ready PDFs DPI = 300, // Enable JavaScript execution with custom timeout EnableJavaScript = true, RenderDelay = 2000, // Wait 2 seconds for dynamic content // Configure page layout MarginTop = 20, MarginBottom = 20, MarginLeft = 15, MarginRight = 15, // Enable modern web features CssMediaType = PdfCssMediaType.Print, ViewPortWidth = 1920, // Optimize for web fonts and images CreatePdfFormsFromHtml = true, FitToPaperMode = FitToPaperModes.Automatic } }; // Convert complex HTML with CSS3 and JavaScript var htmlContent = @" <!DOCTYPE html> <html> <head> <link href='https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap' rel='stylesheet'> <style> body { font-family: 'Roboto', sans-serif; } .chart-container { width: 100%; height: 400px; } @media print { .no-print { display: none; } .page-break { page-break-after: always; } } </style> <script src='https://cdn.jsdelivr.net/npm/chart.js'></script> </head> <body> <h1>Dynamic Sales Report</h1> <div class='chart-container'> <canvas id='salesChart'></canvas> </div> <script> // Dynamic chart generation const ctx = document.getElementById('salesChart').getContext('2d'); new Chart(ctx, { type: 'line', data: { labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'], datasets: [{ label: 'Sales 2025', data: [65, 78, 90, 81, 96], borderColor: 'rgb(75, 192, 192)', tension: 0.4 }] } }); </script> </body> </html>"; // Generate PDF with full JavaScript chart rendering var pdf = renderer.RenderHtmlAsPdf(htmlContent); // Apply post-processing optimizations pdf.CompressImages(90); pdf.SaveAs("sales-report.pdf"); Imports IronPdf ' Initialize the Chrome-based renderer with advanced options Private renderer = New ChromePdfRenderer With { .RenderingOptions = New ChromePdfRenderOptions With { .DPI = 300, .EnableJavaScript = True, .RenderDelay = 2000, .MarginTop = 20, .MarginBottom = 20, .MarginLeft = 15, .MarginRight = 15, .CssMediaType = PdfCssMediaType.Print, .ViewPortWidth = 1920, .CreatePdfFormsFromHtml = True, .FitToPaperMode = FitToPaperModes.Automatic } } ' Convert complex HTML with CSS3 and JavaScript Private htmlContent = " <!DOCTYPE html> <html> <head> <link href='https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap' rel='stylesheet'> <style> body { font-family: 'Roboto', sans-serif; } .chart-container { width: 100%; height: 400px; } @media print { .no-print { display: none; } .page-break { page-break-after: always; } } </style> <script src='https://cdn.jsdelivr.net/npm/chart.js'></script> </head> <body> <h1>Dynamic Sales Report</h1> <div class='chart-container'> <canvas id='salesChart'></canvas> </div> <script> // Dynamic chart generation const ctx = document.getElementById('salesChart').getContext('2d'); new Chart(ctx, { type: 'line', data: { labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'], datasets: [{ label: 'Sales 2025', data: [65, 78, 90, 81, 96], borderColor: 'rgb(75, 192, 192)', tension: 0.4 }] } }); </script> </body> </html>" ' Generate PDF with full JavaScript chart rendering Private pdf = renderer.RenderHtmlAsPdf(htmlContent) ' Apply post-processing optimizations pdf.CompressImages(90) pdf.SaveAs("sales-report.pdf") $vbLabelText $csharpLabel 这款IronPDF示例如下几个高级功能: Chrome V8 JavaScript引擎:完整执行Chart.js以渲染动态可视化 网页字体支持:自动下载和嵌入Google Fonts 响应性渲染:符合CSS媒体查询以优化打印 高DPI支持:以300 DPI生成适合打印的PDF 自动布局:智能适配内容到页面边界 EvoPdf HTML到PDF示例 using EvoPdf; // Create converter with configuration HtmlToPdfConverter converter = new HtmlToPdfConverter(); // Set license key (required for production use) converter.LicenseKey = "your-license-key"; // Configure conversion settings converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; converter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait; converter.PdfDocumentOptions.TopMargin = 20; converter.PdfDocumentOptions.BottomMargin = 20; converter.PdfDocumentOptions.LeftMargin = 15; converter.PdfDocumentOptions.RightMargin = 15; // Enable JavaScript execution converter.JavaScriptEnabled = true; converter.ConversionDelay = 2; // seconds // Set authentication if needed converter.AuthenticationOptions.Username = "username"; converter.AuthenticationOptions.Password = "password"; // Convert HTML string string htmlString = @" <html> <head> <style> body { font-family: Arial, sans-serif; } table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid #ddd; padding: 8px; } </style> </head> <body> <h1>Invoice</h1> <table> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> </tr> <tr> <td>Product A</td> <td>5</td> <td>$50.00</td> </tr> </table> </body> </html>"; // Perform conversion byte[] pdfBytes = converter.ConvertHtml(htmlString, ""); // Save to file System.IO.File.WriteAllBytes("invoice.pdf", pdfBytes); using EvoPdf; // Create converter with configuration HtmlToPdfConverter converter = new HtmlToPdfConverter(); // Set license key (required for production use) converter.LicenseKey = "your-license-key"; // Configure conversion settings converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; converter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait; converter.PdfDocumentOptions.TopMargin = 20; converter.PdfDocumentOptions.BottomMargin = 20; converter.PdfDocumentOptions.LeftMargin = 15; converter.PdfDocumentOptions.RightMargin = 15; // Enable JavaScript execution converter.JavaScriptEnabled = true; converter.ConversionDelay = 2; // seconds // Set authentication if needed converter.AuthenticationOptions.Username = "username"; converter.AuthenticationOptions.Password = "password"; // Convert HTML string string htmlString = @" <html> <head> <style> body { font-family: Arial, sans-serif; } table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid #ddd; padding: 8px; } </style> </head> <body> <h1>Invoice</h1> <table> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> </tr> <tr> <td>Product A</td> <td>5</td> <td>$50.00</td> </tr> </table> </body> </html>"; // Perform conversion byte[] pdfBytes = converter.ConvertHtml(htmlString, ""); // Save to file System.IO.File.WriteAllBytes("invoice.pdf", pdfBytes); Imports EvoPdf ' Create converter with configuration Private converter As New HtmlToPdfConverter() ' Set license key (required for production use) converter.LicenseKey = "your-license-key" ' Configure conversion settings converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4 converter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait converter.PdfDocumentOptions.TopMargin = 20 converter.PdfDocumentOptions.BottomMargin = 20 converter.PdfDocumentOptions.LeftMargin = 15 converter.PdfDocumentOptions.RightMargin = 15 ' Enable JavaScript execution converter.JavaScriptEnabled = True converter.ConversionDelay = 2 ' seconds ' Set authentication if needed converter.AuthenticationOptions.Username = "username" converter.AuthenticationOptions.Password = "password" ' Convert HTML string Dim htmlString As String = " <html> <head> <style> body { font-family: Arial, sans-serif; } table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid #ddd; padding: 8px; } </style> </head> <body> <h1>Invoice</h1> <table> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> </tr> <tr> <td>Product A</td> <td>5</td> <td>$50.00</td> </tr> </table> </body> </html>" ' Perform conversion Dim pdfBytes() As Byte = converter.ConvertHtml(htmlString, "") ' Save to file System.IO.File.WriteAllBytes("invoice.pdf", pdfBytes) $vbLabelText $csharpLabel EvoPdf的方法主要集中在简单的HTML转换,良好支持基础样式和布局。 虽然它很好地处理标准HTML和CSS,但在处理现代网页特性,如CSS网格、Flexbox动画或复杂的JavaScript框架时,可能会遇到困难。 PDF安全和加密:保护敏感文档 在处理敏感文档时,安全性至关重要。 两种库都提供加密功能,但复杂程度不同。 IronPDF高级安全实施 using IronPdf; using IronPdf.Security; // Load an existing PDF or create new one var pdf = PdfDocument.FromFile("confidential-report.pdf"); // Configure comprehensive security settings pdf.SecuritySettings = new SecuritySettings { // Set owner password (full permissions) OwnerPassword = "admin-complex-password-2025", // Set user password (restricted permissions) UserPassword = "user-password-readonly", // Configure granular permissions AllowAccessibilityExtractContent = false, AllowAnnotations = false, AllowAssembleDocument = false, AllowCopy = false, AllowFillForms = true, AllowFullQualityPrint = false, AllowModifyDocument = false, AllowPrint = true, // Use strongest encryption available EncryptionLevel = EncryptionLevel.AES256Bit }; // Add metadata security pdf.MetaData.Author = "Authorized Personnel Only"; pdf.MetaData.ModifiedDate = DateTime.UtcNow; pdf.MetaData.Title = "Confidential: Internal Use Only"; // Apply digital signature for authenticity var signature = new PdfSignature("certificate.pfx", "cert-password") { SigningReason = "Document Approval", SigningLocation = "Corporate Headquarters", SigningContact = "security@company.com", // Visual signature appearance IsVisible = true, X = 100, Y = 100, Width = 200, Height = 50, PageIndex = 0, // Custom appearance SignatureImage = new PdfSignatureImage("signature.png"), DateFormat = "yyyy-MM-dd HH:mm:ss" }; pdf.Sign(signature); // Add watermark for additional security pdf.ApplyWatermark("<h2 style='color:red; opacity:0.5;'>CONFIDENTIAL</h2>", 45, VerticalAlignment.Middle, HorizontalAlignment.Center); pdf.SaveAs("secured-document.pdf"); using IronPdf; using IronPdf.Security; // Load an existing PDF or create new one var pdf = PdfDocument.FromFile("confidential-report.pdf"); // Configure comprehensive security settings pdf.SecuritySettings = new SecuritySettings { // Set owner password (full permissions) OwnerPassword = "admin-complex-password-2025", // Set user password (restricted permissions) UserPassword = "user-password-readonly", // Configure granular permissions AllowAccessibilityExtractContent = false, AllowAnnotations = false, AllowAssembleDocument = false, AllowCopy = false, AllowFillForms = true, AllowFullQualityPrint = false, AllowModifyDocument = false, AllowPrint = true, // Use strongest encryption available EncryptionLevel = EncryptionLevel.AES256Bit }; // Add metadata security pdf.MetaData.Author = "Authorized Personnel Only"; pdf.MetaData.ModifiedDate = DateTime.UtcNow; pdf.MetaData.Title = "Confidential: Internal Use Only"; // Apply digital signature for authenticity var signature = new PdfSignature("certificate.pfx", "cert-password") { SigningReason = "Document Approval", SigningLocation = "Corporate Headquarters", SigningContact = "security@company.com", // Visual signature appearance IsVisible = true, X = 100, Y = 100, Width = 200, Height = 50, PageIndex = 0, // Custom appearance SignatureImage = new PdfSignatureImage("signature.png"), DateFormat = "yyyy-MM-dd HH:mm:ss" }; pdf.Sign(signature); // Add watermark for additional security pdf.ApplyWatermark("<h2 style='color:red; opacity:0.5;'>CONFIDENTIAL</h2>", 45, VerticalAlignment.Middle, HorizontalAlignment.Center); pdf.SaveAs("secured-document.pdf"); Imports IronPdf Imports IronPdf.Security ' Load an existing PDF or create new one Private pdf = PdfDocument.FromFile("confidential-report.pdf") ' Configure comprehensive security settings pdf.SecuritySettings = New SecuritySettings With { .OwnerPassword = "admin-complex-password-2025", .UserPassword = "user-password-readonly", .AllowAccessibilityExtractContent = False, .AllowAnnotations = False, .AllowAssembleDocument = False, .AllowCopy = False, .AllowFillForms = True, .AllowFullQualityPrint = False, .AllowModifyDocument = False, .AllowPrint = True, .EncryptionLevel = EncryptionLevel.AES256Bit } ' Add metadata security pdf.MetaData.Author = "Authorized Personnel Only" pdf.MetaData.ModifiedDate = DateTime.UtcNow pdf.MetaData.Title = "Confidential: Internal Use Only" ' Apply digital signature for authenticity Dim signature = New PdfSignature("certificate.pfx", "cert-password") With { .SigningReason = "Document Approval", .SigningLocation = "Corporate Headquarters", .SigningContact = "security@company.com", .IsVisible = True, .X = 100, .Y = 100, .Width = 200, .Height = 50, .PageIndex = 0, .SignatureImage = New PdfSignatureImage("signature.png"), .DateFormat = "yyyy-MM-dd HH:mm:ss" } pdf.Sign(signature) ' Add watermark for additional security pdf.ApplyWatermark("<h2 style='color:red; opacity:0.5;'>CONFIDENTIAL</h2>", 45, VerticalAlignment.Middle, HorizontalAlignment.Center) pdf.SaveAs("secured-document.pdf") $vbLabelText $csharpLabel IronPDF的安全实施提供企业级的功能: 15+种细粒度权限:精确调整用户的操作 视觉数字签名:包含签名图像和时间戳 元数据保护:保护文档属性和审计记录 分层安全:结合加密、签名和水印 EvoPdf安全配置 using EvoPdf; // Create security manager PdfSecurityOptions securityOptions = new PdfSecurityOptions(); // Set basic security parameters securityOptions.UserPassword = "user123"; securityOptions.OwnerPassword = "owner456"; securityOptions.KeySize = EncryptionKeySize.Key256Bit; // Configure permissions securityOptions.CanPrint = true; securityOptions.CanCopyContent = false; securityOptions.CanEditContent = false; securityOptions.CanEditAnnotations = false; securityOptions.CanFillFormFields = true; securityOptions.CanAssembleDocument = false; // Apply security to existing PDF PdfSecurityManager securityManager = new PdfSecurityManager(securityOptions); securityManager.SaveSecuredPdfToFile("input.pdf", "secured-output.pdf"); using EvoPdf; // Create security manager PdfSecurityOptions securityOptions = new PdfSecurityOptions(); // Set basic security parameters securityOptions.UserPassword = "user123"; securityOptions.OwnerPassword = "owner456"; securityOptions.KeySize = EncryptionKeySize.Key256Bit; // Configure permissions securityOptions.CanPrint = true; securityOptions.CanCopyContent = false; securityOptions.CanEditContent = false; securityOptions.CanEditAnnotations = false; securityOptions.CanFillFormFields = true; securityOptions.CanAssembleDocument = false; // Apply security to existing PDF PdfSecurityManager securityManager = new PdfSecurityManager(securityOptions); securityManager.SaveSecuredPdfToFile("input.pdf", "secured-output.pdf"); Imports EvoPdf ' Create security manager Private securityOptions As New PdfSecurityOptions() ' Set basic security parameters securityOptions.UserPassword = "user123" securityOptions.OwnerPassword = "owner456" securityOptions.KeySize = EncryptionKeySize.Key256Bit ' Configure permissions securityOptions.CanPrint = True securityOptions.CanCopyContent = False securityOptions.CanEditContent = False securityOptions.CanEditAnnotations = False securityOptions.CanFillFormFields = True securityOptions.CanAssembleDocument = False ' Apply security to existing PDF Dim securityManager As New PdfSecurityManager(securityOptions) securityManager.SaveSecuredPdfToFile("input.pdf", "secured-output.pdf") $vbLabelText $csharpLabel EvoPdf提供了适合基本文档保护的基本安全功能,但缺乏IronPDF中的一些高级选项。 内容编辑:合规和隐私保护 在当今的隐私意识环境中,能够永久删除PDF中的敏感信息对遵循GDPR、HIPAA和CCPA等法规至关重要。 IronPDF编辑示例 using IronPdf; // Load PDF containing sensitive information PdfDocument pdf = PdfDocument.FromFile("customer-records.pdf"); // Redact using multiple strategies // 1. Redact specific text patterns (SSN format) pdf.RedactTextOnAllPages(@"\b\d{3}-\d{2}-\d{4}\b", isRegex: true, new RedactionOptions { RedactionColor = Color.Black, RedactionStyle = RedactionStyle.Filled, DrawRedactionBorder = true, BorderColor = Color.Red }); // 2. Redact specific phrases pdf.RedactTextOnPages("Confidential", new[] { 0, 1, 2 }, // Specific pages caseSensitive: false); // 3. Redact regions by coordinates pdf.RedactRegion(new Rectangle(100, 200, 300, 50), 0); // 4. Use advanced pattern matching for credit cards string creditCardPattern = @"\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})\b"; pdf.RedactTextOnAllPages(creditCardPattern, isRegex: true); // Apply OCR-based redaction for scanned documents pdf.ApplyOcr(new TesseractLanguage[] { TesseractLanguage.English }); pdf.RedactTextOnAllPages("Salary:"); // Save with audit trail pdf.MetaData.CustomProperties.Add("Redacted", DateTime.UtcNow.ToString()); pdf.MetaData.CustomProperties.Add("RedactedBy", Environment.UserName); pdf.SaveAs("redacted-records.pdf"); using IronPdf; // Load PDF containing sensitive information PdfDocument pdf = PdfDocument.FromFile("customer-records.pdf"); // Redact using multiple strategies // 1. Redact specific text patterns (SSN format) pdf.RedactTextOnAllPages(@"\b\d{3}-\d{2}-\d{4}\b", isRegex: true, new RedactionOptions { RedactionColor = Color.Black, RedactionStyle = RedactionStyle.Filled, DrawRedactionBorder = true, BorderColor = Color.Red }); // 2. Redact specific phrases pdf.RedactTextOnPages("Confidential", new[] { 0, 1, 2 }, // Specific pages caseSensitive: false); // 3. Redact regions by coordinates pdf.RedactRegion(new Rectangle(100, 200, 300, 50), 0); // 4. Use advanced pattern matching for credit cards string creditCardPattern = @"\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})\b"; pdf.RedactTextOnAllPages(creditCardPattern, isRegex: true); // Apply OCR-based redaction for scanned documents pdf.ApplyOcr(new TesseractLanguage[] { TesseractLanguage.English }); pdf.RedactTextOnAllPages("Salary:"); // Save with audit trail pdf.MetaData.CustomProperties.Add("Redacted", DateTime.UtcNow.ToString()); pdf.MetaData.CustomProperties.Add("RedactedBy", Environment.UserName); pdf.SaveAs("redacted-records.pdf"); Imports IronPdf ' Load PDF containing sensitive information Private pdf As PdfDocument = PdfDocument.FromFile("customer-records.pdf") ' Redact using multiple strategies ' 1. Redact specific text patterns (SSN format) pdf.RedactTextOnAllPages("\b\d{3}-\d{2}-\d{4}\b", isRegex:= True, New RedactionOptions With { .RedactionColor = Color.Black, .RedactionStyle = RedactionStyle.Filled, .DrawRedactionBorder = True, .BorderColor = Color.Red }) ' 2. Redact specific phrases pdf.RedactTextOnPages("Confidential", { 0, 1, 2 }, caseSensitive:= False) ' 3. Redact regions by coordinates pdf.RedactRegion(New Rectangle(100, 200, 300, 50), 0) ' 4. Use advanced pattern matching for credit cards Dim creditCardPattern As String = "\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})\b" pdf.RedactTextOnAllPages(creditCardPattern, isRegex:= True) ' Apply OCR-based redaction for scanned documents pdf.ApplyOcr(New TesseractLanguage() { TesseractLanguage.English }) pdf.RedactTextOnAllPages("Salary:") ' Save with audit trail pdf.MetaData.CustomProperties.Add("Redacted", DateTime.UtcNow.ToString()) pdf.MetaData.CustomProperties.Add("RedactedBy", Environment.UserName) pdf.SaveAs("redacted-records.pdf") $vbLabelText $csharpLabel IronPDF的编辑功能包括: 真实内容删除:永久删除文本,而非仅覆盖 模式识别:支持SSN、信用卡、电子邮件的正则表达式 视觉编辑样式:为审计追踪提供可定制外观 OCR集成:编辑扫描文档中的文本 选择性编辑:针对特定页面或区域 EvoPdf不包括内置的编辑功能,这对于需要遵循隐私法规的应用程序来说可能是一个显著的限制。 表单处理:创建交互式PDF 两种库都支持PDF表单,但其创建和操作方法不同。 IronPDF表单示例 using IronPdf; using IronPdf.Forms; // Create a new PDF with an HTML form var html = @" <html> <body> <h2>Employee Information Form</h2> <form> <label>Full Name:</label> <input type='text' name='fullName' required /> <label>Email:</label> <input type='email' name='email' required /> <label>Department:</label> <select name='department'> <option value=''>Select Department</option> <option value='IT'>Information Technology</option> <option value='HR'>Human Resources</option> <option value='Sales'>Sales</option> </select> <label>Start Date:</label> <input type='date' name='startDate' /> <label> <input type='checkbox' name='agreement' /> I agree to the terms and conditions </label> <button type='submit'>Submit</button> </form> </body> </html>"; var renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { CreatePdfFormsFromHtml = true // Enable form field creation } }; var pdf = renderer.RenderHtmlAsPdf(html); // Programmatically fill form fields pdf.Form.SetFieldValue("fullName", "John Doe"); pdf.Form.SetFieldValue("email", "john.doe@company.com"); pdf.Form.SetFieldValue("department", "IT"); pdf.Form.SetFieldValue("startDate", DateTime.Now.ToString("yyyy-MM-dd")); pdf.Form.SetCheckBoxValue("agreement", true); // Make specific fields read-only pdf.Form.Fields["email"].ReadOnly = true; // Add form field validation foreach (var field in pdf.Form.Fields) { if (field.Name == "email") { field.Annotation.BorderColor = Color.Blue; field.Annotation.BackgroundColor = Color.LightGray; } } // Flatten form (convert to static content) var flattenedPdf = pdf.Flatten(); flattenedPdf.SaveAs("completed-form.pdf"); // Or save as fillable form pdf.SaveAs("fillable-form.pdf"); using IronPdf; using IronPdf.Forms; // Create a new PDF with an HTML form var html = @" <html> <body> <h2>Employee Information Form</h2> <form> <label>Full Name:</label> <input type='text' name='fullName' required /> <label>Email:</label> <input type='email' name='email' required /> <label>Department:</label> <select name='department'> <option value=''>Select Department</option> <option value='IT'>Information Technology</option> <option value='HR'>Human Resources</option> <option value='Sales'>Sales</option> </select> <label>Start Date:</label> <input type='date' name='startDate' /> <label> <input type='checkbox' name='agreement' /> I agree to the terms and conditions </label> <button type='submit'>Submit</button> </form> </body> </html>"; var renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { CreatePdfFormsFromHtml = true // Enable form field creation } }; var pdf = renderer.RenderHtmlAsPdf(html); // Programmatically fill form fields pdf.Form.SetFieldValue("fullName", "John Doe"); pdf.Form.SetFieldValue("email", "john.doe@company.com"); pdf.Form.SetFieldValue("department", "IT"); pdf.Form.SetFieldValue("startDate", DateTime.Now.ToString("yyyy-MM-dd")); pdf.Form.SetCheckBoxValue("agreement", true); // Make specific fields read-only pdf.Form.Fields["email"].ReadOnly = true; // Add form field validation foreach (var field in pdf.Form.Fields) { if (field.Name == "email") { field.Annotation.BorderColor = Color.Blue; field.Annotation.BackgroundColor = Color.LightGray; } } // Flatten form (convert to static content) var flattenedPdf = pdf.Flatten(); flattenedPdf.SaveAs("completed-form.pdf"); // Or save as fillable form pdf.SaveAs("fillable-form.pdf"); Imports IronPdf Imports IronPdf.Forms ' Create a new PDF with an HTML form Private html = " <html> <body> <h2>Employee Information Form</h2> <form> <label>Full Name:</label> <input type='text' name='fullName' required /> <label>Email:</label> <input type='email' name='email' required /> <label>Department:</label> <select name='department'> <option value=''>Select Department</option> <option value='IT'>Information Technology</option> <option value='HR'>Human Resources</option> <option value='Sales'>Sales</option> </select> <label>Start Date:</label> <input type='date' name='startDate' /> <label> <input type='checkbox' name='agreement' /> I agree to the terms and conditions </label> <button type='submit'>Submit</button> </form> </body> </html>" Private renderer = New ChromePdfRenderer With { .RenderingOptions = New ChromePdfRenderOptions With {.CreatePdfFormsFromHtml = True} } Private pdf = renderer.RenderHtmlAsPdf(html) ' Programmatically fill form fields pdf.Form.SetFieldValue("fullName", "John Doe") pdf.Form.SetFieldValue("email", "john.doe@company.com") pdf.Form.SetFieldValue("department", "IT") pdf.Form.SetFieldValue("startDate", DateTime.Now.ToString("yyyy-MM-dd")) pdf.Form.SetCheckBoxValue("agreement", True) ' Make specific fields read-only pdf.Form.Fields("email").ReadOnly = True ' Add form field validation For Each field In pdf.Form.Fields If field.Name = "email" Then field.Annotation.BorderColor = Color.Blue field.Annotation.BackgroundColor = Color.LightGray End If Next field ' Flatten form (convert to static content) Dim flattenedPdf = pdf.Flatten() flattenedPdf.SaveAs("completed-form.pdf") ' Or save as fillable form pdf.SaveAs("fillable-form.pdf") $vbLabelText $csharpLabel IronPDF的表单处理功能: 自动表单生成:将HTML表单转换为PDF表单 程序化操作:通过API填充、读取和修改表单字段 字段类型:文本、复选框、单选、下拉、签名字段 验证:设置字段属性和约束 表单平面化:将填充的表单转换为静态PDF 性能基准:真实场景 性能特点因文档复杂性和用例而异: 批处理性能测试 // Performance comparison for batch processing public class PerformanceBenchmark { public static async Task RunBenchmark() { var htmlTemplates = GenerateInvoiceTemplates(1000); var stopwatch = new Stopwatch(); // IronPDF batch processing with optimization Console.WriteLine("IronPDF Batch Processing:"); stopwatch.Start(); var renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { RenderDelay = 0, // No delay for static content EnableJavaScript = false, // Disable JS for speed DPI = 150 // Lower DPI for faster rendering } }; // Parallel processing var tasks = htmlTemplates.Select(async (html, index) => { var pdf = await renderer.RenderHtmlAsPdfAsync(html); await pdf.SaveAsAsync($"ironpdf-invoice-{index}.pdf"); }); await Task.WhenAll(tasks); stopwatch.Stop(); Console.WriteLine($"Time: {stopwatch.ElapsedMilliseconds}ms"); Console.WriteLine($"Average: {stopwatch.ElapsedMilliseconds / 1000.0}ms per PDF"); // Memory usage var process = Process.GetCurrentProcess(); Console.WriteLine($"Memory: {process.WorkingSet64 / 1024 / 1024}MB"); } } // Performance comparison for batch processing public class PerformanceBenchmark { public static async Task RunBenchmark() { var htmlTemplates = GenerateInvoiceTemplates(1000); var stopwatch = new Stopwatch(); // IronPDF batch processing with optimization Console.WriteLine("IronPDF Batch Processing:"); stopwatch.Start(); var renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { RenderDelay = 0, // No delay for static content EnableJavaScript = false, // Disable JS for speed DPI = 150 // Lower DPI for faster rendering } }; // Parallel processing var tasks = htmlTemplates.Select(async (html, index) => { var pdf = await renderer.RenderHtmlAsPdfAsync(html); await pdf.SaveAsAsync($"ironpdf-invoice-{index}.pdf"); }); await Task.WhenAll(tasks); stopwatch.Stop(); Console.WriteLine($"Time: {stopwatch.ElapsedMilliseconds}ms"); Console.WriteLine($"Average: {stopwatch.ElapsedMilliseconds / 1000.0}ms per PDF"); // Memory usage var process = Process.GetCurrentProcess(); Console.WriteLine($"Memory: {process.WorkingSet64 / 1024 / 1024}MB"); } } ' Performance comparison for batch processing Public Class PerformanceBenchmark Public Shared Async Function RunBenchmark() As Task Dim htmlTemplates = GenerateInvoiceTemplates(1000) Dim stopwatch As New Stopwatch() ' IronPDF batch processing with optimization Console.WriteLine("IronPDF Batch Processing:") stopwatch.Start() Dim renderer = New ChromePdfRenderer With { .RenderingOptions = New ChromePdfRenderOptions With { .RenderDelay = 0, .EnableJavaScript = False, .DPI = 150 } } ' Parallel processing Dim tasks = htmlTemplates.Select(Async Function(html, index) Dim pdf = Await renderer.RenderHtmlAsPdfAsync(html) Await pdf.SaveAsAsync($"ironpdf-invoice-{index}.pdf") End Function) Await Task.WhenAll(tasks) stopwatch.Stop() Console.WriteLine($"Time: {stopwatch.ElapsedMilliseconds}ms") Console.WriteLine($"Average: {stopwatch.ElapsedMilliseconds / 1000.0}ms per PDF") ' Memory usage Dim process As System.Diagnostics.Process = System.Diagnostics.Process.GetCurrentProcess() Console.WriteLine($"Memory: {process.WorkingSet64 \ 1024 \ 1024}MB") End Function End Class $vbLabelText $csharpLabel 来自真实测试的性能发现: 简单HTML:EvoPdf快30-40%(0.8秒对1.2秒) 复杂JavaScript:IronPDF更可靠,EvoPdf可能失败 批处理:IronPDF更好的并行化 内存使用:EvoPdf基础负载更低,IronPDF更好的垃圾回收 大文档:IronPDF对1000+页文档快30% 不同团队规模的定价模型比较如何? IronPDF 许可结构 IronPDF提供各种定价选项,包括Lite、Plus和Professional许可证,并且有免版税再分发的选项。 其许可模式旨在随您的团队和项目需求扩展(截至2025年的定价): Lite许可证:$799 1位开发者 1个地点 1个项目 电子邮件支持 理想的用途:独立开发者、小型项目 Plus许可证:$1,199 3位开发者 3个地点 3个项目 电子邮件、聊天和电话支持 理想的用途:小团队,多项目 Professional许可证:$2,399 10位开发者 10个地点 10个项目 屏幕共享优先支持 理想的用途:中到大型团队 附加选项: 免版税再分发:+$2,399 5年支持和更新:$1,999(或$999/年) Iron Suite:$1,498用于所有9个Iron Software产品 EvoPdf许可选项 EVO PDF工具包的部署版本为$650,公司版本为$1,400,而独立HTML到PDF转换器的部署版本为$450,公司版本为$1,200: 部署许可证: EVO HTML到PDF:$450 EVO PDF工具包:$650 单一服务器,单一应用程序 不可再分发 第一年标准支持 公司许可证: EVO HTML到PDF:$1,200 EVO PDF工具包:$1,400 无限开发者 无限部署 完全再分发权 第一年优先支持 总拥有成本分析 让我们分析真实场景以了解真正的成本影响: 场景1:拥有2名开发者的初创公司 IronPDF Lite:$799(需要2个许可证=$1,498) EvoPdf公司:$1,200(覆盖无限开发者) 胜者:EvoPdf因初始成本 场景2:增长中的团队(5名开发者,多个项目) IronPDF Plus:$1,199(覆盖最多3名开发者,需要Professional) IronPDF Professional:$2,399 EvoPdf公司:$1,200 胜者:EvoPdf因团队扩展 场景3:需要多个PDF工具的企业 IronPDF Professional + IronOCR + IronBarcode:~$9,000 Iron Suite:$1,498(所有9个产品) EvoPdf工具包+额外工具:$1,400+每个工具 胜者:Iron Suite用于全面需求 场景4:SaaS产品的再分发 IronPDF Professional + 再分发:$4,998 EvoPdf公司:$1,200 (includes redistribution) 胜者:EvoPdf在再分发场景中 现代CSS框架如何影响您的选择? 在选择PDF库时,一个经常被低估的因素是支持现代CSS框架。 随着Bootstrap、Tailwind CSS和Foundation主导网页开发,您的库能够处理这些框架将直接影响开发效率和输出质量。 IronPDF:全面的框架支持 IronPDF的完整Chrome V8引擎无需任何妥协地提供所有现代CSS框架的原生支持: Bootstrap 5:完全支持flexbox和CSS网格以实现复杂布局 Tailwind CSS:准确呈现所有实用工具类 现代CSS3:支持变换、动画、自定义属性 Production validation: Successfully renders the Bootstrap homepage and Bootstrap templates 代码示例:Bootstrap时间轴组件 using IronPdf; var renderer = new ChromePdfRenderer(); string bootstrapTimeline = @" <!DOCTYPE html> <html> <head> <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'> <style> .timeline { position: relative; padding: 20px 0; } .timeline::before { content: ''; position: absolute; left: 50%; width: 2px; height: 100%; background: #dee2e6; } .timeline-item { position: relative; margin: 20px 0; } </style> </head> <body> <div class='container py-5'> <h2 class='text-center mb-5'>Project Timeline</h2> <div class='timeline'> <div class='timeline-item'> <div class='row'> <div class='col-md-6'> <div class='card shadow-sm'> <div class='card-body'> <h5 class='card-title'>Phase 1: Planning</h5> <p class='text-muted'>Q1 2025</p> <p class='card-text'>Initial project scope and requirements gathering completed.</p> <span class='badge bg-success'>Completed</span> </div> </div> </div> </div> </div> <!-- Additional timeline items... --> </div> </div> </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(bootstrapTimeline); pdf.SaveAs("project-timeline.pdf"); using IronPdf; var renderer = new ChromePdfRenderer(); string bootstrapTimeline = @" <!DOCTYPE html> <html> <head> <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'> <style> .timeline { position: relative; padding: 20px 0; } .timeline::before { content: ''; position: absolute; left: 50%; width: 2px; height: 100%; background: #dee2e6; } .timeline-item { position: relative; margin: 20px 0; } </style> </head> <body> <div class='container py-5'> <h2 class='text-center mb-5'>Project Timeline</h2> <div class='timeline'> <div class='timeline-item'> <div class='row'> <div class='col-md-6'> <div class='card shadow-sm'> <div class='card-body'> <h5 class='card-title'>Phase 1: Planning</h5> <p class='text-muted'>Q1 2025</p> <p class='card-text'>Initial project scope and requirements gathering completed.</p> <span class='badge bg-success'>Completed</span> </div> </div> </div> </div> </div> <!-- Additional timeline items... --> </div> </div> </body> </html>"; var pdf = renderer.RenderHtmlAsPdf(bootstrapTimeline); pdf.SaveAs("project-timeline.pdf"); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel EvoPdf:良好的CSS支持但有局限 EvoPdf的定制HTML渲染引擎提供了可靠的CSS支持,但对现代框架有一些限制: Bootstrap 3:通常与旧版Bootstrap版本配合良好 Bootstrap 4+:Flexbox布局可能需要调整 CSS3支持:不错的覆盖(~90%),但不完整 可用解决办法:对复杂布局的CSS手动调整通常是必要的 实用考虑: 根据开发者经验: 基本的Bootstrap组件(按钮、警报、表格)一般能正确呈现 高级组件(导航栏、模态框、复杂网格)可能需要自定义 CSS网格布局需要测试和潜在的备选方案 自定义的Bootstrap主题有时会有意料之外的渲染问题 开发影响:如果您的应用广泛使用Bootstrap进行UI设计,并且您需要生成与网页界面匹配的报告或文件,那么IronPDF的无缝渲染将节省大量开发时间。EvoPdf可能需要为PDF生成单独创建简化的模板版本。 有关CSS框架兼容性的详细信息,请参阅Bootstrap & Flexbox CSS指南。 哪个文档和支持选项更适合开发者? IronPDF的开发者资源 IronPDF提供了全面的文档、5天24小时的工程师支持、视频教程、社区论坛和定期更新。 支持生态系统包括: 文档质量: 全面的API参考 分步教程 100+个代码示例 YouTube上的视频教程 从其他库的迁移指南 支持渠道: 5天24小时的工程支持(直接与开发人员联系) 响应时间:通常24-48小时 Plus+许可证的即时聊天 Professional许可证的电话支持 复杂问题的屏幕共享 社区论坛和Stack Overflow上的存在 学习资源: 入门指南 架构文档 性能优化指南 安全最佳实践 云部署指南 EvoPdf的支持结构 EvoPdf通过以下方式提供文档和支持: 文档: API参考文档 常见场景的代码示例 网站上的实时演示部分 基础故障排除指南 支持选项: 电子邮件和电话支持(首年包含) 标准与优先支持层级 支持论坛以获得社区帮助 首年后需要更新 关键的区别在于IronPDF对教育内容和直接工程支持的投资,这显著减少了学习曲线和故障排除时间。 每种库的最佳使用场景是什么? 何时选择 IronPDF? IronPDF在需要的场景中表现出色: 1. 现代网页应用集成 生成动态报告的SaaS平台 具有图表的电子商务网站创建发票 作为PDF导出的业务智能仪表盘 使用React、Angular或Vue.js的应用程序 2. 合规和安全要求 需要HIPAA合规的医疗系统 需要审计记录的金融服务 有编辑功能的法律文档管理 具有安全授权的政府应用 3. 复杂文档处理 多格式文档转换(DOCX、HTML、图像) 扫描文档的OCR集成 支持并行执行的批处理 带数字签名的文档 4. 跨平台部署 Docker容器化应用 基于Linux的云部署 微服务架构 无服务器函数(AWS Lambda、Azure Functions) 真实世界示例:医疗报告生成 public class HealthcareReportGenerator { private readonly ChromePdfRenderer _renderer; public HealthcareReportGenerator() { _renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { DPI = 300, // High quality for medical imaging EnableJavaScript = true, RenderDelay = 3000, // Allow charts to fully render CreatePdfFormsFromHtml = true } }; } public async Task<byte[]> GeneratePatientReport(PatientData patient) { // Generate HTML with patient data and charts var html = await GenerateReportHtml(patient); // Convert to PDF var pdf = await _renderer.RenderHtmlAsPdfAsync(html); // Apply security and compliance pdf.SecuritySettings = new SecuritySettings { AllowPrint = true, AllowCopy = false, EncryptionLevel = EncryptionLevel.AES256Bit, UserPassword = patient.AccessCode }; // Redact SSN except last 4 digits pdf.RedactTextOnAllPages(@"\b\d{3}-\d{2}-(\d{4})\b", replacement: "XXX-XX-$1", isRegex: true); // Add audit metadata pdf.MetaData.Author = "Healthcare System"; pdf.MetaData.Title = $"Patient Report - {patient.PatientId}"; pdf.MetaData.CreationDate = DateTime.UtcNow; pdf.MetaData.CustomProperties.Add("HIPAA_Compliant", "true"); // Add digital signature var signature = new PdfSignature("hospital-cert.pfx", "password") { SigningReason = "Medical Record Authenticity", SigningLocation = "Hospital Name" }; pdf.Sign(signature); return pdf.BinaryData; } } public class HealthcareReportGenerator { private readonly ChromePdfRenderer _renderer; public HealthcareReportGenerator() { _renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { DPI = 300, // High quality for medical imaging EnableJavaScript = true, RenderDelay = 3000, // Allow charts to fully render CreatePdfFormsFromHtml = true } }; } public async Task<byte[]> GeneratePatientReport(PatientData patient) { // Generate HTML with patient data and charts var html = await GenerateReportHtml(patient); // Convert to PDF var pdf = await _renderer.RenderHtmlAsPdfAsync(html); // Apply security and compliance pdf.SecuritySettings = new SecuritySettings { AllowPrint = true, AllowCopy = false, EncryptionLevel = EncryptionLevel.AES256Bit, UserPassword = patient.AccessCode }; // Redact SSN except last 4 digits pdf.RedactTextOnAllPages(@"\b\d{3}-\d{2}-(\d{4})\b", replacement: "XXX-XX-$1", isRegex: true); // Add audit metadata pdf.MetaData.Author = "Healthcare System"; pdf.MetaData.Title = $"Patient Report - {patient.PatientId}"; pdf.MetaData.CreationDate = DateTime.UtcNow; pdf.MetaData.CustomProperties.Add("HIPAA_Compliant", "true"); // Add digital signature var signature = new PdfSignature("hospital-cert.pfx", "password") { SigningReason = "Medical Record Authenticity", SigningLocation = "Hospital Name" }; pdf.Sign(signature); return pdf.BinaryData; } } Public Class HealthcareReportGenerator Private ReadOnly _renderer As ChromePdfRenderer Public Sub New() _renderer = New ChromePdfRenderer With { .RenderingOptions = New ChromePdfRenderOptions With { .DPI = 300, .EnableJavaScript = True, .RenderDelay = 3000, .CreatePdfFormsFromHtml = True } } End Sub Public Async Function GeneratePatientReport(ByVal patient As PatientData) As Task(Of Byte()) ' Generate HTML with patient data and charts Dim html = Await GenerateReportHtml(patient) ' Convert to PDF Dim pdf = Await _renderer.RenderHtmlAsPdfAsync(html) ' Apply security and compliance pdf.SecuritySettings = New SecuritySettings With { .AllowPrint = True, .AllowCopy = False, .EncryptionLevel = EncryptionLevel.AES256Bit, .UserPassword = patient.AccessCode } ' Redact SSN except last 4 digits pdf.RedactTextOnAllPages("\b\d{3}-\d{2}-(\d{4})\b", replacement:= "XXX-XX-$1", isRegex:= True) ' Add audit metadata pdf.MetaData.Author = "Healthcare System" pdf.MetaData.Title = $"Patient Report - {patient.PatientId}" pdf.MetaData.CreationDate = DateTime.UtcNow pdf.MetaData.CustomProperties.Add("HIPAA_Compliant", "true") ' Add digital signature Dim signature = New PdfSignature("hospital-cert.pfx", "password") With { .SigningReason = "Medical Record Authenticity", .SigningLocation = "Hospital Name" } pdf.Sign(signature) Return pdf.BinaryData End Function End Class $vbLabelText $csharpLabel 何时选择EvoPdf EvoPdf适合: 1. 简单的HTML到PDF转换 没有复杂JavaScript的基本报告 静态HTML模板 简单的发票和收据 使用一致模板的批量文档生成 2. 预算有限的团队 单一许可上的无限开发者 基础功能的较低入门成本 不需要高级PDF操作的项目 3. 特定服务器环境 以Windows为中心的部署 具有简单PDF需求的应用程序 旧系统集成 4. 大量简单转换 邮件到PDF归档 静态报告生成 文档系统 可打印的文档创建 实际案例:发票生成系统 public class InvoiceGenerator { private readonly HtmlToPdfConverter _converter; public InvoiceGenerator() { _converter = new HtmlToPdfConverter { LicenseKey = "your-license-key", JavaScriptEnabled = false, // Not needed for static invoices ConversionDelay = 0 }; // Configure for A4 invoices _converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; _converter.PdfDocumentOptions.TopMargin = 30; _converter.PdfDocumentOptions.BottomMargin = 30; } public byte[] GenerateInvoice(InvoiceData data) { // Load HTML template var template = File.ReadAllText("invoice-template.html"); // Simple string replacement for data var html = template .Replace("{{InvoiceNumber}}", data.InvoiceNumber) .Replace("{{Date}}", data.Date.ToString("yyyy-MM-dd")) .Replace("{{CustomerName}}", data.CustomerName) .Replace("{{Total}}", data.Total.ToString("C")); // Convert to PDF return _converter.ConvertHtml(html, ""); } } public class InvoiceGenerator { private readonly HtmlToPdfConverter _converter; public InvoiceGenerator() { _converter = new HtmlToPdfConverter { LicenseKey = "your-license-key", JavaScriptEnabled = false, // Not needed for static invoices ConversionDelay = 0 }; // Configure for A4 invoices _converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; _converter.PdfDocumentOptions.TopMargin = 30; _converter.PdfDocumentOptions.BottomMargin = 30; } public byte[] GenerateInvoice(InvoiceData data) { // Load HTML template var template = File.ReadAllText("invoice-template.html"); // Simple string replacement for data var html = template .Replace("{{InvoiceNumber}}", data.InvoiceNumber) .Replace("{{Date}}", data.Date.ToString("yyyy-MM-dd")) .Replace("{{CustomerName}}", data.CustomerName) .Replace("{{Total}}", data.Total.ToString("C")); // Convert to PDF return _converter.ConvertHtml(html, ""); } } Public Class InvoiceGenerator Private ReadOnly _converter As HtmlToPdfConverter Public Sub New() _converter = New HtmlToPdfConverter With { .LicenseKey = "your-license-key", .JavaScriptEnabled = False, .ConversionDelay = 0 } ' Configure for A4 invoices _converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4 _converter.PdfDocumentOptions.TopMargin = 30 _converter.PdfDocumentOptions.BottomMargin = 30 End Sub Public Function GenerateInvoice(ByVal data As InvoiceData) As Byte() ' Load HTML template Dim template = File.ReadAllText("invoice-template.html") ' Simple string replacement for data Dim html = template.Replace("{{InvoiceNumber}}", data.InvoiceNumber).Replace("{{Date}}", data.Date.ToString("yyyy-MM-dd")).Replace("{{CustomerName}}", data.CustomerName).Replace("{{Total}}", data.Total.ToString("C")) ' Convert to PDF Return _converter.ConvertHtml(html, "") End Function End Class $vbLabelText $csharpLabel 高级实施模式和最佳实践 优化生产中的性能 这两个库在适当的配置和使用模式下都能获益: IronPDF 性能优化 public class OptimizedPdfService { private readonly ChromePdfRenderer _renderer; private readonly SemaphoreSlim _semaphore; public OptimizedPdfService(int maxConcurrency = 4) { _semaphore = new SemaphoreSlim(maxConcurrency); _renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { // Optimize for performance EnableJavaScript = false, // Only if not needed RenderDelay = 0, DPI = 150, // Balance quality vs speed CssMediaType = PdfCssMediaType.Screen, Timeout = 30, // Memory optimization OptimizeForLowMemory = true } }; // Enable connection pooling Installation.ChromeGpuMode = ChromeGpuModes.Disabled; Installation.LinuxAndDockerDependenciesAutoConfig = false; } public async Task<byte[]> GeneratePdfAsync(string html) { await _semaphore.WaitAsync(); try { var pdf = await _renderer.RenderHtmlAsPdfAsync(html); // Optimize file size pdf.CompressImages(85); pdf.RemoveUnusedResources(); return pdf.BinaryData; } finally { _semaphore.Release(); } } } public class OptimizedPdfService { private readonly ChromePdfRenderer _renderer; private readonly SemaphoreSlim _semaphore; public OptimizedPdfService(int maxConcurrency = 4) { _semaphore = new SemaphoreSlim(maxConcurrency); _renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { // Optimize for performance EnableJavaScript = false, // Only if not needed RenderDelay = 0, DPI = 150, // Balance quality vs speed CssMediaType = PdfCssMediaType.Screen, Timeout = 30, // Memory optimization OptimizeForLowMemory = true } }; // Enable connection pooling Installation.ChromeGpuMode = ChromeGpuModes.Disabled; Installation.LinuxAndDockerDependenciesAutoConfig = false; } public async Task<byte[]> GeneratePdfAsync(string html) { await _semaphore.WaitAsync(); try { var pdf = await _renderer.RenderHtmlAsPdfAsync(html); // Optimize file size pdf.CompressImages(85); pdf.RemoveUnusedResources(); return pdf.BinaryData; } finally { _semaphore.Release(); } } } Public Class OptimizedPdfService Private ReadOnly _renderer As ChromePdfRenderer Private ReadOnly _semaphore As SemaphoreSlim Public Sub New(Optional ByVal maxConcurrency As Integer = 4) _semaphore = New SemaphoreSlim(maxConcurrency) _renderer = New ChromePdfRenderer With { .RenderingOptions = New ChromePdfRenderOptions With { .EnableJavaScript = False, .RenderDelay = 0, .DPI = 150, .CssMediaType = PdfCssMediaType.Screen, .Timeout = 30, .OptimizeForLowMemory = True } } ' Enable connection pooling Installation.ChromeGpuMode = ChromeGpuModes.Disabled Installation.LinuxAndDockerDependenciesAutoConfig = False End Sub Public Async Function GeneratePdfAsync(ByVal html As String) As Task(Of Byte()) Await _semaphore.WaitAsync() Try Dim pdf = Await _renderer.RenderHtmlAsPdfAsync(html) ' Optimize file size pdf.CompressImages(85) pdf.RemoveUnusedResources() Return pdf.BinaryData Finally _semaphore.Release() End Try End Function End Class $vbLabelText $csharpLabel EvoPdf 性能模式 public class EvoPdfOptimizedService { private readonly ObjectPool<HtmlToPdfConverter> _converterPool; public EvoPdfOptimizedService() { // Create object pool for converter reuse _converterPool = new DefaultObjectPool<HtmlToPdfConverter>( new ConverterPoolPolicy(), Environment.ProcessorCount * 2); } public async Task<byte[]> GeneratePdfAsync(string html) { var converter = _converterPool.Get(); try { // Configure for speed converter.ConversionDelay = 0; converter.JavaScriptEnabled = false; // Use async pattern return await Task.Run(() => converter.ConvertHtml(html, "")); } finally { _converterPool.Return(converter); } } private class ConverterPoolPolicy : IPooledObjectPolicy<HtmlToPdfConverter> { public HtmlToPdfConverter Create() { return new HtmlToPdfConverter { LicenseKey = "your-license-key" }; } public bool Return(HtmlToPdfConverter obj) { // Reset to default state obj.ConversionDelay = 2; return true; } } } public class EvoPdfOptimizedService { private readonly ObjectPool<HtmlToPdfConverter> _converterPool; public EvoPdfOptimizedService() { // Create object pool for converter reuse _converterPool = new DefaultObjectPool<HtmlToPdfConverter>( new ConverterPoolPolicy(), Environment.ProcessorCount * 2); } public async Task<byte[]> GeneratePdfAsync(string html) { var converter = _converterPool.Get(); try { // Configure for speed converter.ConversionDelay = 0; converter.JavaScriptEnabled = false; // Use async pattern return await Task.Run(() => converter.ConvertHtml(html, "")); } finally { _converterPool.Return(converter); } } private class ConverterPoolPolicy : IPooledObjectPolicy<HtmlToPdfConverter> { public HtmlToPdfConverter Create() { return new HtmlToPdfConverter { LicenseKey = "your-license-key" }; } public bool Return(HtmlToPdfConverter obj) { // Reset to default state obj.ConversionDelay = 2; return true; } } } Public Class EvoPdfOptimizedService Private ReadOnly _converterPool As ObjectPool(Of HtmlToPdfConverter) Public Sub New() ' Create object pool for converter reuse _converterPool = New DefaultObjectPool(Of HtmlToPdfConverter)(New ConverterPoolPolicy(), Environment.ProcessorCount * 2) End Sub Public Async Function GeneratePdfAsync(ByVal html As String) As Task(Of Byte()) Dim converter = _converterPool.Get() Try ' Configure for speed converter.ConversionDelay = 0 converter.JavaScriptEnabled = False ' Use async pattern Return Await Task.Run(Function() converter.ConvertHtml(html, "")) Finally _converterPool.Return(converter) End Try End Function Private Class ConverterPoolPolicy Implements IPooledObjectPolicy(Of HtmlToPdfConverter) Public Function Create() As HtmlToPdfConverter Return New HtmlToPdfConverter With {.LicenseKey = "your-license-key"} End Function Public Function [Return](ByVal obj As HtmlToPdfConverter) As Boolean ' Reset to default state obj.ConversionDelay = 2 Return True End Function End Class End Class $vbLabelText $csharpLabel 错误处理和调试 健壮的错误处理对生产应用程序至关重要: IronPDF 错误处理 public class RobustPdfGenerator { private readonly ILogger<RobustPdfGenerator> _logger; private readonly ChromePdfRenderer _renderer; public async Task<Result<byte[]>> TryGeneratePdfAsync(string html) { try { // Enable detailed logging IronPdf.Logging.Logger.EnableDebugging = true; IronPdf.Logging.Logger.LogFilePath = "ironpdf.log"; IronPdf.Logging.Logger.LoggingLevel = LoggingLevels.All; var pdf = await _renderer.RenderHtmlAsPdfAsync(html); // Validate output if (pdf.PageCount == 0) { return Result<byte[]>.Failure("Generated PDF has no pages"); } return Result<byte[]>.Success(pdf.BinaryData); } catch (IronPdf.Exceptions.IronPdfRenderException ex) { _logger.LogError(ex, "Rendering failed: {Message}", ex.Message); // Attempt fallback with simpler settings return await FallbackRender(html); } catch (Exception ex) { _logger.LogError(ex, "Unexpected error in PDF generation"); return Result<byte[]>.Failure($"PDF generation failed: {ex.Message}"); } } private async Task<Result<byte[]>> FallbackRender(string html) { var fallbackRenderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { EnableJavaScript = false, DPI = 96, Timeout = 60 } }; try { var pdf = await fallbackRenderer.RenderHtmlAsPdfAsync(html); return Result<byte[]>.Success(pdf.BinaryData); } catch (Exception ex) { return Result<byte[]>.Failure($"Fallback render failed: {ex.Message}"); } } } public class RobustPdfGenerator { private readonly ILogger<RobustPdfGenerator> _logger; private readonly ChromePdfRenderer _renderer; public async Task<Result<byte[]>> TryGeneratePdfAsync(string html) { try { // Enable detailed logging IronPdf.Logging.Logger.EnableDebugging = true; IronPdf.Logging.Logger.LogFilePath = "ironpdf.log"; IronPdf.Logging.Logger.LoggingLevel = LoggingLevels.All; var pdf = await _renderer.RenderHtmlAsPdfAsync(html); // Validate output if (pdf.PageCount == 0) { return Result<byte[]>.Failure("Generated PDF has no pages"); } return Result<byte[]>.Success(pdf.BinaryData); } catch (IronPdf.Exceptions.IronPdfRenderException ex) { _logger.LogError(ex, "Rendering failed: {Message}", ex.Message); // Attempt fallback with simpler settings return await FallbackRender(html); } catch (Exception ex) { _logger.LogError(ex, "Unexpected error in PDF generation"); return Result<byte[]>.Failure($"PDF generation failed: {ex.Message}"); } } private async Task<Result<byte[]>> FallbackRender(string html) { var fallbackRenderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { EnableJavaScript = false, DPI = 96, Timeout = 60 } }; try { var pdf = await fallbackRenderer.RenderHtmlAsPdfAsync(html); return Result<byte[]>.Success(pdf.BinaryData); } catch (Exception ex) { return Result<byte[]>.Failure($"Fallback render failed: {ex.Message}"); } } } Public Class RobustPdfGenerator Private ReadOnly _logger As ILogger(Of RobustPdfGenerator) Private ReadOnly _renderer As ChromePdfRenderer Public Async Function TryGeneratePdfAsync(ByVal html As String) As Task(Of Result(Of Byte())) Try ' Enable detailed logging IronPdf.Logging.Logger.EnableDebugging = True IronPdf.Logging.Logger.LogFilePath = "ironpdf.log" IronPdf.Logging.Logger.LoggingLevel = LoggingLevels.All Dim pdf = Await _renderer.RenderHtmlAsPdfAsync(html) ' Validate output If pdf.PageCount = 0 Then Return Result(Of Byte()).Failure("Generated PDF has no pages") End If Return Result(Of Byte()).Success(pdf.BinaryData) Catch ex As IronPdf.Exceptions.IronPdfRenderException _logger.LogError(ex, "Rendering failed: {Message}", ex.Message) ' Attempt fallback with simpler settings Return Await FallbackRender(html) Catch ex As Exception _logger.LogError(ex, "Unexpected error in PDF generation") Return Result(Of Byte()).Failure($"PDF generation failed: {ex.Message}") End Try End Function Private Async Function FallbackRender(ByVal html As String) As Task(Of Result(Of Byte())) Dim fallbackRenderer = New ChromePdfRenderer With { .RenderingOptions = New ChromePdfRenderOptions With { .EnableJavaScript = False, .DPI = 96, .Timeout = 60 } } Try Dim pdf = Await fallbackRenderer.RenderHtmlAsPdfAsync(html) Return Result(Of Byte()).Success(pdf.BinaryData) Catch ex As Exception Return Result(Of Byte()).Failure($"Fallback render failed: {ex.Message}") End Try End Function End Class $vbLabelText $csharpLabel 行业特定的实施示例 金融服务:法规遵从 金融机构需要特定的功能以符合规定: public class FinancialStatementGenerator { public async Task<byte[]> GenerateQuarterlyReport(FinancialData data) { var renderer = new ChromePdfRenderer(); // Generate report with charts and tables var html = await BuildFinancialReportHtml(data); var pdf = renderer.RenderHtmlAsPdf(html); // Add compliance watermark pdf.ApplyWatermark(@" <div style='text-align: center; color: rgba(0,0,0,0.1); font-size: 120px; transform: rotate(-45deg); font-family: Arial;'> DRAFT </div>", 30, VerticalAlignment.Middle, HorizontalAlignment.Center); // Embed audit information pdf.MetaData.Author = "Financial Reporting System"; pdf.MetaData.Keywords = "Quarterly Report, SOX Compliant"; pdf.MetaData.CustomProperties.Add("ReportPeriod", data.Quarter); pdf.MetaData.CustomProperties.Add("GeneratedBy", Environment.UserName); pdf.MetaData.CustomProperties.Add("Timestamp", DateTime.UtcNow.ToString("O")); // Apply tamper-evident signature var cert = new X509Certificate2("financial-cert.pfx", "password"); var signature = new PdfSignature(cert) { SigningReason = "Financial Report Certification", SigningLocation = "Corporate Finance Department", IsVisible = true, SignatureImage = new PdfSignatureImage("cfo-signature.png") }; pdf.Sign(signature); // Lock document from editing pdf.SecuritySettings = new SecuritySettings { AllowModifyDocument = false, AllowCopy = true, AllowPrint = true, EncryptionLevel = EncryptionLevel.AES256Bit }; return pdf.BinaryData; } } public class FinancialStatementGenerator { public async Task<byte[]> GenerateQuarterlyReport(FinancialData data) { var renderer = new ChromePdfRenderer(); // Generate report with charts and tables var html = await BuildFinancialReportHtml(data); var pdf = renderer.RenderHtmlAsPdf(html); // Add compliance watermark pdf.ApplyWatermark(@" <div style='text-align: center; color: rgba(0,0,0,0.1); font-size: 120px; transform: rotate(-45deg); font-family: Arial;'> DRAFT </div>", 30, VerticalAlignment.Middle, HorizontalAlignment.Center); // Embed audit information pdf.MetaData.Author = "Financial Reporting System"; pdf.MetaData.Keywords = "Quarterly Report, SOX Compliant"; pdf.MetaData.CustomProperties.Add("ReportPeriod", data.Quarter); pdf.MetaData.CustomProperties.Add("GeneratedBy", Environment.UserName); pdf.MetaData.CustomProperties.Add("Timestamp", DateTime.UtcNow.ToString("O")); // Apply tamper-evident signature var cert = new X509Certificate2("financial-cert.pfx", "password"); var signature = new PdfSignature(cert) { SigningReason = "Financial Report Certification", SigningLocation = "Corporate Finance Department", IsVisible = true, SignatureImage = new PdfSignatureImage("cfo-signature.png") }; pdf.Sign(signature); // Lock document from editing pdf.SecuritySettings = new SecuritySettings { AllowModifyDocument = false, AllowCopy = true, AllowPrint = true, EncryptionLevel = EncryptionLevel.AES256Bit }; return pdf.BinaryData; } } Public Class FinancialStatementGenerator Public Async Function GenerateQuarterlyReport(ByVal data As FinancialData) As Task(Of Byte()) Dim renderer = New ChromePdfRenderer() ' Generate report with charts and tables Dim html = Await BuildFinancialReportHtml(data) Dim pdf = renderer.RenderHtmlAsPdf(html) ' Add compliance watermark pdf.ApplyWatermark(" <div style='text-align: center; color: rgba(0,0,0,0.1); font-size: 120px; transform: rotate(-45deg); font-family: Arial;'> DRAFT </div>", 30, VerticalAlignment.Middle, HorizontalAlignment.Center) ' Embed audit information pdf.MetaData.Author = "Financial Reporting System" pdf.MetaData.Keywords = "Quarterly Report, SOX Compliant" pdf.MetaData.CustomProperties.Add("ReportPeriod", data.Quarter) pdf.MetaData.CustomProperties.Add("GeneratedBy", Environment.UserName) pdf.MetaData.CustomProperties.Add("Timestamp", DateTime.UtcNow.ToString("O")) ' Apply tamper-evident signature Dim cert = New X509Certificate2("financial-cert.pfx", "password") Dim signature = New PdfSignature(cert) With { .SigningReason = "Financial Report Certification", .SigningLocation = "Corporate Finance Department", .IsVisible = True, .SignatureImage = New PdfSignatureImage("cfo-signature.png") } pdf.Sign(signature) ' Lock document from editing pdf.SecuritySettings = New SecuritySettings With { .AllowModifyDocument = False, .AllowCopy = True, .AllowPrint = True, .EncryptionLevel = EncryptionLevel.AES256Bit } Return pdf.BinaryData End Function End Class $vbLabelText $csharpLabel 电子商务:动态发票生成 电子商务平台需要快速、可靠的发票生成: public class EcommerceInvoiceService { private readonly ChromePdfRenderer _renderer; public EcommerceInvoiceService() { _renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { MarginTop = 10, MarginBottom = 10, PaperSize = PdfPaperSize.A4, DPI = 200 // High quality for barcodes } }; } public async Task<byte[]> GenerateInvoice(Order order) { // Build invoice HTML with order details var html = $@" <html> <head> <style> @page {{ size: A4; margin: 0; }} body {{ font-family: Arial, sans-serif; }} .invoice-header {{ background: #f0f0f0; padding: 20px; }} .barcode {{ text-align: center; margin: 20px 0; }} table {{ width: 100%; border-collapse: collapse; }} th, td {{ padding: 10px; border-bottom: 1px solid #ddd; }} </style> </head> <body> <div class='invoice-header'> <h1>Invoice #{order.InvoiceNumber}</h1> <p>Date: {order.Date:yyyy-MM-dd}</p> </div> <div class='barcode'> <img src='data:image/png;base64,{GenerateBarcode(order.InvoiceNumber)}' /> </div> <table> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> <th>Total</th> </tr> {string.Join("", order.Items.Select(item => $@" <tr> <td>{item.Name}</td> <td>{item.Quantity}</td> <td>${item.Price:F2}</td> <td>${item.Total:F2}</td> </tr>"))} <tr> <td colspan='3'><strong>Total</strong></td> <td><strong>${order.Total:F2}</strong></td> </tr> </table> <div class='footer'> <p>Thank you for your business!</p> <p>Return policy and terms at: www.example.com/terms</p> </div> </body> </html>"; var pdf = await _renderer.RenderHtmlAsPdfAsync(html); // Add QR code for mobile payment verification var qrStamper = new ImageStamper($"https://api.qrserver.com/v1/create-qr-code/?data={order.PaymentId}") { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Width = 100, Height = 100 }; pdf.ApplyStamp(qrStamper); return pdf.BinaryData; } } public class EcommerceInvoiceService { private readonly ChromePdfRenderer _renderer; public EcommerceInvoiceService() { _renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { MarginTop = 10, MarginBottom = 10, PaperSize = PdfPaperSize.A4, DPI = 200 // High quality for barcodes } }; } public async Task<byte[]> GenerateInvoice(Order order) { // Build invoice HTML with order details var html = $@" <html> <head> <style> @page {{ size: A4; margin: 0; }} body {{ font-family: Arial, sans-serif; }} .invoice-header {{ background: #f0f0f0; padding: 20px; }} .barcode {{ text-align: center; margin: 20px 0; }} table {{ width: 100%; border-collapse: collapse; }} th, td {{ padding: 10px; border-bottom: 1px solid #ddd; }} </style> </head> <body> <div class='invoice-header'> <h1>Invoice #{order.InvoiceNumber}</h1> <p>Date: {order.Date:yyyy-MM-dd}</p> </div> <div class='barcode'> <img src='data:image/png;base64,{GenerateBarcode(order.InvoiceNumber)}' /> </div> <table> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> <th>Total</th> </tr> {string.Join("", order.Items.Select(item => $@" <tr> <td>{item.Name}</td> <td>{item.Quantity}</td> <td>${item.Price:F2}</td> <td>${item.Total:F2}</td> </tr>"))} <tr> <td colspan='3'><strong>Total</strong></td> <td><strong>${order.Total:F2}</strong></td> </tr> </table> <div class='footer'> <p>Thank you for your business!</p> <p>Return policy and terms at: www.example.com/terms</p> </div> </body> </html>"; var pdf = await _renderer.RenderHtmlAsPdfAsync(html); // Add QR code for mobile payment verification var qrStamper = new ImageStamper($"https://api.qrserver.com/v1/create-qr-code/?data={order.PaymentId}") { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Width = 100, Height = 100 }; pdf.ApplyStamp(qrStamper); return pdf.BinaryData; } } Public Class EcommerceInvoiceService Private ReadOnly _renderer As ChromePdfRenderer Public Sub New() _renderer = New ChromePdfRenderer With { .RenderingOptions = New ChromePdfRenderOptions With { .MarginTop = 10, .MarginBottom = 10, .PaperSize = PdfPaperSize.A4, .DPI = 200 } } End Sub Public Async Function GenerateInvoice(ByVal order As Order) As Task(Of Byte()) ' Build invoice HTML with order details , order.InvoiceNumbstring.Format(r, order.Date, GenerateBarcode(order.InvoiceNumber), String.Join(TangibleTempVerbatimDoubleQuote, order.Items.Select(Function(item) $TangibleTempVerbatimCloseTag"ignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignore<tr><td>{item.Name}</td><td>{item.Quantity}</td><td>${item.Price:F2}</td><td>${item.Total:F2}</td></tr>")), TangibleStringInterpolationMarker) var html = $"TangibleTempVerbatimOpenTagTangibleTempVerbatimStringLiteralLineJoin <html>TangibleTempVerbatimStringLiteralLineJoin <head>TangibleTempVerbatimStringLiteralLineJoin <style>TangibleTempVerbatimStringLiteralLineJoin @page {{ size: A4; margin: 0; }}TangibleTempVerbatimStringLiteralLineJoin body {{ font-family: Arial, sans-serif; }}TangibleTempVerbatimStringLiteralLineJoin .invoice-header {{ background: #f0f0f0; padding: 20px; }}TangibleTempVerbatimStringLiteralLineJoin .barcode {{ text-align: center; margin: 20px 0; }}TangibleTempVerbatimStringLiteralLineJoin table {{ width: 100%; border-collapse: collapse; }}TangibleTempVerbatimStringLiteralLineJoin th, td {{ padding: 10px; border-bottom: 1px solid #ddd; }}TangibleTempVerbatimStringLiteralLineJoin </style>TangibleTempVerbatimStringLiteralLineJoin </head>TangibleTempVerbatimStringLiteralLineJoin <body>TangibleTempVerbatimStringLiteralLineJoin <div class='invoice-header'>TangibleTempVerbatimStringLiteralLineJoin <h1>Invoice #{0}</h1>TangibleTempVerbatimStringLiteralLineJoin <p>Date: {1:yyyy-MM-dd}</p>TangibleTempVerbatimStringLiteralLineJoin </div>TangibleTempVerbatimStringLiteralLineJoinTangibleTempVerbatimStringLiteralLineJoin <div class='barcode'>TangibleTempVerbatimStringLiteralLineJoin <img src='data:image/png;base64,{2}' />TangibleTempVerbatimStringLiteralLineJoin </div>TangibleTempVerbatimStringLiteralLineJoinTangibleTempVerbatimStringLiteralLineJoin <table>TangibleTempVerbatimStringLiteralLineJoin <tr>TangibleTempVerbatimStringLiteralLineJoin <th>Item</th>TangibleTempVerbatimStringLiteralLineJoin <th>Quantity</th>TangibleTempVerbatimStringLiteralLineJoin <th>Price</th>TangibleTempVerbatimStringLiteralLineJoin <th>Total</th>TangibleTempVerbatimStringLiteralLineJoin </tr>TangibleTempVerbatimStringLiteralLineJoin {3}ignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignoreignore<tr><td colspan='3'><strong>Total</strong></td><td><strong>${order.Total:F2}</strong></td></tr></table><div class='footer'><p>Thank you for your business!</p><p>Return policy and terms at: www.example.com/terms</p></div></body></html>" Dim pdf = Await _renderer.RenderHtmlAsPdfAsync(html) ' Add QR code for mobile payment verification Dim qrStamper = New ImageStamper($"https://api.qrserver.com/v1/create-qr-code/?data={order.PaymentId}") With { .HorizontalAlignment = HorizontalAlignment.Right, .VerticalAlignment = VerticalAlignment.Bottom, .Width = 100, .Height = 100 } pdf.ApplyStamp(qrStamper) Return pdf.BinaryData End Function End Class $vbLabelText $csharpLabel 迁移策略:在库之间切换 如果您考虑在库之间切换,这里有一个迁移方法: 从 EvoPdf 迁移到 IronPDF // EvoPdf pattern HtmlToPdfConverter evoPdfConverter = new HtmlToPdfConverter(); evoPdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; byte[] pdfBytes = evoPdfConverter.ConvertUrl(url); // Equivalent IronPDF pattern var ironPdfRenderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { PaperSize = PdfPaperSize.A4 } }; var pdf = ironPdfRenderer.RenderUrlAsPdf(url); byte[] pdfBytes = pdf.BinaryData; // Migration wrapper for gradual transition public interface IPdfConverter { byte[] ConvertHtmlToPdf(string html); byte[] ConvertUrlToPdf(string url); } public class IronPdfAdapter : IPdfConverter { private readonly ChromePdfRenderer _renderer = new ChromePdfRenderer(); public byte[] ConvertHtmlToPdf(string html) { return _renderer.RenderHtmlAsPdf(html).BinaryData; } public byte[] ConvertUrlToPdf(string url) { return _renderer.RenderUrlAsPdf(url).BinaryData; } } public class EvoPdfAdapter : IPdfConverter { private readonly HtmlToPdfConverter _converter = new HtmlToPdfConverter(); public byte[] ConvertHtmlToPdf(string html) { return _converter.ConvertHtml(html, ""); } public byte[] ConvertUrlToPdf(string url) { return _converter.ConvertUrl(url); } } // EvoPdf pattern HtmlToPdfConverter evoPdfConverter = new HtmlToPdfConverter(); evoPdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; byte[] pdfBytes = evoPdfConverter.ConvertUrl(url); // Equivalent IronPDF pattern var ironPdfRenderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { PaperSize = PdfPaperSize.A4 } }; var pdf = ironPdfRenderer.RenderUrlAsPdf(url); byte[] pdfBytes = pdf.BinaryData; // Migration wrapper for gradual transition public interface IPdfConverter { byte[] ConvertHtmlToPdf(string html); byte[] ConvertUrlToPdf(string url); } public class IronPdfAdapter : IPdfConverter { private readonly ChromePdfRenderer _renderer = new ChromePdfRenderer(); public byte[] ConvertHtmlToPdf(string html) { return _renderer.RenderHtmlAsPdf(html).BinaryData; } public byte[] ConvertUrlToPdf(string url) { return _renderer.RenderUrlAsPdf(url).BinaryData; } } public class EvoPdfAdapter : IPdfConverter { private readonly HtmlToPdfConverter _converter = new HtmlToPdfConverter(); public byte[] ConvertHtmlToPdf(string html) { return _converter.ConvertHtml(html, ""); } public byte[] ConvertUrlToPdf(string url) { return _converter.ConvertUrl(url); } } ' EvoPdf pattern Dim evoPdfConverter As New HtmlToPdfConverter() evoPdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4 Dim pdfBytes() As Byte = evoPdfConverter.ConvertUrl(url) ' Equivalent IronPDF pattern Dim ironPdfRenderer = New ChromePdfRenderer With { .RenderingOptions = New ChromePdfRenderOptions With {.PaperSize = PdfPaperSize.A4} } Dim pdf = ironPdfRenderer.RenderUrlAsPdf(url) Dim pdfBytes() As Byte = pdf.BinaryData ' Migration wrapper for gradual transition 'INSTANT VB TODO TASK: Local functions are not converted by Instant VB: 'public interface IPdfConverter '{ ' byte[] ConvertHtmlToPdf(string html); ' byte[] ConvertUrlToPdf(string url); '} 'INSTANT VB TODO TASK: Local functions are not converted by Instant VB: 'public class IronPdfAdapter : IPdfConverter '{ ' private readonly ChromePdfRenderer _renderer = New ChromePdfRenderer(); ' ' public byte[] ConvertHtmlToPdf(string html) ' { ' Return _renderer.RenderHtmlAsPdf(html).BinaryData; ' } ' ' public byte[] ConvertUrlToPdf(string url) ' { ' Return _renderer.RenderUrlAsPdf(url).BinaryData; ' } '} 'INSTANT VB TODO TASK: Local functions are not converted by Instant VB: 'public class EvoPdfAdapter : IPdfConverter '{ ' private readonly HtmlToPdfConverter _converter = New HtmlToPdfConverter(); ' ' public byte[] ConvertHtmlToPdf(string html) ' { ' Return _converter.ConvertHtml(html, ""); ' } ' ' public byte[] ConvertUrlToPdf(string url) ' { ' Return _converter.ConvertUrl(url); ' } '} $vbLabelText $csharpLabel 结论:为您的项目做出正确选择 IronPDF 和 EvoPdf 都在 .NET PDF 库生态系统中起着重要作用,但它们针对的是不同的用例和开发理念。 选择 IronPDF 当您需要: 现代网络标准支持 (CSS3, JavaScript 框架) 不仅仅是生成的综合 PDF 操作 企业安全功能和合规工具 跨平台部署灵活性 完整的文档和直接的工程支持 与其他文档处理工具的集成 选择 EvoPdf 当您需要: 以较低成本的简单 HTML 到 PDF 转换 针对简单文档的基础 PDF 生成 大团队的无限开发者许可证 更快地处理简单的 HTML 内容 以 Windows 为中心的部署环境 最终的决定取决于您的具体需求、预算限制和长期的可扩展性需求。 对于大多数需要强大 PDF 功能的现代应用程序,IronPDF 的综合功能集和卓越的渲染引擎证明了投资的合理性。 然而,对于成本为主要关注的简单用例,EvoPdf 仍然是一个可行的选择。 Consider starting with the 30-day free trial of IronPDF to evaluate its capabilities in your specific use case. 该试用包括所有功能且无任何限制,使您能够根据实际性能做出明智的决定。 请记住,PDF 库的真实成本不仅限于许可证价格—还需考虑开发时间、维护开销和随着应用程序的增长可能需要的额外功能。 选择不仅能满足您当前需求还能随着您未来需求扩展的库。 [{i:(EvoPdf 是其各自所有者的注册商标。 此站点与 EvoPdf 无关、未被其认可或赞助。 所有产品名称、徽标和品牌均为其各自所有者的财产。 比较仅供参考,反映的是撰写时的公开信息。] 常见问题解答 如何在 C# 中使用 .NET 库将 HTML 转换为 PDF? 你可以使用IronPDF的RenderHtmlAsPdf方法将HTML字符串转换为PDF。你还可以使用RenderHtmlFileAsPdf将HTML文件转换为PDF。 哪个是处理复杂 JavaScript 和 CSS 的最佳 .NET PDF 库? IronPDF 是处理复杂 JavaScript 和 CSS 的最佳选择,因为它使用完整的 Chrome V8 渲染引擎,提供 98% 以上的浏览器保真度,并支持像 React 和 Angular 这样的现代框架。 哪个 .NET PDF 库提供更好的跨平台支持? IronPDF 提供卓越的跨平台支持,具有针对 Windows、Linux、macOS 和 Docker 容器的原生兼容性,允许零配置部署。 IronPDF 的安全性和合规性关键功能是什么? IronPDF 提供全面的安全特性,包括 AES-256 加密、15+ 细粒度权限设置、可视化数字签名,以及通过 RedactTextOnAllPages() 方法实现真正的内容编辑。 如何在 .NET 中高效地进行批量 PDF 处理? IronPDF 在批量 PDF 处理方面表现出色,通过提供原生异步/等待优化和更好的内存管理,使其适合高效处理大型文档。 哪个库为开发人员提供更好的支持和文档? IronPDF 提供广泛的支持和文档,包括 24/5 工程支持、全面的 API 文档、100+ 代码示例和视频教程,显著减少了开发时间。 我可以使用 .NET 库将 DOCX 文件转换为 PDF 吗? 可以,IronPDF 包含通过其 DocxToPdfRenderer 类的内置 DOCX 到 PDF 转换,使您能够在保留格式的情况下转换 Word 文档。 使用 IronPDF 进行现代 Web 应用程序的优势是什么? IronPDF 适合现代 Web 应用程序,因为其基于 Chrome 的渲染引擎,全面的 PDF 操作功能,和跨平台兼容性,适用于动态内容生成和复杂文档处理。 IronPDF 如何处理符合合规性要求的 PDF 编辑? IronPDF 提供全面的编辑功能,包括基于正则表达式的内容删除和基于 OCR 的编辑,确保符合 GDPR 和 HIPAA 等隐私法规。 IronPDF 对于 SaaS 和电子商务平台来说有什么好处? IronPDF 非常适合 SaaS 和电子商务平台,因为它能够生成动态发票,支持数字签名,并提供与现代表现技术的无缝集成。 Jacob Mellor 立即与工程团队聊天 首席技术官 Jacob Mellor 是 Iron Software 的首席技术官,是 C# PDF 技术的先锋工程师。作为 Iron Software 核心代码库的原始开发者,自公司成立以来,他就塑造了公司的产品架构,并与首席执行官 Cameron Rimington 一起将其转变成一家公司,拥有50多人,服务于 NASA、特斯拉和全球政府机构。Jacob 拥有曼彻斯特大学 (1998-2001) 的一级荣誉土木工程学士学位。1999 年在伦敦创办了自己的第一家软件公司,并于 2005 年创建了他的第一个 .NET 组件后,他专注于解决微软生态系统中的复杂问题。他的旗舰 IronPDF 和 IronSuite .NET 库在全球已获得超过 3000 万次的 NuGet 安装,其基础代码继续为全球使用的开发者工具提供支持。拥有 25 年商业经验和 41 年编程经验的 Jacob 仍专注于推动企业级 C#、Java 和 Python PDF 技术的创新,同时指导下一代技术领导者。 相关文章 已发布十一月 13, 2025 比较 C# HTML 到 PDF 开源与 IronPDF 比较开源 HTML 到 PDF 库与 IronPDF for C#。发现哪个解决方案为您的 .NET 项目提供最佳的 PDF 生成能力。 阅读更多 已发布十月 27, 2025 哪种 ASP.NET Core PDF 库性价比最高? 发现适合ASP.NET Core应用程序的最佳PDF库。比较IronPDF的Chrome引擎与Aspose和Syncfusion的替代品。 阅读更多 已发布十月 27, 2025 如何使用 Aspose C# 与 IronPDF 创作 PDF 通过此逐步指南,学习如何使用 Aspose C# 与 IronPDF 创建 PDF,专为开发人员设计。 阅读更多 IronPDF与SelectPdf:完整.NET Core PDF库比较用于HTML到PDF转换iTextSharp C# HTML到PDF替代方...
已发布十一月 13, 2025 比较 C# HTML 到 PDF 开源与 IronPDF 比较开源 HTML 到 PDF 库与 IronPDF for C#。发现哪个解决方案为您的 .NET 项目提供最佳的 PDF 生成能力。 阅读更多
已发布十月 27, 2025 哪种 ASP.NET Core PDF 库性价比最高? 发现适合ASP.NET Core应用程序的最佳PDF库。比较IronPDF的Chrome引擎与Aspose和Syncfusion的替代品。 阅读更多
已发布十月 27, 2025 如何使用 Aspose C# 与 IronPDF 创作 PDF 通过此逐步指南,学习如何使用 Aspose C# 与 IronPDF 创建 PDF,专为开发人员设计。 阅读更多