跳至页脚内容
产品比较

CraftMyPDF vs IronPDF:C#开发者应该选择哪个PDF生成库?

IronPDF 提供代码优先的 HTML 到 PDF 转换,支持完整的 CSS/JavaScript,永久许可价格为 749 美元起;而 CraftMyPDF 提供基于云的模板设计,集成了 JSON,但需要持续订阅和 API 依赖。

CraftMyPDF 提供了一个基于云的拖放式模板设计器,并集成了 JSON 数据;而IronPDF则为寻求完全控制文档生成的 .NET 开发人员提供了代码优先的HTML 到 PDF 转换功能,并提供了完整的 CSS/JavaScript 支持。

PDF(可移植文档格式)是由 Adobe 开发的一种用于文档交换的文件格式。 它能在不同设备上保留格式、字体和图片,确保外观一致。 PDF 支持安全功能、交互性和压缩功能,使其成为可靠文档共享的理想选择。

C# PDF 库使开发人员能够通过编程方式创建修改 PDF 文件以及从中提取内容。 这些工具支持表单处理数字签名跨平台部署。 通过集成 PDF 库,开发人员可直接在应用程序中添加文档生成功能,从而简化 PDF创建编辑和管理工作流程。

本文对比了两种不同的 PDF 生成方案:IronPDF C# 库Craftmypdf API。 本对比分析涵盖功能介绍、代码示例以及许可选项的讨论。

什么是 CraftMyPDF API 基础解决方案?

CraftMyPDF 主页展示了拖放式 PDF 编辑器界面,其中正在实时编辑装箱单模板。

CraftMyPDF 是一款基于云的 API,用于通过模板创建 PDF 文件。 它提供了一个基于 Web 的拖放式编辑器,用于设计无需编码即可重复使用的模板。 该平台通过将这些模板与 JSON 数据合并来生成 PDF,支持发票报告和证书等文档的动态内容生成。

CraftMyPDF 的主要特性是什么?

  1. 拖放编辑器:无需编码知识即可使用的可视化模板设计工具。

  2. 模板复用性:只需设计一次,即可针对不同的数据集反复使用。

  3. JSON 数据集成:通过 JSON 将动态数据与模板进行合并。

  4. 高级格式化和表达式:动态格式化日期、数字和货币。

  5. API 集成:REST API 支持 Zapier、Make.com 以及自定义应用程序。

  6. 可填写组件:创建包含文本框和复选框的交互式表单

  7. 安全与合规:通过区域 API 端点保障 PDF 访问安全,并符合 GDPR 合规要求。

什么是 IronPDF?

IronPDF PDF Library 适用于 .NET Developers 是一款面向 .NET 应用程序的完整 PDF 库。 该工具采用 C# 编写,能够从 HTMLCSSJavaScript图像生成像素级精确的 PDF 文件。 IronPDF 通过在 .NET 环境中提供全面的 PDF 创建、编辑和管理功能,简化了 PDF 工作流程。

IronPDF 的主要功能有哪些?

  1. HTML 转 PDF:将 HTML、CSS 和 JavaScript 转换为像素级精准PDF 文件

  2. URL转PDF:从任意URL生成PDF文件,完整保留内容及响应式样式

  3. 图片转PDF:支持将 JPG、PNG、GIF、BMP 和 SVG 转换为 PDF 文档,并支持多帧 TIFF 格式

  4. 表单填写与数据提取:通过编程方式创建并填写 PDF 表单,并支持自定义验证

  5. 数字签名与安全性:支持 HSM,可添加数字签名密码权限

  6. PDF 编辑:添加、复制或删除页面。 支持页面旋转功能的 PDF 合并与拆分

  7. 注释与附件:添加便签嵌入带有自定义元数据的附件

  8. 页眉、页脚和水印:使用 HTML 模板应用自定义的页眉、页脚水印

  9. 跨平台兼容性:支持 WindowsmacOSLinuxDockerAzureAWS

  10. 性能优化:支持多线程和异步处理,通过并行处理实现海量生成。

  11. 完整的文档:详尽的指南教程以及每周 5 天、每天 24 小时的技术支持

  12. 无外部依赖:采用原生渲染引擎,仅需部署单个 DLL 文件,无需额外软件支持。

如何在 Visual Studio 中创建 C# 应用程序?

创建 C# 控制台应用程序需要在计算机上安装 Visual Studio。 请按照以下步骤设置项目:

如何打开 Visual Studio?

从"开始"菜单或桌面图标启动 Visual Studio。

如何创建新项目?

  1. 在首页上点击"创建新项目"
  2. 搜索"Console App"或从模板列表中选择。

如何选择项目模板?

请根据需求选择"控制台应用程序(.NET Core)""控制台应用程序(.NET Framework)"。 如需 .NET MAUI 支持,请选择相应的 MAUI 模板。

如何配置我的项目?

  1. 项目名称:输入项目名称
  2. 位置:选择保存目录
  3. 解决方案名称:通常与项目名称一致
  4. 点击"创建"继续

如何安装 IronPDF?

IronPDF 提供三种安装方式:NuGet 包管理器包管理器控制台以及直接下载。 该库支持 WindowsmacOSLinux 以及云端部署

如何使用 NuGet 包管理器?

在 Visual Studio 中,右键单击"解决方案资源管理器"中的"引用"或"依赖项"。 选择"管理 NuGet 包",搜索"IronPDF",然后点击"安装"。

