如何用 C# 從 SAP Crystal Reports 轉移到 IronPDF
從SAP Crystal Reports轉移到IronPDF可將您的報表工作流程從具有複雜部署需求的重量級傳統平台轉換為現代化、輕量級的NuGet套件。 本指南提供完整的逐步遷移路徑,可省去 500MB 以上的龐大執行時安裝,消除 SAP 生態系統的鎖定,並實現完整的 .NET Core/5/6/7/8+ 支援。
為什麼要從SAP Crystal Reports遷移到 IronPDF?
瞭解 SAP Crystal Reports
SAP Crystal Reports 在企業領域中脫穎而出,是一種可產生動態且"像素完美"報表的工具。SAP Crystal Reports以其連結多種資料來源的能力而聞名,一直是許多企業尋求全面報表功能的最佳解決方案。 該平台透過 Crystal Reports Designer 提供無與倫比的功能,此工具可簡化複雜報表佈局的建構。
然而,隨著技術的發展,SAP Crystal Reports 對 SAP 架構的高度依賴,以及其嚴苛的安裝和部署要求也不能不引起注意。 重量級的性質意味著企業通常需要大量的資源和時間才能完全實施和維護系統。
遷移的主要原因
1.安裝過程龐大: Crystal Reports 運行時庫大小超過 500MB,安裝過程較為複雜。
- SAP生態系鎖定:受制於SAP的定價、支援週期及產品路線圖 3.複雜的授權模式:採用 SAP 企業銷售流程的按處理器/按使用者授權模式 4.傳統架構: 32 位元 COM 相依性使現代 64 位元部署變得複雜 5.已棄用對 .NET Core 的支援:對現代 .NET 平台的支援有限 6.報表設計器相依性:需要 Visual Studio 擴充或獨立設計器 7.效能緩慢:運行時初始化耗時過長,記憶體佔用過高。
SAP Crystal Reports的隱藏成本
| 成本因素 | SAP Crystal Reports | IronPDF |
|---|---|---|
| 運行時間大小 | 500MB+ | 約20MB |
| 安裝 | 複雜的 MSI/安裝 | NuGet 套件 |
| 部署 | 特殊安裝程式 | xcopy |
| 64 位元支援 | 問題 | 原生語言 |
| .NET Core/5/6/7/8 | 限額 | 支援 |
| 雲端部署 | 難度 | 簡單的 |
| Linux/Docker | 無 | 是 |
SAP Crystal Reports與IronPDF比較。
| 特點 | SAP Crystal Reports | IronPDF |
|---|---|---|
| 主要功能 | 企業報告平台 | HTML 到 PDF 的轉換引擎和 PDF 操作 |
| 整合。 | SAP 生態系統內最佳 | 現代 .NET 整合,輕量級NuGet套件 |
| 易用性 | 複雜的設定與部署 | 簡化整合,支援 .NET 開發人員 |
| 報表設計師 | 要求 | 可選 (HTML/CSS) |
| 範本格式 | .rpt (二進位) | HTML/CSS |
| HTML至PDF | 無 | 完整的 Chromium |
| URL轉PDF | 無 | 是 |
| CSS 支援 | 無 | 完整的 CSS3 |
| JavaScript。 | 無 | 完整的 ES2024 |
| PDF 操作 | 無 | 完整(合併、分割、編輯) |
| 數位簽名 | 無 | 是 |
| PDF/A合規性 | 無 | 是 |
| 現代相關性 | 日漸式微,被現代替代品取代 | 現代化,與當代技術完美結合 |
對於計劃在 2025 年和 2026 年之前採用 .NET 10 和 C# 14 的團隊而言,IronPDF 可提供SAP Crystal Reports無法提供的原生跨平台支援。
開始之前
先決條件
- .NET環境:.NET Framework4.6.2+ 或.NET Core 3.1+ / .NET 5/6/7/8/9+
- NuGet存取權限:能夠安裝NuGet套件
- IronPDF許可證:請從IronPDF取得您的許可證密鑰。
NuGet套件變更
# Remove Crystal Reports packages
dotnet remove package CrystalDecisions.CrystalReports.Engine
dotnet remove package CrystalDecisions.Shared
dotnet remove package CrystalDecisions.ReportAppServer
dotnet remove package CrystalDecisions.Web
# Remove legacy assemblies from project references
# Install IronPDF
dotnet add package IronPdf
# Remove Crystal Reports packages
dotnet remove package CrystalDecisions.CrystalReports.Engine
dotnet remove package CrystalDecisions.Shared
dotnet remove package CrystalDecisions.ReportAppServer
dotnet remove package CrystalDecisions.Web
# Remove legacy assemblies from project references
# Install IronPDF
dotnet add package IronPdf
授權組態
// Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
完整的 API 參考資料
命名空間變更
// Before: SAP Crystal Reports
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportAppServer;
// After: IronPDF
using IronPdf;
// Before: SAP Crystal Reports
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportAppServer;
// After: IronPDF
using IronPdf;
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportAppServer
Imports IronPdf
核心 API 對應
| SAP Crystal Reports | IronPDF | 筆記 |
|---|---|---|
ReportDocument |
ChromePdfRenderer |
核心渲染 |
ReportDocument.Load() |
RenderHtmlAsPdf() |
載入內容 |
.rpt 文件 |
HTML/CSS 範本 | 範本格式 |
SetDataSource() |
包含資料的 HTML | 資料綁定 |
SetParameterValue() |
字串插值 | 參數 |
ExportToDisk() |
pdf.SaveAs() |
儲存檔案 |
ExportToStream() |
pdf.BinaryData |
取得 bytes |
PrintToPrinter() |
pdf.Print() |
印刷 |
Database.Tables |
C# 資料存取 | 資料來源 |
FormulaFieldDefinitions |
C# 邏輯 | 計算 |
SummaryInfo |
pdf.MetaData |
PDF 元資料 |
ExportFormatType.PortableDocFormat |
預設輸出 | PDF 原生語言 |
程式碼遷移範例
範例 1:HTML 到 PDF 的轉換
之前 (SAP Crystal Reports):
// NuGet: Install-Package CrystalReports.Engine
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
class Program
{
static void Main()
{
// Crystal Reports requires a .rpt file template
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load("Report.rpt");
// Crystal Reports doesn't directly support HTML
// You need to bind data to the report template
// reportDocument.SetDataSource(dataSet);
ExportOptions exportOptions = reportDocument.ExportOptions;
exportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
DiskFileDestinationOptions diskOptions = new DiskFileDestinationOptions();
diskOptions.DiskFileName = "output.pdf";
exportOptions.DestinationOptions = diskOptions;
reportDocument.Export();
reportDocument.Close();
reportDocument.Dispose();
}
}
// NuGet: Install-Package CrystalReports.Engine
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
class Program
{
static void Main()
{
// Crystal Reports requires a .rpt file template
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load("Report.rpt");
// Crystal Reports doesn't directly support HTML
// You need to bind data to the report template
// reportDocument.SetDataSource(dataSet);
ExportOptions exportOptions = reportDocument.ExportOptions;
exportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
DiskFileDestinationOptions diskOptions = new DiskFileDestinationOptions();
diskOptions.DiskFileName = "output.pdf";
exportOptions.DestinationOptions = diskOptions;
reportDocument.Export();
reportDocument.Close();
reportDocument.Dispose();
}
}
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System
Class Program
Shared Sub Main()
' Crystal Reports requires a .rpt file template
Dim reportDocument As New ReportDocument()
reportDocument.Load("Report.rpt")
' Crystal Reports doesn't directly support HTML
' You need to bind data to the report template
' reportDocument.SetDataSource(dataSet)
Dim exportOptions As ExportOptions = reportDocument.ExportOptions
exportOptions.ExportDestinationType = ExportDestinationType.DiskFile
exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
Dim diskOptions As New DiskFileDestinationOptions()
diskOptions.DiskFileName = "output.pdf"
exportOptions.DestinationOptions = diskOptions
reportDocument.Export()
reportDocument.Close()
reportDocument.Dispose()
End Sub
End Class
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
// Create a PDF from HTML string
var renderer = new ChromePdfRenderer();
string htmlContent = "<h1>Hello World</h1><p>This is a PDF generated from HTML.</p>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully!");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
// Create a PDF from HTML string
var renderer = new ChromePdfRenderer();
string htmlContent = "<h1>Hello World</h1><p>This is a PDF generated from HTML.</p>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully!");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
' Create a PDF from HTML string
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "<h1>Hello World</h1><p>This is a PDF generated from HTML.</p>"
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF created successfully!")
End Sub
End Class
本範例展示了基本的範式差異。SAP Crystal Reports需要一個預先設計的 .rpt 檔案模板,該模板在 Crystal Reports Designer 中創建,然後您必須配置 @@--CODE-19774--@@、@@--CODE-19775--@@、@@--CODE-19776--@@ 和 @@--CODE-19777--@@。 該函式庫不直接支援 HTML 內容 - 您必須將資料綁定到報告範本。
IronPDF 直接接受 HTML 字串:建立一個 ChromePdfRenderer,使用任何 HTML 內容呼叫 RenderHtmlAsPdf(),以及 SaveAs()。 不需要設計師、不需要二進位範本、不需要複雜的匯出設定。 請參閱 HTML to PDF 文件,以瞭解全面的範例。
範例 2:URL 到 PDF 的轉換
之前 (SAP Crystal Reports):
// NuGet: Install-Package CrystalReports.Engine
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
using System.Net;
class Program
{
static void Main()
{
// Crystal Reports cannot directly convert URLs to PDF
// You need to create a report template first
// Download HTML content
WebClient client = new WebClient();
string htmlContent = client.DownloadString("https://example.com");
// Crystal Reports requires .rpt template and data binding
// This approach is not straightforward for URL conversion
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load("WebReport.rpt");
// Manual data extraction and binding required
// reportDocument.SetDataSource(extractedData);
reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "output.pdf");
reportDocument.Close();
reportDocument.Dispose();
}
}
// NuGet: Install-Package CrystalReports.Engine
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
using System.Net;
class Program
{
static void Main()
{
// Crystal Reports cannot directly convert URLs to PDF
// You need to create a report template first
// Download HTML content
WebClient client = new WebClient();
string htmlContent = client.DownloadString("https://example.com");
// Crystal Reports requires .rpt template and data binding
// This approach is not straightforward for URL conversion
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load("WebReport.rpt");
// Manual data extraction and binding required
// reportDocument.SetDataSource(extractedData);
reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "output.pdf");
reportDocument.Close();
reportDocument.Dispose();
}
}
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System
Imports System.Net
Module Program
Sub Main()
' Crystal Reports cannot directly convert URLs to PDF
' You need to create a report template first
' Download HTML content
Dim client As New WebClient()
Dim htmlContent As String = client.DownloadString("https://example.com")
' Crystal Reports requires .rpt template and data binding
' This approach is not straightforward for URL conversion
Dim reportDocument As New ReportDocument()
reportDocument.Load("WebReport.rpt")
' Manual data extraction and binding required
' reportDocument.SetDataSource(extractedData)
reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "output.pdf")
reportDocument.Close()
reportDocument.Dispose()
End Sub
End Module
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
// Create a PDF from a URL
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created from URL successfully!");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
// Create a PDF from a URL
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created from URL successfully!");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
' Create a PDF from a URL
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF created from URL successfully!")
End Sub
End Class
SAP Crystal Reports 無法直接將 URL 轉換為 PDF。 您需要使用 WebClient 手動下載 HTML 內容,然後以某種方式提取該資料並將其綁定到預先設計的 .rpt 模板——這是一個不直接的過程,需要大量的手動工作。
IronPDF 的 RenderUrlAsPdf() 方法只需一次呼叫即可擷取包含所有 CSS、JavaScript 和影像的完整渲染網頁。 請參閱我們的 教學,瞭解更多資訊。
範例 3:帶有頁碼的頁首和頁尾
之前 (SAP Crystal Reports):
// NuGet: Install-Package CrystalReports.Engine
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
class Program
{
static void Main()
{
// Crystal Reports requires design-time configuration
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load("Report.rpt");
// Headers and footers must be designed in the .rpt file
// using Crystal Reports designer
// You can set parameter values programmatically
reportDocument.SetParameterValue("HeaderText", "Company Name");
reportDocument.SetParameterValue("FooterText", "Page ");
// Crystal Reports handles page numbers through formula fields
// configured in the designer
reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "output.pdf");
reportDocument.Close();
reportDocument.Dispose();
}
}
// NuGet: Install-Package CrystalReports.Engine
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
class Program
{
static void Main()
{
// Crystal Reports requires design-time configuration
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load("Report.rpt");
// Headers and footers must be designed in the .rpt file
// using Crystal Reports designer
// You can set parameter values programmatically
reportDocument.SetParameterValue("HeaderText", "Company Name");
reportDocument.SetParameterValue("FooterText", "Page ");
// Crystal Reports handles page numbers through formula fields
// configured in the designer
reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "output.pdf");
reportDocument.Close();
reportDocument.Dispose();
}
}
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System
Class Program
Shared Sub Main()
' Crystal Reports requires design-time configuration
Dim reportDocument As New ReportDocument()
reportDocument.Load("Report.rpt")
' Headers and footers must be designed in the .rpt file
' using Crystal Reports designer
' You can set parameter values programmatically
reportDocument.SetParameterValue("HeaderText", "Company Name")
reportDocument.SetParameterValue("FooterText", "Page ")
' Crystal Reports handles page numbers through formula fields
' configured in the designer
reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "output.pdf")
reportDocument.Close()
reportDocument.Dispose()
End Sub
End Class
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
// Configure headers and footers
renderer.RenderingOptions.TextHeader.CenterText = "Company Name";
renderer.RenderingOptions.TextHeader.FontSize = 12;
renderer.RenderingOptions.TextFooter.LeftText = "Confidential";
renderer.RenderingOptions.TextFooter.RightText = "Page {page} of {total-pages}";
renderer.RenderingOptions.TextFooter.FontSize = 10;
string htmlContent = "<h1>Document Title</h1><p>Document content goes here.</p>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF with headers and footers created!");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
// Configure headers and footers
renderer.RenderingOptions.TextHeader.CenterText = "Company Name";
renderer.RenderingOptions.TextHeader.FontSize = 12;
renderer.RenderingOptions.TextFooter.LeftText = "Confidential";
renderer.RenderingOptions.TextFooter.RightText = "Page {page} of {total-pages}";
renderer.RenderingOptions.TextFooter.FontSize = 10;
string htmlContent = "<h1>Document Title</h1><p>Document content goes here.</p>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF with headers and footers created!");
}
}
Imports IronPdf
Imports System
Module Program
Sub Main()
Dim renderer As New ChromePdfRenderer()
' Configure headers and footers
renderer.RenderingOptions.TextHeader.CenterText = "Company Name"
renderer.RenderingOptions.TextHeader.FontSize = 12
renderer.RenderingOptions.TextFooter.LeftText = "Confidential"
renderer.RenderingOptions.TextFooter.RightText = "Page {page} of {total-pages}"
renderer.RenderingOptions.TextFooter.FontSize = 10
Dim htmlContent As String = "<h1>Document Title</h1><p>Document content goes here.</p>"
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF with headers and footers created!")
End Sub
End Module
SAP Crystal Reports 需要在設計時設定頁首和頁尾。 您必須使用 Crystal Reports Designer 在 .rpt 檔案中設計它們,然後在執行時間傳遞參數值,例如 "HeaderText" 和 "FooterText"。頁碼必須透過設計器中的公式欄位進行配置。
IronPDF 提供程式化的頁首/頁尾配置,具有 TextHeader 和 TextFooter 屬性。 直接在程式碼中設定 CenterText、LeftText、RightText 和 FontSize。 頁碼使用 {page} 和 {total-pages} 佔位符-無需設計師。
常見的遷移問題
問題 1:.rpt 檔案轉換
SAP Crystal Reports:內嵌版面、資料、公式的二進位 .rpt 檔案。
解決方案:無法直接轉換 - 必須重新製作成 HTML: 1.在 Crystal Reports 設計器中開啟 .rpt 2.文件排版、字型、顏色 3.請注意所有公式欄位 4.以HTML/CSS重製 5.將公式轉換為 C# 程式碼
第 2 期:資料庫連線
SAP Crystal Reports: 內嵌連接字串和 ODBC。
解決方案:使用您應用程式的資料層:
// Instead of Crystal's database integration
var data = await _dbContext.Orders
.Where(o => o.Date >= startDate && o.Date <= endDate)
.ToListAsync();
// Bind to HTML template
var html = GenerateReportHtml(data);
// Instead of Crystal's database integration
var data = await _dbContext.Orders
.Where(o => o.Date >= startDate && o.Date <= endDate)
.ToListAsync();
// Bind to HTML template
var html = GenerateReportHtml(data);
Option Strict On
' Instead of Crystal's database integration
Dim data = Await _dbContext.Orders _
.Where(Function(o) o.Date >= startDate AndAlso o.Date <= endDate) _
.ToListAsync()
' Bind to HTML template
Dim html = GenerateReportHtml(data)
問題 3:運行時依賴性
SAP Crystal Reports: 需要安裝 Crystal Reports Runtime (500MB以上)。
解決方案:IronPDF是自成一格的:
# Just add theNuGetpackage
dotnet add package IronPdf
# That's it - no additional installs needed
# Just add theNuGetpackage
dotnet add package IronPdf
# That's it - no additional installs needed
第 4 期:32 位元/64 位元問題
SAP Crystal Reports: COM 依賴通常需要 32 位元模式。
解決方案:IronPDF為原生 64 位元,無需特殊設定。
遷移後的新功能
遷移到IronPDF之後,您可以獲得SAP Crystal Reports無法提供的功能:
PDF 合併
var pdf1 = PdfDocument.FromFile("report1.pdf");
var pdf2 = PdfDocument.FromFile("report2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("complete_report.pdf");
var pdf1 = PdfDocument.FromFile("report1.pdf");
var pdf2 = PdfDocument.FromFile("report2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("complete_report.pdf");
Dim pdf1 = PdfDocument.FromFile("report1.pdf")
Dim pdf2 = PdfDocument.FromFile("report2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("complete_report.pdf")
PDF安全性
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(reportHtml);
pdf.MetaData.Title = "Quarterly Sales Report";
pdf.MetaData.Author = "Finance Department";
pdf.SecuritySettings.OwnerPassword = "admin123";
pdf.SecuritySettings.UserPassword = "view123";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SaveAs("secure_report.pdf");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(reportHtml);
pdf.MetaData.Title = "Quarterly Sales Report";
pdf.MetaData.Author = "Finance Department";
pdf.SecuritySettings.OwnerPassword = "admin123";
pdf.SecuritySettings.UserPassword = "view123";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SaveAs("secure_report.pdf");
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(reportHtml)
pdf.MetaData.Title = "Quarterly Sales Report"
pdf.MetaData.Author = "Finance Department"
pdf.SecuritySettings.OwnerPassword = "admin123"
pdf.SecuritySettings.UserPassword = "view123"
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SaveAs("secure_report.pdf")
數位簽名
var signature = new PdfSignature("certificate.pfx", "password");
pdf.Sign(signature);
var signature = new PdfSignature("certificate.pfx", "password");
pdf.Sign(signature);
Dim signature = New PdfSignature("certificate.pfx", "password")
pdf.Sign(signature)
水印。
pdf.ApplyWatermark("<h1 style='color:red; opacity:0.3;'>DRAFT</h1>");
pdf.ApplyWatermark("<h1 style='color:red; opacity:0.3;'>DRAFT</h1>");
IRON VB CONVERTER ERROR developers@ironsoftware.com
功能比較摘要
| 特點 | SAP Crystal Reports | IronPDF | |||
|---|---|---|---|---|---|
| :安裝: | 運行時間大小 | 500MB+ | 約20MB | ||
| 安裝方法 | MSI/Setup.exe | NuGet | |||
| 部署 | 複雜的 | xcopy | |||
| 平台支援: | .NET Framework | 是 | 是 | ||
| .NET Core/5/6/7/8 | 限額 | 全文 | |||
| 64 位元原生 | 問題 | 是 | |||
| Linux/Docker | 無 | 是 | |||
| Azure/AWS | 難度 | 簡單的 | |||
| :發展: | 報表設計師 | 要求 | 可選 (HTML) | ||
| 範本格式 | .rpt (二進位) | HTML/CSS | |||
| 學習曲線 | 水晶語法 | 網頁標準 | |||
| IntelliSense | 無 | 完整 C# | |||
| 渲染: | HTML 至 PDF | 無 | 完整的 Chromium | ||
| URL 至 PDF | 無 | 是 | |||
| CSS 支援 | 無 | 完整的 CSS3 | |||
| JavaScript | 無 | 完整的 ES2024 | |||
| PDF 功能: | 合併 PDF | 無 | 是 | ||
| 分割 PDF | 無 | 是 | |||
| 水印 | 限額 | 完整 HTML | |||
| 數位簽名 | 無 | 是 | |||
| PDF/A | 無 | 是 |
遷移清單
預遷移
- 清點所有
.rpt文件 - 截取每份報告版面的螢幕截圖以供參考
- 文檔公式欄位和計算 列出所有資料來源和參數
- 確定列印要求
- 從ironpdf.com取得IronPDF許可證金鑰
程式碼更新
- 移除 Crystal Reports 軟體套件(
CrystalDecisions.CrystalReports.Engine等) - 從部署中移除執行時間安裝
安裝
IronPdfNuGet套件 將.rpt佈局轉換為HTML/CSS模板 - 將 Crystal 公式轉換為 C# 程式碼
- 將資料綁定從
SetDataSource()更新為 HTML 字串插值 - 將列印代碼從
PrintToPrinter()更新為pdf.Print() - 在應用程式啟動時新增許可證初始化
基礎架構
從伺服器移除 Crystal Runtime
- 更新部署腳本
- 移除 32 位元相容模式
- 更新 Docker 映像(如適用)
測試
- 將 PDF 輸出與原始報告進行比較
- 核對所有計算結果。
- 測試所有參數
- 測試列印功能
- 效能測試
- 64 位元測試

