如何在C++中將HTML轉PDF
IronPDF 提供以程式碼為主的 HTML 轉換 PDF 功能,支援完整的 CSS/JavaScript 並提供由 $999 發售的永久授權,而 CraftMy PDF 則提供基於雲端的範本設計和 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 是一個基於雲端的 API 用於透過範本建立 PDF。 它提供一個以網頁瀏覽器為基礎的拖放式編輯器,用於設計無需程式碼的可重用範本。 該平台透過將這些範本與 JSON 資料融合來生成 PDF,支援如發票、報告和證書等文件的動態內容生成。
CraftMyPDF 的主要功能有哪些?
-
拖放編輯器:視覺化範本設計工具,無需程式碼知識。
-
範本重用性:設計一次即可配合不同資料集重複使用。
-
JSON 資料整合:透過 JSON 將動態資料與範本融合。
-
高級格式和表達式:動態格式化日期、數字和貨幣。
-
API 整合:REST API 支援 Zapier、Make.com 和自訂應用程式。
-
可填寫的元件:建立具有文字欄位和核取框的互動表單。
- 安全性和合規性:透過區域 API 端點和 GDPR 合規性保護 PDF 存取。
什麼是IronPDF?
IronPDF PDF Library for .NET Developers 是一個完整的 PDF 程式庫,適用於 .NET 應用程式。 以 C# 撰寫,生成像素完美的 PDF,從HTML、CSS、JavaScript和圖像中生成。 IronPDF 透過在.NET 環境中提供建立、編輯和管理的廣泛能力,簡化了 PDF 相關工作流程。
IronPDF 的主要功能有哪些?
-
HTML 轉換為 PDF:將 HTML、CSS 和 JavaScript 轉換為 PDF,達到像素級精確度。
-
URL 轉換為 PDF:從任何 URL 生成 PDF,保留內容和響應式樣式。
-
圖像轉換為 PDF:將 JPG、PNG、GIF、BMP 和 SVG 轉換為 PDF 文件,支援多幀 TIFF。
-
表單填寫和資料提取:建立並程式化填寫 PDF 表單,具有自訂驗證。
-
PDF 編輯:新增、複製或刪除頁面。 合併和拆分 PDF,可進行頁面旋轉。
- 無外部依賴:透過本地渲染引擎進行單一 DLL 部署,無需額外軟體要求。
如何在 Visual Studio 上建立 C# 應用程式?
建立 C# 主控台應用程式需要在計算機上安裝 Visual Studio。 請按以下步驟設定專案:
如何開啟 Visual Studio?
從開始功能表或桌面圖示啟動 Visual Studio。
如何建立新專案?
- 單擊啟動頁面的"建立新專案"。
- 搜索"Console App"或從範本清單中選擇。
如何選擇專案範本?
根據需求選擇 "Console App (.NET Core)" 或 "Console App (.NET Framework)"。 要支援 .NET MAUI,請選擇相應的 MAUI 範本。
如何配置我的專案?
- 專案名稱:輸入專案名稱
- 位置:選擇保存目錄
- 解決方案名稱:通常與專案名稱相符
- 單擊 "建立" 以繼續
如何安裝IronPDF?
IronPDF 提供三種安裝方法: NuGet 套件管理器、 套件管理器控制台 和直接下載。 該程式庫支援 Windows、macOS、Linux 和 雲端部署。
如何使用 NuGet 套件管理器?
在 Visual Studio 中,右鍵單擊方案瀏覽器中的 "引用" 或 "依賴項"。 選擇"管理 NuGet 套件",搜索"IronPDF",然後單擊"安裝"。

如何使用 NuGet 套件管理器控制台?
開啟工具 > NuGet 套件管理器 > 套件管理控制台並執行:
Install-Package IronPdf
如何從 NuGet 網站下載?
存取NuGet 網站,下載套件檔案,並在 Visual Studio 中將其作為套件來源新增。 針對 Docker 部署,使用特定的容器配置。
如何使用 CraftMyPDF?
要合併 CraftMyPDF ,需要建立一個帳戶,選擇一個方案,並獲取 API 憑據。
如何建立帳戶並選擇免費方案?
- 註冊:在CraftMyPDF 網站上註冊
- 選擇免費方案:選擇免費層進行開發和測試
- 獲取 API 鑰匙:從帳戶儀表板獲取 API 鑰匙