Visual Studio NuGet 包管理器显示 IronPDF 搜索结果,其中已安装主 IronPDF 包版本 2024.5.2,并且可见 IronPdf.Native.Chrome.Windows 和 IronPdf.Slim 等相关包。

如何使用 NuGet 包管理器控制台?

打开"工具">"NuGet 包管理器">"包管理器控制台",并运行:

Install-Package IronPdf

如何从 NuGet 网站下载?

请访问 NuGet 网站,下载包文件,并在 Visual Studio 中将其添加为包源。 对于 Docker 部署,请使用具体的容器配置。

有关详细指导,请参阅安装概述高级 NuGet 配置

如何使用 CraftMyPDF

要集成 CraftMyPDF,请创建帐户、选择套餐并获取 API 凭证。

如何创建账户并选择免费套餐?

  1. 注册:CraftMyPDF 网站上注册
  2. 选择免费套餐:选择免费套餐用于开发和测试
  3. 获取 API 密钥:从账户仪表盘中获取 API 密钥

CraftMyPDF 控制面板显示免费计划订阅详情、已使用 6/50 个积分,以及包含签名域等新功能和错误修复的最新更新日志

我需要安装哪些库?

安装System.Net.HttpRestSharpNewtonsoft.Json包:

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using RestSharp;
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using RestSharp;
Imports System
Imports System.Net.Http
Imports System.Text
Imports System.Threading.Tasks
Imports RestSharp
$vbLabelText   $csharpLabel

初始化 API 客户端:

var client = new RestClient("___PROTECTED_URL_51___");
var request = new RestRequest(Method.Post);
string apiKey = "API Key"; // Replace with your actual API key
string templateId = "Template ID"; // Replace with your actual template ID
request.AddHeader("X-API-KEY", apiKey);
request.AddHeader("Content-Type", "application/json");
var client = new RestClient("___PROTECTED_URL_51___");
var request = new RestRequest(Method.Post);
string apiKey = "API Key"; // Replace with your actual API key
string templateId = "Template ID"; // Replace with your actual template ID
request.AddHeader("X-API-KEY", apiKey);
request.AddHeader("Content-Type", "application/json");
Dim client As New RestClient("___PROTECTED_URL_51___")
Dim request As New RestRequest(Method.Post)
Dim apiKey As String = "API Key" ' Replace with your actual API key
Dim templateId As String = "Template ID" ' Replace with your actual template ID
request.AddHeader("X-API-KEY", apiKey)
request.AddHeader("Content-Type", "application/json")
$vbLabelText   $csharpLabel

如何创建 PDF 文件?

这两个库提供了不同的 PDF 生成方法。 IronPDF 使用基于代码的HTML 渲染,而 CraftMyPDF 使用带有数据绑定的可视化模板。 IronPDF 还支持 Markdown 转 PDFXML 转 PDF 转换。

如何使用 IronPDF 创建 PDF 文件?

如何将 HTML 转换为 PDF?

直接将 HTML 字符串转换为 PDF,支持完整的 CSS 样式和 JavaScript 渲染

using IronPdf;
public class PDFCreator
{
    public void CreatePdfFromHtml()
    {
        var renderer = new ChromePdfRenderer();
        // Define your HTML string
        string htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a sample PDF document created from an HTML string.</p>";
        // Render the HTML as a PDF document
        var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent);
        // Save the PDF document
        pdfDocument.SaveAs("html_output.pdf");
    }
}
using IronPdf;
public class PDFCreator
{
    public void CreatePdfFromHtml()
    {
        var renderer = new ChromePdfRenderer();
        // Define your HTML string
        string htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a sample PDF document created from an HTML string.</p>";
        // Render the HTML as a PDF document
        var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent);
        // Save the PDF document
        pdfDocument.SaveAs("html_output.pdf");
    }
}
Imports IronPdf
Public Class PDFCreator
	Public Sub CreatePdfFromHtml()
		Dim renderer = New ChromePdfRenderer()
		' Define your HTML string
		Dim htmlContent As String = "<h1>Hello, IronPDF!</h1><p>This is a sample PDF document created from an HTML string.</p>"
		' Render the HTML as a PDF document
		Dim pdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
		' Save the PDF document
		pdfDocument.SaveAs("html_output.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel

这是 IronPDF 生成的 PDF 文档的屏幕截图,显示了Hello, IronPDF!标题和示例文本,演示了 HTML 到 PDF 的转换。

如需更多示例,请访问 HTML 转 PDF 示例页面。 开发人员还可以设置自定义页边距添加分页符以及配置纸张尺寸

如何将 URL 转换为 PDF?

将网页转换为 PDF 文件,同时保留所有样式,包括 WebGL 内容响应式 CSS

using IronPdf;
public class PDFCreator
{
    public void CreatePdfFromUrl(string url)
    {
        // Initialize the ChromePdfRenderer
        var renderer = new ChromePdfRenderer();
        // Render the URL as a PDF document
        var pdfDocument = renderer.RenderUrlAsPdf(url);
        // Save the PDF document
        pdfDocument.SaveAs("url_output.pdf");
    }
}
using IronPdf;
public class PDFCreator
{
    public void CreatePdfFromUrl(string url)
    {
        // Initialize the ChromePdfRenderer
        var renderer = new ChromePdfRenderer();
        // Render the URL as a PDF document
        var pdfDocument = renderer.RenderUrlAsPdf(url);
        // Save the PDF document
        pdfDocument.SaveAs("url_output.pdf");
    }
}
Imports IronPdf

Public Class PDFCreator
    Public Sub CreatePdfFromUrl(url As String)
        ' Initialize the ChromePdfRenderer
        Dim renderer = New ChromePdfRenderer()
        ' Render the URL as a PDF document
        Dim pdfDocument = renderer.RenderUrlAsPdf(url)
        ' Save the PDF document
        pdfDocument.SaveAs("url_output.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF 主页展示了使用 C# 中的 ChromePdfRenderer 库进行 HTML 转 PDF 转换的 C# 代码示例,该库的 NuGet 下载量已达 9,229,207 次,并介绍了其主要功能

了解更多关于 URL 转 PDF 的信息。 关于需要身份验证的页面,请参阅 TLS 网站登录HTTP 请求头

如何将 HTML 文件转换为 PDF?

将本地 HTML 文件转换为 PDF,支持 CSS 媒体类型基准 URL

using IronPdf;
public class PDFCreator
{
    public void CreatePdfFromHtmlFile(string filePath)
    {
        // Initialize the ChromePdfRenderer
        var renderer = new ChromePdfRenderer();
        // Render the HTML file as a PDF document
        var pdfDocument = renderer.RenderHtmlFileAsPdf(filePath);
        // Save the PDF document
        pdfDocument.SaveAs("html_file_output.pdf");
    }
}
using IronPdf;
public class PDFCreator
{
    public void CreatePdfFromHtmlFile(string filePath)
    {
        // Initialize the ChromePdfRenderer
        var renderer = new ChromePdfRenderer();
        // Render the HTML file as a PDF document
        var pdfDocument = renderer.RenderHtmlFileAsPdf(filePath);
        // Save the PDF document
        pdfDocument.SaveAs("html_file_output.pdf");
    }
}
Imports IronPdf

Public Class PDFCreator
    Public Sub CreatePdfFromHtmlFile(filePath As String)
        ' Initialize the ChromePdfRenderer
        Dim renderer As New ChromePdfRenderer()
        ' Render the HTML file as a PDF document
        Dim pdfDocument = renderer.RenderHtmlFileAsPdf(filePath)
        ' Save the PDF document
        pdfDocument.SaveAs("html_file_output.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

详情请参阅 HTML 转 PDF 指南。 对于 HTML ZIP 文件,IronPDF 会自动进行提取。

如何使用 CraftMyPDF API 创建 PDF?

CraftMyPDF 需要先创建模板,然后通过合并数据生成 PDF。

如何创建模板?

1.登录控制面板:访问 CraftMyPDF 帐户

  1. 创建新模板:使用拖放编辑器进行设计
  2. 保存模板:获取用于 API 调用的模板 ID

CraftMyPDF模板管理仪表板显示了一个带有编辑工具和教程资源的发票模板

如何发送生成 PDF 的请求?

通过向模板发送 JSON 数据生成 PDF:

using System;
using System.Net;
using System.Threading.Tasks;
using RestSharp;

class Program
{
    static async Task Main(string[] args)
    {
        var client = new RestClient("___PROTECTED_URL_52___");
        var request = new RestRequest(Method.Post);
        string apiKey = "API-Key"; // Replace with your actual API key
        string templateId = "Template-ID"; // Replace with your actual template ID
        request.AddHeader("X-API-KEY", apiKey);
        request.AddHeader("Content-Type", "application/json");
        var body = new
        {
            data = new
            {
                invoice_number = "INV48321",
                date = "2024-05-27",
                due_date = "2024-06-27",
                currency = "EUR",
                discount = 10,
                tax = 5,
                company_name = "Tech Innovations Ltd",
                email = "contact@techinnovations.com",
                client = "Future Solutions GmbH",
                client_address = "1234 Innovation Drive",
                client_address2 = "Berlin",
                client_address3 = "10115",
                items = new[]
                {
                    new { description = "Cloud Hosting Services", quantity = 12, unit_price = 75, total = 900 },
                    new { description = "Custom Web Application", quantity = 3, unit_price = 150, total = 450 },
                    new { description = "Technical Support", quantity = 15, unit_price = 30, total = 450 },
                    new { description = "Digital Marketing Campaign", quantity = 2, unit_price = 500, total = 1000 },
                    new { description = "SEO Optimization", quantity = 5, unit_price = 120, total = 600 }
                },
                gross_total = 3400
            },
            load_data_from = (string)null,
            template_id = templateId,
            version = 8,
            export_type = "json",
            expiration = 60,
            output_file = "output.pdf",
            is_cmyk = false,
            image_resample_res = 600,
            direct_download = 0,
            cloud_storage = 1
        };
        request.AddJsonBody(body);
        RestResponse response = await client.ExecuteAsync(request);
        Console.WriteLine(response.Content);
        if (response.IsSuccessful)
        {
            var content = response.Content;
            dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(content);
            string fileUrl = result.file;
            string localPath = "f:\\downloaded_output.pdf";
            using (WebClient webClient = new WebClient())
            {
                webClient.DownloadFile(fileUrl, localPath);
            }
            Console.WriteLine($"PDF downloaded successfully to {localPath}");
        }
        else
        {
            Console.WriteLine($"Error: {response.Content}");
        }
    }
}
using System;
using System.Net;
using System.Threading.Tasks;
using RestSharp;

class Program
{
    static async Task Main(string[] args)
    {
        var client = new RestClient("___PROTECTED_URL_52___");
        var request = new RestRequest(Method.Post);
        string apiKey = "API-Key"; // Replace with your actual API key
        string templateId = "Template-ID"; // Replace with your actual template ID
        request.AddHeader("X-API-KEY", apiKey);
        request.AddHeader("Content-Type", "application/json");
        var body = new
        {
            data = new
            {
                invoice_number = "INV48321",
                date = "2024-05-27",
                due_date = "2024-06-27",
                currency = "EUR",
                discount = 10,
                tax = 5,
                company_name = "Tech Innovations Ltd",
                email = "contact@techinnovations.com",
                client = "Future Solutions GmbH",
                client_address = "1234 Innovation Drive",
                client_address2 = "Berlin",
                client_address3 = "10115",
                items = new[]
                {
                    new { description = "Cloud Hosting Services", quantity = 12, unit_price = 75, total = 900 },
                    new { description = "Custom Web Application", quantity = 3, unit_price = 150, total = 450 },
                    new { description = "Technical Support", quantity = 15, unit_price = 30, total = 450 },
                    new { description = "Digital Marketing Campaign", quantity = 2, unit_price = 500, total = 1000 },
                    new { description = "SEO Optimization", quantity = 5, unit_price = 120, total = 600 }
                },
                gross_total = 3400
            },
            load_data_from = (string)null,
            template_id = templateId,
            version = 8,
            export_type = "json",
            expiration = 60,
            output_file = "output.pdf",
            is_cmyk = false,
            image_resample_res = 600,
            direct_download = 0,
            cloud_storage = 1
        };
        request.AddJsonBody(body);
        RestResponse response = await client.ExecuteAsync(request);
        Console.WriteLine(response.Content);
        if (response.IsSuccessful)
        {
            var content = response.Content;
            dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(content);
            string fileUrl = result.file;
            string localPath = "f:\\downloaded_output.pdf";
            using (WebClient webClient = new WebClient())
            {
                webClient.DownloadFile(fileUrl, localPath);
            }
            Console.WriteLine($"PDF downloaded successfully to {localPath}");
        }
        else
        {
            Console.WriteLine($"Error: {response.Content}");
        }
    }
}
Imports System
Imports System.Net
Imports System.Threading.Tasks
Imports RestSharp

Module Program
    Async Function Main(args As String()) As Task
        Dim client As New RestClient("___PROTECTED_URL_52___")
        Dim request As New RestRequest(Method.Post)
        Dim apiKey As String = "API-Key" ' Replace with your actual API key
        Dim templateId As String = "Template-ID" ' Replace with your actual template ID
        request.AddHeader("X-API-KEY", apiKey)
        request.AddHeader("Content-Type", "application/json")
        Dim body = New With {
            .data = New With {
                .invoice_number = "INV48321",
                .date = "2024-05-27",
                .due_date = "2024-06-27",
                .currency = "EUR",
                .discount = 10,
                .tax = 5,
                .company_name = "Tech Innovations Ltd",
                .email = "contact@techinnovations.com",
                .client = "Future Solutions GmbH",
                .client_address = "1234 Innovation Drive",
                .client_address2 = "Berlin",
                .client_address3 = "10115",
                .items = New Object() {
                    New With {.description = "Cloud Hosting Services", .quantity = 12, .unit_price = 75, .total = 900},
                    New With {.description = "Custom Web Application", .quantity = 3, .unit_price = 150, .total = 450},
                    New With {.description = "Technical Support", .quantity = 15, .unit_price = 30, .total = 450},
                    New With {.description = "Digital Marketing Campaign", .quantity = 2, .unit_price = 500, .total = 1000},
                    New With {.description = "SEO Optimization", .quantity = 5, .unit_price = 120, .total = 600}
                },
                .gross_total = 3400
            },
            .load_data_from = CType(Nothing, String),
            .template_id = templateId,
            .version = 8,
            .export_type = "json",
            .expiration = 60,
            .output_file = "output.pdf",
            .is_cmyk = False,
            .image_resample_res = 600,
            .direct_download = 0,
            .cloud_storage = 1
        }
        request.AddJsonBody(body)
        Dim response As RestResponse = Await client.ExecuteAsync(request)
        Console.WriteLine(response.Content)
        If response.IsSuccessful Then
            Dim content = response.Content
            Dim result = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Object)(content)
            Dim fileUrl As String = result.file
            Dim localPath As String = "f:\downloaded_output.pdf"
            Using webClient As New WebClient()
                webClient.DownloadFile(fileUrl, localPath)
            End Using
            Console.WriteLine($"PDF downloaded successfully to {localPath}")
        Else
            Console.WriteLine($"Error: {response.Content}")
        End If
    End Function
End Module
$vbLabelText   $csharpLabel

Visual Studio 调试控制台显示 CraftMyPDF API 成功生成 PDF 输出,并包含 JSON 响应详情

生成的 PDF 输出:

Tech Innovations Ltd 开具的发票显示,该公司提供多种技术服务,包括搜索引擎优化 (SEO)、数字营销、技术支持、Web 应用程序和云托管,折扣和税后总额为 2,907.00 欧元。

如何使用 Bootstrap 生成 Professional 发票?

IronPDF 可在不依赖外部组件的情况下渲染现代框架。 此 Bootstrap 5 示例展示了采用响应式设计PRINT 样式表(CSS)的专业发票生成功能:

using IronPdf;

var renderer = new ChromePdfRenderer();

string professionalInvoice = @"
<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <link href='___PROTECTED_URL_53___ rel='stylesheet'>
    <style>
        .invoice-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
        .invoice-table th { background: #f8f9fa; }
        @media print { .invoice-box { page-break-inside: avoid; } }
    </style>
</head>
<body>
    <div class='container my-4'>
        <div class='card shadow-lg invoice-box'>
            <div class='invoice-header p-4'>
                <div class='row align-items-center'>
                    <div class='col-md-8'>
                        <h1 class='mb-0'>INVOICE</h1>
                        <p class='mb-0 opacity-75'>Invoice #INV-2024-0427</p>
                    </div>
                    <div class='col-md-4 text-md-end'>
                        <h3 class='mb-0'>$3,400.00</h3>
                        <small class='opacity-75'>Due: June 27, 2024</small>
                    </div>
                </div>
            </div>

            <div class='card-body p-4'>
                <div class='row mb-4'>
                    <div class='col-md-6'>
                        <h6 class='text-primary text-uppercase mb-2'>From</h6>
                        <strong>Tech Innovations Ltd</strong><br>
                        contact@techinnovations.com
                    </div>
                    <div class='col-md-6 text-md-end'>
                        <h6 class='text-primary text-uppercase mb-2'>Bill To</h6>
                        <strong>Future Solutions GmbH</strong><br>
                        1234 Innovation Drive<br>
                        Berlin, 10115
                    </div>
                </div>

                <table class='table invoice-table'>
                    <thead>
                        <tr>
                            <th>Description</th>
                            <th class='text-center'>Qty</th>
                            <th class='text-end'>Unit Price</th>
                            <th class='text-end'>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Cloud Hosting Services</td>
                            <td class='text-center'>12</td>
                            <td class='text-end'>€75.00</td>
                            <td class='text-end'>€900.00</td>
                        </tr>
                        <tr>
                            <td>Custom Web Application</td>
                            <td class='text-center'>3</td>
                            <td class='text-end'>€150.00</td>
                            <td class='text-end'>€450.00</td>
                        </tr>
                        <tr>
                            <td>Technical Support</td>
                            <td class='text-center'>15</td>
                            <td class='text-end'>€30.00</td>
                            <td class='text-end'>€450.00</td>
                        </tr>
                        <tr>
                            <td>Digital Marketing Campaign</td>
                            <td class='text-center'>2</td>
                            <td class='text-end'>€500.00</td>
                            <td class='text-end'>€1,000.00</td>
                        </tr>
                        <tr>
                            <td>SEO Optimization</td>
                            <td class='text-center'>5</td>
                            <td class='text-end'>€120.00</td>
                            <td class='text-end'>€600.00</td>
                        </tr>
                    </tbody>
                </table>

                <div class='row justify-content-end'>
                    <div class='col-md-4'>
                        <table class='table table-sm'>
                            <tr>
                                <td>Subtotal:</td>
                                <td class='text-end'><strong>€3,400.00</strong></td>
                            </tr>
                            <tr>
                                <td>Discount (10%):</td>
                                <td class='text-end text-success'>-€340.00</td>
                            </tr>
                            <tr>
                                <td>Tax (5%):</td>
                                <td class='text-end'>€153.00</td>
                            </tr>
                            <tr class='table-primary'>
                                <td><strong>Total Due:</strong></td>
                                <td class='text-end'><strong>€3,213.00</strong></td>
                            </tr>
                        </table>
                    </div>
                </div>

                <div class='alert alert-info mt-4'>
                    <strong>Payment Terms:</strong> Payment due within 30 days. Late payments may incur additional charges.
                </div>

                <div class='row mt-4 pt-3 border-top'>
                    <div class='col-md-6'>
                        <small class='text-muted'>Generated with IronPDF - No external APIs required</small>
                    </div>
                    <div class='col-md-6 text-md-end'>
                        <span class='badge bg-success'>PAID</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(professionalInvoice);
pdf.SaveAs("professional-invoice.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

string professionalInvoice = @"
<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <link href='___PROTECTED_URL_53___ rel='stylesheet'>
    <style>
        .invoice-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
        .invoice-table th { background: #f8f9fa; }
        @media print { .invoice-box { page-break-inside: avoid; } }
    </style>
</head>
<body>
    <div class='container my-4'>
        <div class='card shadow-lg invoice-box'>
            <div class='invoice-header p-4'>
                <div class='row align-items-center'>
                    <div class='col-md-8'>
                        <h1 class='mb-0'>INVOICE</h1>
                        <p class='mb-0 opacity-75'>Invoice #INV-2024-0427</p>
                    </div>
                    <div class='col-md-4 text-md-end'>
                        <h3 class='mb-0'>$3,400.00</h3>
                        <small class='opacity-75'>Due: June 27, 2024</small>
                    </div>
                </div>
            </div>

            <div class='card-body p-4'>
                <div class='row mb-4'>
                    <div class='col-md-6'>
                        <h6 class='text-primary text-uppercase mb-2'>From</h6>
                        <strong>Tech Innovations Ltd</strong><br>
                        contact@techinnovations.com
                    </div>
                    <div class='col-md-6 text-md-end'>
                        <h6 class='text-primary text-uppercase mb-2'>Bill To</h6>
                        <strong>Future Solutions GmbH</strong><br>
                        1234 Innovation Drive<br>
                        Berlin, 10115
                    </div>
                </div>

                <table class='table invoice-table'>
                    <thead>
                        <tr>
                            <th>Description</th>
                            <th class='text-center'>Qty</th>
                            <th class='text-end'>Unit Price</th>
                            <th class='text-end'>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Cloud Hosting Services</td>
                            <td class='text-center'>12</td>
                            <td class='text-end'>€75.00</td>
                            <td class='text-end'>€900.00</td>
                        </tr>
                        <tr>
                            <td>Custom Web Application</td>
                            <td class='text-center'>3</td>
                            <td class='text-end'>€150.00</td>
                            <td class='text-end'>€450.00</td>
                        </tr>
                        <tr>
                            <td>Technical Support</td>
                            <td class='text-center'>15</td>
                            <td class='text-end'>€30.00</td>
                            <td class='text-end'>€450.00</td>
                        </tr>
                        <tr>
                            <td>Digital Marketing Campaign</td>
                            <td class='text-center'>2</td>
                            <td class='text-end'>€500.00</td>
                            <td class='text-end'>€1,000.00</td>
                        </tr>
                        <tr>
                            <td>SEO Optimization</td>
                            <td class='text-center'>5</td>
                            <td class='text-end'>€120.00</td>
                            <td class='text-end'>€600.00</td>
                        </tr>
                    </tbody>
                </table>

                <div class='row justify-content-end'>
                    <div class='col-md-4'>
                        <table class='table table-sm'>
                            <tr>
                                <td>Subtotal:</td>
                                <td class='text-end'><strong>€3,400.00</strong></td>
                            </tr>
                            <tr>
                                <td>Discount (10%):</td>
                                <td class='text-end text-success'>-€340.00</td>
                            </tr>
                            <tr>
                                <td>Tax (5%):</td>
                                <td class='text-end'>€153.00</td>
                            </tr>
                            <tr class='table-primary'>
                                <td><strong>Total Due:</strong></td>
                                <td class='text-end'><strong>€3,213.00</strong></td>
                            </tr>
                        </table>
                    </div>
                </div>

                <div class='alert alert-info mt-4'>
                    <strong>Payment Terms:</strong> Payment due within 30 days. Late payments may incur additional charges.
                </div>

                <div class='row mt-4 pt-3 border-top'>
                    <div class='col-md-6'>
                        <small class='text-muted'>Generated with IronPDF - No external APIs required</small>
                    </div>
                    <div class='col-md-6 text-md-end'>
                        <span class='badge bg-success'>PAID</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(professionalInvoice);
pdf.SaveAs("professional-invoice.pdf");
Imports IronPdf

Dim renderer As New ChromePdfRenderer()

Dim professionalInvoice As String = "
<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <link href='___PROTECTED_URL_53___ rel='stylesheet'>
    <style>
        .invoice-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
        .invoice-table th { background: #f8f9fa; }
        @media print { .invoice-box { page-break-inside: avoid; } }
    </style>
</head>
<body>
    <div class='container my-4'>
        <div class='card shadow-lg invoice-box'>
            <div class='invoice-header p-4'>
                <div class='row align-items-center'>
                    <div class='col-md-8'>
                        <h1 class='mb-0'>INVOICE</h1>
                        <p class='mb-0 opacity-75'>Invoice #INV-2024-0427</p>
                    </div>
                    <div class='col-md-4 text-md-end'>
                        <h3 class='mb-0'>$3,400.00</h3>
                        <small class='opacity-75'>Due: June 27, 2024</small>
                    </div>
                </div>
            </div>

            <div class='card-body p-4'>
                <div class='row mb-4'>
                    <div class='col-md-6'>
                        <h6 class='text-primary text-uppercase mb-2'>From</h6>
                        <strong>Tech Innovations Ltd</strong><br>
                        contact@techinnovations.com
                    </div>
                    <div class='col-md-6 text-md-end'>
                        <h6 class='text-primary text-uppercase mb-2'>Bill To</h6>
                        <strong>Future Solutions GmbH</strong><br>
                        1234 Innovation Drive<br>
                        Berlin, 10115
                    </div>
                </div>

                <table class='table invoice-table'>
                    <thead>
                        <tr>
                            <th>Description</th>
                            <th class='text-center'>Qty</th>
                            <th class='text-end'>Unit Price</th>
                            <th class='text-end'>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Cloud Hosting Services</td>
                            <td class='text-center'>12</td>
                            <td class='text-end'>€75.00</td>
                            <td class='text-end'>€900.00</td>
                        </tr>
                        <tr>
                            <td>Custom Web Application</td>
                            <td class='text-center'>3</td>
                            <td class='text-end'>€150.00</td>
                            <td class='text-end'>€450.00</td>
                        </tr>
                        <tr>
                            <td>Technical Support</td>
                            <td class='text-center'>15</td>
                            <td class='text-end'>€30.00</td>
                            <td class='text-end'>€450.00</td>
                        </tr>
                        <tr>
                            <td>Digital Marketing Campaign</td>
                            <td class='text-center'>2</td>
                            <td class='text-end'>€500.00</td>
                            <td class='text-end'>€1,000.00</td>
                        </tr>
                        <tr>
                            <td>SEO Optimization</td>
                            <td class='text-center'>5</td>
                            <td class='text-end'>€120.00</td>
                            <td class='text-end'>€600.00</td>
                        </tr>
                    </tbody>
                </table>

                <div class='row justify-content-end'>
                    <div class='col-md-4'>
                        <table class='table table-sm'>
                            <tr>
                                <td>Subtotal:</td>
                                <td class='text-end'><strong>€3,400.00</strong></td>
                            </tr>
                            <tr>
                                <td>Discount (10%):</td>
                                <td class='text-end text-success'>-€340.00</td>
                            </tr>
                            <tr>
                                <td>Tax (5%):</td>
                                <td class='text-end'>€153.00</td>
                            </tr>
                            <tr class='table-primary'>
                                <td><strong>Total Due:</strong></td>
                                <td class='text-end'><strong>€3,213.00</strong></td>
                            </tr>
                        </table>
                    </div>
                </div>

                <div class='alert alert-info mt-4'>
                    <strong>Payment Terms:</strong> Payment due within 30 days. Late payments may incur additional charges.
                </div>

                <div class='row mt-4 pt-3 border-top'>
                    <div class='col-md-6'>
                        <small class='text-muted'>Generated with IronPDF - No external APIs required</small>
                    </div>
                    <div class='col-md-6 text-md-end'>
                        <span class='badge bg-success'>PAID</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>"

Dim pdf = renderer.RenderHtmlAsPdf(professionalInvoice)
pdf.SaveAs("professional-invoice.pdf")
$vbLabelText   $csharpLabel

输出:一份 Professional 发票 PDF,包含 Bootstrap 5 渐变标题、响应式表格和计算摘要。 IronPDF准确呈现所有CSS渐变、表格样式和实用程序类——无需外部API调用,无需模板,无需互联网连接。 与CraftMyPDF的云端方式不同,IronPDF在您的服务器上即时生成发票,并拥有完全控制。

该代码的作用是什么?

1.设置 RestClient使用 CraftMyPDF API 端点初始化客户端

  1. 添加头部信息:包含用于身份验证的 API 密钥和内容类型
  2. 准备请求正文:使用模板数据和选项创建 JSON 对象
  3. 发送请求:执行 API 调用以生成 PDF
  4. 处理响应:下载生成的 PDF 或显示错误信息

对于技术型创始人而言,关键区别是什么?

基于模板和代码优先的方法有何区别?

基于模板(CraftMyPDF):

  • 非技术团队成员可以创建和修改模板
  • 模板在云端控制台中集中管理
  • 模板的更改无需部署代码
  • 受模板设计限制
  • 最适合布局可预测的标准化文档

代码优先 (IronPDF):

  • 通过 HTML 和 CSS 完全掌控文档布局
  • 支持 JavaScript,可实现动态图表和计算
  • 模板作为代码库的一部分,受版本控制
  • 支持任何 Web 技术,设计灵活性无限
  • 特别适用于需要编程逻辑处理的复杂动态文档

对于 Razor 模板,IronPDF 在 MVC CoreMVC FrameworkRazor Pages 中均提供原生支持。

不同规模下的成本影响是什么?

CraftMyPDF 成本结构:

  • 免费套餐:每月 50 次 API 调用,模板数量上限为 3 个
  • 付费套餐的月费起价较高
  • 每份 PDF 的费用随数量呈线性增长
  • 持续的月度/年度订阅费用
  • 高级功能的额外费用

IronPDF 成本结构:

  • 免费试用评估,全面评估
  • 一次性永久许可,自 $999 起
  • 无按PDF计费或使用限制
  • 包含一年的更新与支持
  • SaaS 产品的 OEM 再分发选项

对于每月处理 1,000 份以上 PDF 的应用程序,IronPDF 的永久许可证可提供可预测的成本,且无需支付持续费用。 许可计算器可帮助估算总拥有成本。 请考虑为不断扩大的团队提供升级扩展方案

开发工作流有何不同?

CraftMyPDF 工作流程:

  1. 设计师在网页界面中创建模板
  2. 开发者将 JSON 字段映射到模板
  3. API 集成需要进行身份验证配置
  4. 测试需要调用 API 并消耗积分
  5. 模板更新在代码部署之外进行

IronPDF 工作流:

  1. 开发人员在代码中编写 HTML/CSS 模板
  2. 无 API 限制的本地测试
  3. 随应用程序代码部署的模板
  4. 版本控制记录所有变更
  5. 用于自动化测试的 CI/CD 集成

IronPDF 的自包含式设计能够加快迭代周期并支持离线开发,这对快速开发至关重要。 该库支持自定义日志记录渲染选项,以辅助调试。

关于数据隐私和合规性?

CraftMyPDF 数据处理:

  • 在云服务器上处理的文档
  • 需要通过互联网传输数据
  • 符合合规要求的区域端点
  • 临时文件存储策略
  • 第三方数据处理协议

IronPDF 数据处理:

  • 本地处理可将数据保留在本地
  • 无需调用外部 API 或连接互联网
  • 对文档安全性的全面控制
  • 符合 HIPAA 和 GDPR 标准的部署
  • 敏感数据的加密选项

对于处理敏感客户数据的应用程序,IronPDF 的本地处理功能消除了第三方隐私方面的担忧。 数字签名密码保护提供了额外的安全保障。 该库还支持 PDF/APDF/UA 标准以确保合规性。

我能多快添加新的文档类型?

CraftMyPDF 时间线:

  • 模板设计:1-4 小时(视复杂程度而定)
  • 字段映射与测试:1-2 小时
  • 视设计师的可用情况而定
  • 模板审批流程可能会导致延迟
  • 受编辑器功能限制

IronPDF 发展历程:

  • HTML 模板创建:30 分钟至 2 小时
  • 使用现有的 Web 框架,如 Bootstrap
  • 在不同文档间复用 CSS 样式表
  • 在本地测试并即时获得反馈
  • 通过定期发布部署新的文档类型

IronPDF 的"代码优先"方法通常能缩短新文档类型的上市时间,尤其是在利用现有 Web 资源和框架时。 该库支持 RTF 转 PDFDOCX 转 PDF 以及 Markdown 转 PDF 转换,以提供更大的灵活性。

有哪些许可选项?

IronPDF 定价页面显示三种永久许可级别:Lite(749 美元)、Plus(1,499 美元)和 Professional(2,999 美元),并提供功能比较以及可选的免版税再分发附加组件(1,499 美元)。

IronPDF 提供一次性付费的永久许可证。 Lite 许可证 ($999) 支持单个开发人员在一个项目中工作。 专业版许可证($1,499)涵盖多个项目和开发人员。 企业版许可证($2,999)适用于部署需求广泛的大型团队。 每个许可证均包含一年的支持和更新服务。 OEM 再分发许可允许进行商业分发。 提供免费试用版供评估。 查看完整的许可选项

CraftMyPDF 采用订阅式定价。 免费套餐适用于开发和测试场景,API调用限制。 付费套餐可提升使用限额并增加功能,以满足业务需求。 订阅通过 CraftMyPDF 控制面板进行管理。

有哪些文档和支持资源可用?

IronPDF 在文档和支持方面提供哪些服务?

IronPDF 提供了完整的文档,包括详细指南、示例以及"快速入门"部分。 相关资源涵盖从基础用法到高级配置的全方位内容。 支持渠道包括知识库、电子邮件支持以及工程支持请求。 支持团队每周工作 5 天,全天候提供及时协助。 故障排除指南针对常见问题提供解决方案。

文档包含所有功能的 API 参考教程代码示例变更日志记录更新情况,里程碑则突出显示主要版本发布。 有关迁移支持,请参阅对比 AsposeiTextSyncfusion 及其他竞争对手的指南。

CraftMyPdf 提供哪些文档和支持?

CraftMyPDF 提供 API 文档,详细说明端点、参数和示例。 指南涵盖模板创建、API 请求以及响应处理。 如有疑问或建议,可通过电子邮件和社区论坛获取支持。

我应该选择哪种 PDF 解决方案?

IronPDF 和 CraftMyPDF 都提供了功能强大的 PDF 生成解决方案,但方法各不相同。 CraftMyPDF 凭借其可视化模板设计器和基于云的处理功能脱颖而出,而 IronPDF 则通过HTML 渲染提供完整的程序化控制。

IronPDF 凭借其丰富的功能集,在满足复杂文档需求方面脱颖而出。 它可将 HTMLURL文件转换为 PDF,同时支持数字签名表单处理文档编辑等高级功能。 无需外部依赖的自包含部署方式,确保了跨平台的可靠运行。

这些产品的许可模式存在显著差异。 IronPDF 的永久许可证起价为 $999,并提供免费试用以进行评估。 Iron Suite 套装以两款产品的价格提供九款产品,为全面的文档管理需求带来非凡价值。

对于需要全面掌控 PDF 生成、支持丰富的 HTML/CSS 功能具备高级文档处理能力且成本可预测的开发者而言,IronPDF 提供了一个可靠的解决方案。 其详尽的文档响应迅速的支持以及灵活的部署选项,使其适用于从简单的文档生成到复杂的企业工作流等各类应用场景。

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

常见问题解答

使用C# PDF库相比基于API的解决方案有什么优势?

像IronPDF这样全面的PDF库提供广泛的功能,与.NET开发环境无缝集成,强大的支持以及具有成本效益的许可选项,使其成为复杂文档处理的优良选择。

如何使用C#将HTML内容转换为PDF文档?

您可以使用IronPDF将HTML内容转换为PDF文档。它支持HTML5和CSS3,确保网页内容在生成的PDF中被准确呈现。

在IronPDF中用于PDF生成的关键功能是什么?

IronPDF提供数字签名、表单填写、PDF编辑、注释以及跨平台兼容性。它在将HTML、URL和图像转换为PDF方面表现出色,并具有强大的性能和优化。

CraftMyPDF如何处理PDF模板设计?

CraftMyPDF提供一个基于Web的拖放编辑器,允许用户无需编程即可设计PDF模板。它支持JSON数据集成,能够创建定制的PDF文档。

像IronPDF之类的PDF工具有哪些许可选项可用?

IronPDF提供灵活的许可选项,包括一次性费用的Lite、Professional和Enterprise许可证。它还为新用户提供免费试用,以探索其功能。

如何将PDF生成API集成到我的C#应用中?

要集成像CraftMyPDF这样的PDF生成API,您需要创建一个帐户,选择合适的计划,获取API密钥,并使用诸如System.Net.Http和RestSharp等库进行API调用。

为使用IronPDF的开发人员提供了哪些支持资源?

IronPDF提供广泛的文档、教程和24/5技术支持。这些资源帮助开发人员在项目中有效实现和排除库故障。

如何在C#应用程序中安装IronPDF?

可以通过Visual Studio中的NuGet包管理器安装IronPDF,使用NuGet包管理器控制台,或者直接从NuGet网站下载包。

IronPDF如何增强PDF文档的安全性和交互性?

IronPDF支持数字签名和表单处理等功能,增强了文档的安全性和交互性,使其适合于综合的PDF管理。

Curtis Chau
技术作家

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

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

钢铁支援团队

我们每周 5 天,每天 24 小时在线。
聊天
电子邮件
打电话给我