我需要安裝哪些程式庫?
安裝 System.Net.Http、RestSharp 和 Newtonsoft.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
初始化 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")
如何建立 PDF?
兩個程式庫提供不同的 PDF 生成方法。 IronPDF 使用基於程式碼的 HTML 渲染,而 CraftMyPDF 使用可視範本搭配資料繫結。 IronPDF 亦支援Markdown 轉換 PDF 和 XML 轉換 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

欲了解更多範例,請存取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

了解更多關於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
請參閱HTML 檔案轉換 PDF 指南以了解更多內容。 對於HTML ZIP 檔案,IronPDF 可自動提取。
如何使用 CraftMyPDF API 建立 PDF?
CraftMyPDF 需首先建立範本,其後透過合併資料來生成 PDF。
如何建立範本?
- 登入儀表板:存取
CraftMyPDF帳戶 - 建立新範本:利用拖放編輯器設計
- 儲存範本:獲得用於 API 呼叫的範本 ID

如何發送請求生成 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

生成的 PDF 輸出:

如何使用 Bootstrap 生產專業發票?
IronPDF 無需外部依賴來呈現現代框架。 此 Bootstrap 5 範例展示了帶有響應設計和印刷 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")
輸出: 運用 Bootstrap 5 漸變頁眉、響應式表和計算摘要生成的專業發票 PDF。 IronPDF 精確呈現所有 CSS 漸變、表格樣式和工具類別—無需外部 API 呼叫、範本、或網際網路連接。 與 CraftMyPDF 的雲端方法不同,IronPDF 可在您的伺服器上即時生成發票,並提供完全的控制。
程式碼實現了什麼?
- 設置
RestClient:使用CraftMyPDFAPI 端點初始化客戶端 - 新增頁眉資訊:包括 API 鍵和內容型別以進行身份驗證
- 準備請求正文:建立包含範本資料和選項的 JSON 物件
- 發送請求:執行 API 呼叫生成 PDF
- 處理回應:下載生成的 PDF 或顯示錯誤資訊
技術創辦人的主要區別是什麼?
模板為基礎和程式碼優先的方法如何比較?
模板為基礎(CraftMyPDF):
- 非技術團隊成員也可以建立和修改模板
- 模板集中管理於雲端儀表板
- 更改模板無需程式碼部署
- 受模板設計限制限制
- 最適用於佈局可預測的標準化文件
程式碼優先(IronPDF):
- 使用 HTML 和 CSS 完全掌控文件佈局
- 支援JavaScript,實現動態圖表和計算
- 模板是程式碼的一部份,受到版本控制
- 使用任何網路技術擁有無限的設計靈活性
- 適用於需要程式邏輯的複雜動態文件
對 Razor 範本,IronPDF 在 MVC Core、MVC Framework 和 Razor Pages 提供了原生支援。
不同規模的成本差異是什麼?
CraftMyPDF 成本結構:
- 免費層:每月 50 次 API 呼叫,限制 3 個模板
- 付費方案從更高的每月費用開始
- 每份 PDF 成本隨著數量線性增加
- 持續的每月/年度訂閱費用
- 高級功能的額外成本
IronPDF 成本結構:
對於每月處理 1,000+ PDF 的應用,IronPDF 的永久授權提供可預測的成本,不需持續費用。 授權計算機幫助估計總擁有成本。 考慮擴展選項以支援成長的團隊。
開發工作流程有什麼不同?
CraftMyPDF 工作流程:
- 設計師通過網頁介面建立範本
- 開發者將 JSON 字段對應範本
- API 整合需要配置身份驗證
- 測試需要 API 呼叫和點數使用
- 模板更新在程式碼部署之外發生
IronPDF 工作流程:
IronPDF 的獨立方式支持更快的迭代週期和離線開發,對於快速開發至關重要。 該程式庫支援自訂日誌記錄和渲染選項以進行除錯。
資料隱私和合規性如何保障?
CraftMyPDF 資料處理:
- 文件在雲端伺服器上處理
- 網際網路資料傳輸是必需的
- 為合規性提供區域端點
- 臨時文件儲存政策
- 第三方資料處理協議
IronPDF 資料處理:
- 本地化處理讓資料保留在本地
- 無外部 API 呼叫或網際網路要求
- 完整控制的文件安全性
- HIPAA 和 GDPR 合規部署
- 提供敏感資料的加密選項
對於處理敏感客戶資料的應用,IronPDF 的本地化處理消除了第三方隱私顧慮。 數位簽名和密碼保護提供了額外的安全層。 該程式庫還支援PDF/A和PDF/UA標準以滿足合規性。
如何快速新增新的文件型別?
CraftMyPDF 時間線:
- 範本設計:取決於複雜性大概需 1-4 小時
- 字段對應及測試:1-2 小時
- 受限於設計師的可用性
- 範本批准工作流程可能造成延遲
- 受編輯器功能限制
IronPDF 時間線:
- HTML 範本建立:30 分鐘到 2 小時
- 使用現有的 Web 框架如 Bootstrap
- 可重用 CSS 樣式表在不同文件中
- 本地測試及時獲取反饋
- 通過定期發佈新增文件型別
IronPDF 的程式碼優先方法通常可縮短新文件型別的上市時間,特別是在使用現有 Web 資產及框架時。 該程式庫支援RTF 轉換為 PDF、DOCX 轉換為 PDF、及Markdown 轉換為 PDF,具備更高靈活性。
有哪些授權選項?

IronPDF 提供一次性收費的永久授權。 Lite 許可證($999)支持單個開發者在單個專案上使用。 Professional 許可證($1,499)涵蓋多個專案和開發者。 Enterprise 許可證($2,399)適合有大量部署需求的大型團隊。 每一份許可證包含一年支持和更新。 OEM 再分發許可證支持商業分發。 有一個 免費試用 可供評估。 可查閱完整的 授權選項。
CraftMyPDF 採用基於訂閱的定價。 免費層適用於有限 API 呼叫的開發和測試。 付費方案擴大使用限制並增加功能,隨著業務需求擴大。 訂閱管理透過 CraftMyPDF 儀表板進行。
有哪些文件和支持可使用?
IronPDF 在文件和支持方面提供了什麼?
IronPDF 提供完整文件,包括詳細指南、例子和快速入門部分。 資源涵蓋從基礎使用到高級配置。 支持渠道包括知識庫、電子郵件支持和工程支持請求。 支援團隊提供24/5的及時協助。 故障排除指南解決常見問題。
文件包含API 參考、教學及所有功能的程式碼範例。 更新日誌記錄更新動態,里程碑 突出主要版本。 查看遷移支援指南,比較Aspose、iText、Syncfusion和其他競爭者。
CraftMyPdf 在文件和支持方面提供了什麼?
CraftMyPDF 提供 API 文件,詳細介紹端點、參數和範例。 指南涵蓋範本建立、API 請求和回應處理。 透過電子郵件和社群論壇提供問題和見解的支持。
我應該選擇哪個 PDF 解決方案?
IronPDF 和 CraftMyPDF 均提供強大的 PDF 生成解決方案,採用不同的方法。 CraftMyPDF 因其可視化模板設計工具和基於雲端的處理而出色,而 IronPDF 則通過HTML 渲染提供完整的程式控制。
IronPDF 因其豐富的功能集而在滿足複雜文件需求方面脫穎而出。 它將HTML、URL和文件轉換為 PDF,同時支援高級功能如數位簽名、表單處理和文件編輯。 自足式部署無需外部依賴,確保跨平台穩定運行。
授權模式有顯著差異。 IronPDF 的永久授權從 $999 開始,並提供免費試用供評估。 Iron Suite 套裝提供九款產品僅售兩件產品的價格,是完整文件管理需求的絕佳價值選擇。
對於需要對 PDF 生成進行全控的開發者,在豐富的HTML/CSS 支援、高級文件操作和可預測的成本上,IronPDF 提供了一個可靠的解決方案。 豐富文件、迅速支持和靈活的部署選項,使其適用於從簡單文件生成到複雜企業工作流程的應用。
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提供基於網頁的拖放編輯器,允許使用者在不需要編碼的情況下設計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?
IronPDF可以通過Visual Studio中的NuGet Package Manager安裝,使用NuGet Package Manager Console,或直接從NuGet網站下載套件。
IronPDF如何增強PDF文件的安全性和互動性?
IronPDF支援如數位簽章和表單處理等功能,增強了文件的安全性和互動性,適合全面的PDF管理。



