產品比較

APITemplate io 和 IronPDF C# PDF 函式庫比較

發佈 2024年9月29日
分享:

作為一名 C# 開發者,我經常面臨生成和操作的挑戰 PDFs 在我的專案中。 在我們的領域中,對於高效、可靠且易於整合的 PDF 解決方案的需求是常見的痛點。 這就是為什麼我決定探索 APITemplateIronPDF,兩款熱門工具承諾可簡化 C# 應用程式中與 PDF 相關的任務。

在本文中,我將分享我對 APITemplate 和 IronPDF 的實際使用經驗,並比較它們的功能、性能和整合能力。 我的目標是為您提供清晰、公正的分析,以幫助您為下一個項目做出明智的決策。 當我初次接觸到APITemplate和IronPDF時,它們在解決C#開發中的PDF相關挑戰方面的潛力引起了我的興趣。 讓我們分解這些工具各自提供的功能。

APITemplate

APITemplate io 與 IronPDF C# PDF 函式庫比較:圖 1

APITemplate 是一種雲端服務,專注於從模板生成 PDF 和圖像。 它提供了一個 API,允許開發人員透過將 JSON 數據發送到預定義的模板來創建文件和圖形。 在我最初的測試中,我發現 APITemplate 易於使用。 我可以使用他們的網頁介面創建一個模板,然後使用他們的API將我的C#應用程序中的數據填入其中。

APITemplate 的主要功能

基於模板的生成

APITemplate的核心優勢在於其基於模板的方法。 我可以為文件和圖片建立可重複使用的範本,這為我在重複性任務上節省了大量時間。 它還提供一個Markdown模板編輯器來生成PDF同步。 您可以從與 Zapier 和其他第三方集成的可重用模板生成 PDF。

JSON 數據整合

JSON 資料整合是我經常使用的一個功能。 它使您能夠用 JSON 數據填充模板。 這讓我能夠非常輕鬆地與我的 C# 應用程式進行整合,因為我可以將我的物件序列化為 JSON 並將它們發送到 API。

API 控制台

API 控制台功能為我節省了不少時間。 藉此,我可以直接從網站預覽和測試 API 呼叫,這幫助我在將其實施到我的 C# 代碼中之前進行調試和微調請求。

可自訂的頁首和頁尾

能夠在我的 PDF 中添加自訂的頁首和頁尾非常有價值,特別是在製作專業報告或發票時。 我可以輕鬆地加入頁碼、日期或公司標誌。

IronPDF

APITemplate io 和 IronPDF C# PDF 庫比較:圖 2

IronPDF另一方面,是一個專為在 C# 應用程式中進行 PDF 操作而設計的 .NET 函式庫。 它提供多種功能,包括 PDF 創建、編輯和轉換。 其中一個突出的功能是能夠從HTML生成PDF,這對於基於網路的應用程式非常有用。

我首次使用 IronPDF 的經驗是透過 NuGet 安裝它,並直接整合到我的 C# 專案中。 其 API 集成過程非常順暢,這意味著我能夠在短時間內將其集成到我的專案中。我對能夠輕鬆地以程式化方式創建 PDF 而無需依賴外部服務感到驚訝。

我注意到的主要區別是 APITemplate 在使用預定義模板創建文件方面表現出色,而 IronPDF 在 C# 代碼中提供了更靈活的自定義 PDF 操作功能。 APITemplate 是基於雲的性質意味著您不需要擔心用於 PDF 生成功能的伺服器資源,但它確實需要網際網路連線。 IronPDF 作為本地函式庫,可以離線工作,但會使用您的伺服器資源。

IronPDF 的主要功能

從 HTML 生成 PDF

IronPDF 擅長於 從 HTML 內容生成 PDF 文件. 我廣泛使用這個功能來動態生成報告和文件。 只需將 HTML 字串或甚至 URL 傳遞給庫即可。 IronPDF 對現代網頁標準的廣泛支持,意味著我從 HTML 內容生成的每個 PDF 都變成了高品質的文件。

PDF 操作

此功能允許我 編輯 以程式方式處理現有的PDF文件。 我可以在 PDF 文檔中添加文字、圖片甚至新頁面,這對於更新報告或表單非常有用。

PDF 合併與分割

在處理大型文件時,我發現這個功能特別方便。 IronPDF 讓您輕鬆地 合併 多個 PDF 合併為一個或 分割 將單個PDF拆分為多個文件。

文字提取

當我需要從 PDF 中提取文字內容進行分析或索引時,IronPDF 的文字提取功能就派上用場了。 它能很好地處理各種 PDF 佈局,使數據提取變得輕而易舉。

填寫表單

對於涉及自動表單填寫的項目,IronPDF 填寫表單 此功能非常有用。 我可以以程式方式填寫 PDF 表單,節省手動輸入資料的時間。

數位簽名

安全性在我的許多專案中是至關重要的。 IronPDF 允許我添加 數位簽章 轉換為 PDF,提高文件的真實性和安全性。

密碼保護

在處理敏感文件時,我使用 IronPDF 來添加 密碼保護 轉換為PDF。 這在確保我的機密信息保持安全方面非常有幫助。

PDF 轉換為圖像

有時我需要轉換 PDF 頁面轉換為圖像 預覽或縮圖用。 IronPDF 使這個過程變得簡單,我只需幾行代碼即可,並且支持各種圖像格式。

跨平台相容性

作為從事跨平台專案的 .NET 開發者,我很欣賞 IronPDF 能夠在不同作業系統中無縫運行,這得益於其 .NET Standard 支援。

為您的C#專案設置IronPDF和APITemplate

在 C# 專案中設置這些工具相當簡單。 根據我的經驗,我會帶你了解 IronPDF 和 APITemplate 的過程。

IronPDF

在我的 C# 專案中設定 IronPDF,我會遵循以下步驟:

  1. 在 Visual Studio 中開啟我的專案。

    1. 使用 NuGet 套件管理器安裝 IronPDF。 我會使用 NuGet 套件管理器或套件管理器控制台。

      1. 在 NuGet 套件管理器中,搜索 IronPDF 並安裝它。

    APITemplate io 與 IronPDF 的 C# PDF 庫比較:圖 3

    1. 或者,在套件管理器主控台中,我執行:
Install-Package IronPdf
Install-Package IronPdf
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'Install-Package IronPdf
VB   C#

APITemplate io 和 IronPDF 的 C# PDF 庫比較:圖 4

  1. 安裝完成後,我在我的C#文件頂部添加必要的using語句:
using IronPdf;
using IronPdf;
Imports IronPdf
VB   C#
  1. 為了啟用許可證,我在應用程式啟動初期添加這行:
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY-HERE"
VB   C#

就是這樣! 現在我可以在我的程式碼中開始使用IronPDF。

APITemplate

對於 APITemplate,由於它是一個基於網頁的 API,設定過程有些不同:

  1. 首先,我在他們的網站上註冊一個 APITemplate 帳戶。

  2. 註冊後,我會導航到 API 區段以獲取我的 API 金鑰。

  3. 在我的 C# 專案中,我不需要安裝任何特定的套件。 我通常使用內建的 HttpClient 來進行 API 呼叫。

    1. 我會安全地存儲 API 金鑰。 在開發過程中,我可能會使用用戶密鑰:
dotnet user-secrets set "APITemplate:ApiKey" "YOUR-API-KEY-HERE"
dotnet user-secrets set "APITemplate:ApiKey" "YOUR-API-KEY-HERE"
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'dotnet user-secrets @set "APITemplate:ApiKey" "YOUR-API-KEY-HERE"
VB   C#
  1. 在我的代碼中,我設置了 HttpClient 並使用了 API 密鑰:
using System.Net.Http;
    using System.Net.Http.Headers;
    var client = new HttpClient();
    client.DefaultRequestHeaders.Add("X-API-KEY", Configuration["APITemplate:ApiKey"]);
using System.Net.Http;
    using System.Net.Http.Headers;
    var client = new HttpClient();
    client.DefaultRequestHeaders.Add("X-API-KEY", Configuration["APITemplate:ApiKey"]);
Imports System.Net.Http
	Imports System.Net.Http.Headers
	Private client = New HttpClient()
	client.DefaultRequestHeaders.Add("X-API-KEY", Configuration("APITemplate:ApiKey"))
VB   C#
  1. 現在我已準備好向 APITemplate 發出 API 請求。

    在這個專案中,我將使用 APITemplate 的官方範例 GitHub 專案 已經配置完成,您只需添加模板鍵。 在這些設置完成後,我可以開始在我的 C# 專案中使用 IronPDF 和 APITemplate。 IronPDF 在我的應用程式中本地運行,而 APITemplate 需要網際網路連接以與其伺服器通信。

IronPDF 中的進階功能與 APITemplate 之比較

作為 C# 開發人員,我有機會深入研究 IronPDF 和 APITemplate。 讓我們來探討一些令我印象深刻的進階功能。

IronPDF 高級功能

支持 JavaScript 的 HTML 到 PDF 轉換

IronPDF 的 HTML轉PDF 轉換相當驚人。 它不僅能夠渲染靜態 HTML,還能處理 JavaScript。 這對於我在處理動態網頁內容時來說是一個改變遊戲規則的工具。

以下是我使用它的一個簡單範例:

var Renderer = new ChromePdfRenderer();
string htmlContent = @"
    <html>
    <body>
        <h1>Dynamic Chart</h1>
        <canvas id='myChart'></canvas>
        <script src='https://cdn.jsdelivr.net/npm/chart.js'></script>
        <script>
            var ctx = document.getElementById('myChart').getContext('2d');
            new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
                    datasets: [{
                        label: '# of Votes',
                        data: [12, 19, 3, 5, 2, 3],
                        backgroundColor: [
                            'rgba(255, 99, 132, 0.2)',
                            'rgba(54, 162, 235, 0.2)',
                            'rgba(255, 206, 86, 0.2)',
                            'rgba(75, 192, 192, 0.2)',
                            'rgba(153, 102, 255, 0.2)',
                            'rgba(255, 159, 64, 0.2)'
                        ],
                        borderColor: [
                            'rgba(255, 99, 132, 1)',
                            'rgba(54, 162, 235, 1)',
                            'rgba(255, 206, 86, 1)',
                            'rgba(75, 192, 192, 1)',
                            'rgba(153, 102, 255, 1)',
                            'rgba(255, 159, 64, 1)'
                        ],
                        borderWidth: 1
                    }]
                },
                options: {
                    scales: {
                        y: {
                            beginAtZero: true
                        }
                    }
                }
            });
        </script>
    </body>
    </html>";
var PDF = Renderer.RenderHtmlAsPdf(htmlContent);
PDF.SaveAs("dynamic_chart.pdf");
var Renderer = new ChromePdfRenderer();
string htmlContent = @"
    <html>
    <body>
        <h1>Dynamic Chart</h1>
        <canvas id='myChart'></canvas>
        <script src='https://cdn.jsdelivr.net/npm/chart.js'></script>
        <script>
            var ctx = document.getElementById('myChart').getContext('2d');
            new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
                    datasets: [{
                        label: '# of Votes',
                        data: [12, 19, 3, 5, 2, 3],
                        backgroundColor: [
                            'rgba(255, 99, 132, 0.2)',
                            'rgba(54, 162, 235, 0.2)',
                            'rgba(255, 206, 86, 0.2)',
                            'rgba(75, 192, 192, 0.2)',
                            'rgba(153, 102, 255, 0.2)',
                            'rgba(255, 159, 64, 0.2)'
                        ],
                        borderColor: [
                            'rgba(255, 99, 132, 1)',
                            'rgba(54, 162, 235, 1)',
                            'rgba(255, 206, 86, 1)',
                            'rgba(75, 192, 192, 1)',
                            'rgba(153, 102, 255, 1)',
                            'rgba(255, 159, 64, 1)'
                        ],
                        borderWidth: 1
                    }]
                },
                options: {
                    scales: {
                        y: {
                            beginAtZero: true
                        }
                    }
                }
            });
        </script>
    </body>
    </html>";
var PDF = Renderer.RenderHtmlAsPdf(htmlContent);
PDF.SaveAs("dynamic_chart.pdf");
Dim Renderer = New ChromePdfRenderer()
Dim htmlContent As String = "
    <html>
    <body>
        <h1>Dynamic Chart</h1>
        <canvas id='myChart'></canvas>
        <script src='https://cdn.jsdelivr.net/npm/chart.js'></script>
        <script>
            var ctx = document.getElementById('myChart').getContext('2d');
            new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
                    datasets: [{
                        label: '# of Votes',
                        data: [12, 19, 3, 5, 2, 3],
                        backgroundColor: [
                            'rgba(255, 99, 132, 0.2)',
                            'rgba(54, 162, 235, 0.2)',
                            'rgba(255, 206, 86, 0.2)',
                            'rgba(75, 192, 192, 0.2)',
                            'rgba(153, 102, 255, 0.2)',
                            'rgba(255, 159, 64, 0.2)'
                        ],
                        borderColor: [
                            'rgba(255, 99, 132, 1)',
                            'rgba(54, 162, 235, 1)',
                            'rgba(255, 206, 86, 1)',
                            'rgba(75, 192, 192, 1)',
                            'rgba(153, 102, 255, 1)',
                            'rgba(255, 159, 64, 1)'
                        ],
                        borderWidth: 1
                    }]
                },
                options: {
                    scales: {
                        y: {
                            beginAtZero: true
                        }
                    }
                }
            });
        </script>
    </body>
    </html>"
Dim PDF = Renderer.RenderHtmlAsPdf(htmlContent)
PDF.SaveAs("dynamic_chart.pdf")
VB   C#

此代碼使用 Chart.js 生成具有動態圖表的 PDF。 在 PDF 創建過程中執行 JavaScript,生成的 PDF 包含已呈現的圖表。 我已使用這個來創建動態報告,數據經常變動,讓我不必手動更新圖表和報告。

APITemplate io 與 IronPDF 的 C# PDF 庫比較:圖 5

能夠包含外部腳本,例如在此示例中的 Chart.js,意味著我可以利用強大的 JavaScript 庫在我的 PDF 中創建豐富的動態內容。 此外,此功能允許我在 HTML 中使用 CSS 和響應式設計技術,確保生成的 PDF 在各種設備和打印格式上都呈現出色外觀。 我甚至使用了媒體查詢,從相同的 HTML 原始碼創建了優化熒幕查看和列印的 PDF。

PDF 加密和解密

在許多專案中,安全性至關重要,尤其是在處理敏感信息時。 IronPDF 的加密和解密功能在這些情況下非常寶貴。

var pdf = PdfDocument.FromFile("input.pdf");
// Set user password (for opening the document)
pdf.Password = "user_password";
// Set owner password (for editing, printing, etc.)
pdf.OwnerPassword = "owner_password";
// Set specific permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
pdf.SaveAs("highly_secured.pdf");
var pdf = PdfDocument.FromFile("input.pdf");
// Set user password (for opening the document)
pdf.Password = "user_password";
// Set owner password (for editing, printing, etc.)
pdf.OwnerPassword = "owner_password";
// Set specific permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
pdf.SaveAs("highly_secured.pdf");
Dim pdf = PdfDocument.FromFile("input.pdf")
' Set user password (for opening the document)
pdf.Password = "user_password"
' Set owner password (for editing, printing, etc.)
pdf.OwnerPassword = "owner_password"
' Set specific permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit
pdf.SaveAs("highly_secured.pdf")
VB   C#

APITemplate io 和 IronPDF 對比 C# PDF 庫:圖 6

此程式碼不僅用使用者密碼加密 PDF,還設定擁有者密碼,以細緻控制 權限. 我可以具體指定用戶能夠和不能夠對 PDF 進行的操作,例如列印或複製內容。

對於解密,我經常使用這種方法:

try
{
    var pdf = PdfDocument.FromFile("encrypted.pdf", "user_password");
    pdf.SecuritySettings.RemovePasswordsAndEncryption();
    pdf.SaveAs("decrypted.pdf");
    Console.WriteLine("PDF decrypted successfully!");
}
catch (Exception ex)
{
    Console.WriteLine($"Decryption failed: {ex.Message}");
}
try
{
    var pdf = PdfDocument.FromFile("encrypted.pdf", "user_password");
    pdf.SecuritySettings.RemovePasswordsAndEncryption();
    pdf.SaveAs("decrypted.pdf");
    Console.WriteLine("PDF decrypted successfully!");
}
catch (Exception ex)
{
    Console.WriteLine($"Decryption failed: {ex.Message}");
}
Try
	Dim pdf = PdfDocument.FromFile("encrypted.pdf", "user_password")
	pdf.SecuritySettings.RemovePasswordsAndEncryption()
	pdf.SaveAs("decrypted.pdf")
	Console.WriteLine("PDF decrypted successfully!")
Catch ex As Exception
	Console.WriteLine($"Decryption failed: {ex.Message}")
End Try
VB   C#

這段代碼嘗試使用用戶密碼打開加密的 PDF,移除所有安全限制,並將其保存為新的未加密文件。try-catch 區塊有助於處理密碼可能不正確的情況。

我曾在各種情境中使用這些功能,例如建立安全文件管理系統,讓不同使用者對 PDF 擁有不同的訪問權限。 例如,在醫療記錄系統中,我確保敏感的病人信息被加密,且只能由授權人員訪問。

PDF壓縮

在處理大量 PDF 文件時,檔案大小成為關鍵因素。 IronPDF 的 壓縮功能 在管理存儲和頻寬限制方面是個救星。

以下是我如何使用壓縮的更高級示例:

using IronPdf;
using IronSoftware.Drawing;
using PdfToSvg;
using System;
using PdfDocument = IronPdf.PdfDocument;
#region LicenseKey
License.LicenseKey = "License-Key";
#endregion
var PDF = PdfDocument.FromFile(@"F:/Test.pdf");
// Compress images
PDF.CompressImages(80); // 80% quality
// Compress fonts
PDF.CompressStructTree();
// Save the compressed PDF
PDF.SaveAs(@"F:/highly_compressed.pdf");
// Compare file sizes
var originalSize = new FileInfo(@"F:/Test.pdf").Length;
var compressedSize = new FileInfo(@"F:/highly_compressed.pdf").Length;
var compressionRatio = (1 - (double)compressedSize / originalSize) * 100;
Console.WriteLine($"Original size: {originalSize / 1024} KB");
Console.WriteLine($"Compressed size: {compressedSize / 1024} KB");
Console.WriteLine($"Compression ratio: {compressionRatio:F2}%");
using IronPdf;
using IronSoftware.Drawing;
using PdfToSvg;
using System;
using PdfDocument = IronPdf.PdfDocument;
#region LicenseKey
License.LicenseKey = "License-Key";
#endregion
var PDF = PdfDocument.FromFile(@"F:/Test.pdf");
// Compress images
PDF.CompressImages(80); // 80% quality
// Compress fonts
PDF.CompressStructTree();
// Save the compressed PDF
PDF.SaveAs(@"F:/highly_compressed.pdf");
// Compare file sizes
var originalSize = new FileInfo(@"F:/Test.pdf").Length;
var compressedSize = new FileInfo(@"F:/highly_compressed.pdf").Length;
var compressionRatio = (1 - (double)compressedSize / originalSize) * 100;
Console.WriteLine($"Original size: {originalSize / 1024} KB");
Console.WriteLine($"Compressed size: {compressedSize / 1024} KB");
Console.WriteLine($"Compression ratio: {compressionRatio:F2}%");
Imports IronPdf
Imports IronSoftware.Drawing
Imports PdfToSvg
Imports System
Imports PdfDocument = IronPdf.PdfDocument
#Region "LicenseKey"
License.LicenseKey = "License-Key"
'#End Region
Dim PDF = PdfDocument.FromFile("F:/Test.pdf")
' Compress images
PDF.CompressImages(80) ' 80% quality
' Compress fonts
PDF.CompressStructTree()
' Save the compressed PDF
PDF.SaveAs("F:/highly_compressed.pdf")
' Compare file sizes
Dim originalSize = (New FileInfo("F:/Test.pdf")).Length
Dim compressedSize = (New FileInfo("F:/highly_compressed.pdf")).Length
Dim compressionRatio = (1 - CDbl(compressedSize) / originalSize) * 100
Console.WriteLine($"Original size: {originalSize \ 1024} KB")
Console.WriteLine($"Compressed size: {compressedSize \ 1024} KB")
Console.WriteLine($"Compression ratio: {compressionRatio:F2}%")
VB   C#

以下是結果:

APITemplate io 和 IronPDF C# PDF 函式庫比較:圖 7

我發現這些技術的組合在減小文件大小的同時不會顯著影響質量,非常有效。

我在各種情境中使用過這個功能:

  1. Email attachments:在通過電子郵件發送PDF時,我會壓縮PDF以確保它們不超過附件大小限制。

  2. Web 應用程式:對於需要用戶下載的 PDF,壓縮有助於減少加載時間和頻寬使用量。

  3. 存檔:在長期保存大量 PDF 時,壓縮顯著降低了存儲成本。

    在一個專案中,我為一家律師事務所開發了一個文件管理系統。 他們有數千個PDF格式的案件檔案,其中許多是掃描文件,文件大小較大。 通過實施這種壓縮技術,我們將他們的存儲需求減少了超過60%,從而大幅節省了他們的雲存儲費用。

數位簽名

添加 數位簽章 將文件轉換為 PDF 是許多商業流程中必備的功能,以確保文件的真實性和不可否認性。 IronPDF 使這項複雜任務變得出奇地簡單。 以下是我如何實現數位簽章的更詳細示例:

using IronPdf;
using IronPdf.Signing;
var renderer = new ChromePdfRenderer();
var pdf = PdfDocument.FromFile(@"F:/Contract.pdf");
var signature = new IronPdf.Signing.PdfSignature(@"F:/Iron.pfx", "123")
{
    // Step 3. Optional signing options and a handwritten signature graphic
    SigningContact = "support@ironsoftware.com",
    SigningLocation = "New York, USA",
    SigningReason = "Signing PDF"
};
pdf.Sign(signature);
pdf.SaveAs(@"F:/signed.pdf");
using IronPdf;
using IronPdf.Signing;
var renderer = new ChromePdfRenderer();
var pdf = PdfDocument.FromFile(@"F:/Contract.pdf");
var signature = new IronPdf.Signing.PdfSignature(@"F:/Iron.pfx", "123")
{
    // Step 3. Optional signing options and a handwritten signature graphic
    SigningContact = "support@ironsoftware.com",
    SigningLocation = "New York, USA",
    SigningReason = "Signing PDF"
};
pdf.Sign(signature);
pdf.SaveAs(@"F:/signed.pdf");
Imports IronPdf
Imports IronPdf.Signing
Private renderer = New ChromePdfRenderer()
Private pdf = PdfDocument.FromFile("F:/Contract.pdf")
Private signature = New IronPdf.Signing.PdfSignature("F:/Iron.pfx", "123") With {
	.SigningContact = "support@ironsoftware.com",
	.SigningLocation = "New York, USA",
	.SigningReason = "Signing PDF"
}
pdf.Sign(signature)
pdf.SaveAs("F:/signed.pdf")
VB   C#

我在幾個實際應用中使用過這個功能:

  1. 合同管理系統:我們為一家公司實施了這個系統,以便電子方式發送和接收簽署的合同。 數位簽章確保了合同的法律效力。

  2. 醫療記錄系統:在醫療應用程式中,我們使用數位簽章讓醫生能夠簽署患者記錄和處方。

  3. 政府文件處理:對於一個政府機構,我們實施了一個系統,使官方文件可以進行數字簽名。

PDF 拆分與合併

能力來 分割和合併PDF 是我經常在文件管理系統中使用的基本功能。 IronPDF 的這些功能實現既強大又靈活。 這是一個更高級的拆分和合併PDF的範例:

using IronPdf;
class Program
{
    static void Main(string[] args)
    {
        // Create first PDF with three pages
        const string html_a = @"
            <h1>Document A</h1>
            <p>This is the first page of Document A.</p>
            <div style='page-break-after: always;'></div>
            <h2>Document A - Page 2</h2>
            <p>This is the second page of Document A.</p>
            <div style='page-break-after: always;'></div>
            <h2>Document A - Page 3</h2>
            <p>This is the third and final page of Document A.</p>";
        // Create second PDF with two pages
        const string html_b = @"
            <h1>Document B</h1>
            <p>Welcome to the first page of Document B.</p>
            <div style='page-break-after: always;'></div>
            <h2>Document B - Page 2</h2>
            <p>This is the second and last page of Document B.</p>";
        // Render HTML to PDF
        var renderer = new ChromePdfRenderer();
        var pdfdoc_a = renderer.RenderHtmlAsPdf(html_a);
        var pdfdoc_b = renderer.RenderHtmlAsPdf(html_b);
        // Merge PDFs
        var merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
        merged.SaveAs(@"F:/IronPdf/MergedDocument.pdf");
        Console.WriteLine("Merged PDF created: MergedDocument.pdf");
        // Load the merged PDF
        var pdf = PdfDocument.FromFile(@"F:/IronPdf/MergedDocument.pdf");
        // Extract the first page
        var firstPage = pdf.CopyPage(0);
        firstPage.SaveAs(@"F:/IronPdf/FirstPageOnly.pdf");
        Console.WriteLine("First page extracted: FirstPageOnly.pdf");
        // Extract pages 2 to 4 (note: index starts at 0)
        var middlePages = pdf.CopyPages(1, 3);
        middlePages.SaveAs(@"F:/IronPdf/Pages2to4.pdf");
        Console.WriteLine("Pages 2 to 4 extracted: Pages2to4.pdf");
        Console.WriteLine("Process completed. Press any key to exit.");
        Console.ReadKey();
    }
}
using IronPdf;
class Program
{
    static void Main(string[] args)
    {
        // Create first PDF with three pages
        const string html_a = @"
            <h1>Document A</h1>
            <p>This is the first page of Document A.</p>
            <div style='page-break-after: always;'></div>
            <h2>Document A - Page 2</h2>
            <p>This is the second page of Document A.</p>
            <div style='page-break-after: always;'></div>
            <h2>Document A - Page 3</h2>
            <p>This is the third and final page of Document A.</p>";
        // Create second PDF with two pages
        const string html_b = @"
            <h1>Document B</h1>
            <p>Welcome to the first page of Document B.</p>
            <div style='page-break-after: always;'></div>
            <h2>Document B - Page 2</h2>
            <p>This is the second and last page of Document B.</p>";
        // Render HTML to PDF
        var renderer = new ChromePdfRenderer();
        var pdfdoc_a = renderer.RenderHtmlAsPdf(html_a);
        var pdfdoc_b = renderer.RenderHtmlAsPdf(html_b);
        // Merge PDFs
        var merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
        merged.SaveAs(@"F:/IronPdf/MergedDocument.pdf");
        Console.WriteLine("Merged PDF created: MergedDocument.pdf");
        // Load the merged PDF
        var pdf = PdfDocument.FromFile(@"F:/IronPdf/MergedDocument.pdf");
        // Extract the first page
        var firstPage = pdf.CopyPage(0);
        firstPage.SaveAs(@"F:/IronPdf/FirstPageOnly.pdf");
        Console.WriteLine("First page extracted: FirstPageOnly.pdf");
        // Extract pages 2 to 4 (note: index starts at 0)
        var middlePages = pdf.CopyPages(1, 3);
        middlePages.SaveAs(@"F:/IronPdf/Pages2to4.pdf");
        Console.WriteLine("Pages 2 to 4 extracted: Pages2to4.pdf");
        Console.WriteLine("Process completed. Press any key to exit.");
        Console.ReadKey();
    }
}
Imports IronPdf
Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Create first PDF with three pages
		Const html_a As String = "
            <h1>Document A</h1>
            <p>This is the first page of Document A.</p>
            <div style='page-break-after: always;'></div>
            <h2>Document A - Page 2</h2>
            <p>This is the second page of Document A.</p>
            <div style='page-break-after: always;'></div>
            <h2>Document A - Page 3</h2>
            <p>This is the third and final page of Document A.</p>"
		' Create second PDF with two pages
		Const html_b As String = "
            <h1>Document B</h1>
            <p>Welcome to the first page of Document B.</p>
            <div style='page-break-after: always;'></div>
            <h2>Document B - Page 2</h2>
            <p>This is the second and last page of Document B.</p>"
		' Render HTML to PDF
		Dim renderer = New ChromePdfRenderer()
		Dim pdfdoc_a = renderer.RenderHtmlAsPdf(html_a)
		Dim pdfdoc_b = renderer.RenderHtmlAsPdf(html_b)
		' Merge PDFs
		Dim merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b)
		merged.SaveAs("F:/IronPdf/MergedDocument.pdf")
		Console.WriteLine("Merged PDF created: MergedDocument.pdf")
		' Load the merged PDF
		Dim pdf = PdfDocument.FromFile("F:/IronPdf/MergedDocument.pdf")
		' Extract the first page
		Dim firstPage = pdf.CopyPage(0)
		firstPage.SaveAs("F:/IronPdf/FirstPageOnly.pdf")
		Console.WriteLine("First page extracted: FirstPageOnly.pdf")
		' Extract pages 2 to 4 (note: index starts at 0)
		Dim middlePages = pdf.CopyPages(1, 3)
		middlePages.SaveAs("F:/IronPdf/Pages2to4.pdf")
		Console.WriteLine("Pages 2 to 4 extracted: Pages2to4.pdf")
		Console.WriteLine("Process completed. Press any key to exit.")
		Console.ReadKey()
	End Sub
End Class
VB   C#

APITemplate.io 與 IronPDF 的 C# PDF 庫比較:圖 8

以下是由程式碼生成的合併文件:

APITemplate io 和 IronPDF 的 C# PDF 函式庫比較:圖 9

填寫表單

自動化 表單填寫 在我的許多專案中一直是個巨大的時間節省器。 IronPDF 允許我以程式的方式填寫 PDF 表單,這對於處理大量的表單或創建個性化文件來說是非常寶貴的。 以下是一個更全面的表單填寫範例:

using IronPdf;
using System;
// Load the combined form
PdfDocument pdf = PdfDocument.FromFile(@"F:/completeForm.pdf");
// Handle radio buttons
var radioForm = pdf.Form.FindFormField("traveltype");
radioForm.Value = "Airplane";
// Handle checkbox
var checkboxForm = pdf.Form.FindFormField("taskCompleted");
checkboxForm.Value = "Yes";
// Handle combobox
var comboboxForm = pdf.Form.FindFormField("priority");
comboboxForm.Value = "Low";
// Print out all the available choices for combobox
foreach (var choice in comboboxForm.Choices)
{
    Console.WriteLine(choice);
}
// Handle text inputs
pdf.Form.FindFormField("firstname").Value = "John";
pdf.Form.FindFormField("lastname").Value = "Smith";
// Handle text area
pdf.Form.FindFormField("address").Value = "Iron Software LLC\r\n205 N. Michigan Ave.";
// Save the edited PDF
pdf.SaveAs(@"F:/completeFormEdited.pdf");
using IronPdf;
using System;
// Load the combined form
PdfDocument pdf = PdfDocument.FromFile(@"F:/completeForm.pdf");
// Handle radio buttons
var radioForm = pdf.Form.FindFormField("traveltype");
radioForm.Value = "Airplane";
// Handle checkbox
var checkboxForm = pdf.Form.FindFormField("taskCompleted");
checkboxForm.Value = "Yes";
// Handle combobox
var comboboxForm = pdf.Form.FindFormField("priority");
comboboxForm.Value = "Low";
// Print out all the available choices for combobox
foreach (var choice in comboboxForm.Choices)
{
    Console.WriteLine(choice);
}
// Handle text inputs
pdf.Form.FindFormField("firstname").Value = "John";
pdf.Form.FindFormField("lastname").Value = "Smith";
// Handle text area
pdf.Form.FindFormField("address").Value = "Iron Software LLC\r\n205 N. Michigan Ave.";
// Save the edited PDF
pdf.SaveAs(@"F:/completeFormEdited.pdf");
Imports Microsoft.VisualBasic
Imports IronPdf
Imports System
' Load the combined form
Private pdf As PdfDocument = PdfDocument.FromFile("F:/completeForm.pdf")
' Handle radio buttons
Private radioForm = pdf.Form.FindFormField("traveltype")
radioForm.Value = "Airplane"
' Handle checkbox
Dim checkboxForm = pdf.Form.FindFormField("taskCompleted")
checkboxForm.Value = "Yes"
' Handle combobox
Dim comboboxForm = pdf.Form.FindFormField("priority")
comboboxForm.Value = "Low"
' Print out all the available choices for combobox
For Each choice In comboboxForm.Choices
	Console.WriteLine(choice)
Next choice
' Handle text inputs
pdf.Form.FindFormField("firstname").Value = "John"
pdf.Form.FindFormField("lastname").Value = "Smith"
' Handle text area
pdf.Form.FindFormField("address").Value = "Iron Software LLC" & vbCrLf & "205 N. Michigan Ave."
' Save the edited PDF
pdf.SaveAs("F:/completeFormEdited.pdf")
VB   C#

我在幾個實際應用中使用過這個功能:

  1. 人力資源入職系統: 我們創建了一個系統,可以根據人力資源資料庫中的信息自動填寫新員工的文件,省去了數小時的手動數據輸入。

  2. 保險理賠處理: 我們為一間保險公司建置了一個系統,該系統自動填入保單持有人的信息,顯著加快了理賠申請的過程。

  3. 學校申請系統: 在一個教育專案中,我們實施了一個系統,根據學生資料填寫學校申請表,使得申請過程對學生和行政人員都更加簡便。

  4. 稅務表格生成: 對於一家會計事務所,我們創建了一個系統,該系統根據客戶的財務數據自動填寫稅務表格,從而減少錯誤並節省稅季時間。

    以程式化方式填寫表單的能力一直是自動化許多業務流程的關鍵因素,這不僅能顯著節省時間,還能減少手動資料輸入所帶來的錯誤。

浮水印

添加 浮水印 將文件轉換為PDF通常是為了品牌推廣、安全性或狀態指示。 IronPDF 提供靈活的水印功能,我在許多專案中發現非常實用。 以下是我如何使用浮水印的更詳細範例:

using IronPdf;
using IronSoftware.Drawing;
string watermarkHtml = @"
<img style='width: 250px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>");
// Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 90);
pdf.SaveAs("watermarkOpacity&amp;Rotation.pdf");
using IronPdf;
using IronSoftware.Drawing;
string watermarkHtml = @"
<img style='width: 250px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>");
// Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 90);
pdf.SaveAs("watermarkOpacity&amp;Rotation.pdf");
Imports IronPdf
Imports IronSoftware.Drawing
Private watermarkHtml As String = "
<img style='width: 250px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>"
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>")
' Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation:= 30, opacity:= 90)
pdf.SaveAs("watermarkOpacity&amp;Rotation.pdf")
VB   C#

APITemplate io 和 IronPDF 比較 C# 的 PDF 函式庫:圖 10

APITemplate 高級功能

動態模板生成

APITemplate 的動態模板生成是一項強大的功能,允許使用自訂 JSON 資料創建高度可自訂的文件。 APITemplate 的 API 支援動態元件。 您可以獲得程式碼的 PDF 和圖像輸出。 在 API 控制台中,我能夠使用所見即所得編輯器輕鬆生成 PDF 文件。

讓我們更深入地探討我是如何在我的專案中使用這個的。

using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
    class ReturnContent
    {
        public string download_url
        {
            get;
            set;
        }
        public string status
        {
            get;
            set;
        }
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
            var template_id = "bf077b23b4a407ae";
            var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}";
            var data = new
            {
                date = "15/05/2022",
                invoice_no = "435568799",
                sender_address1 = "3244 Jurong Drive",
                sender_address2 = "Falmouth Maine 1703",
                sender_phone = "255-781-6789",
                sender_email = "dev@ironsoftware.com",
                rece_addess1 = "2354 Lakeside Drive",
                rece_addess2 = "New York 234562 ",
                rece_phone = "34333-84-223",
                rece_email = "info@ironsoftware.com",
                items = new[] {
            new {
              item_name = "Oil",
                unit = 1,
                unit_price = 100,
                total = 100
            },
            new {
              item_name = "Rice",
                unit = 2,
                unit_price = 200,
                total = 400
            },
            new {
              item_name = "Orange",
                unit = 7,
                unit_price = 20,
                total = 1400
            }
          },
                total = "total",
                footer_email = "info@ironsoftware.com"
            };
            var json_content = JsonSerializer.Serialize(data);
            var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
            var byteContent = new ByteArrayContent(buffer);
            Console.WriteLine(json_content);
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
            var response = await client.PostAsync(url, byteContent);
            var ret = await response.Content.ReadAsStringAsync();
            var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
            if (returnContent.status == "success")
            {
                Console.WriteLine($"Downloading {returnContent.download_url}...");
                var download_response = await client.GetAsync(returnContent.download_url);
                using (var stream = await download_response.Content.ReadAsStreamAsync())
                {
                    var fileInfo = new FileInfo(@"F:/generated_document.pdf");
                    using (var fileStream = fileInfo.OpenWrite())
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                }
                Console.WriteLine("PDF file has been downloaded and saved as 'generated_document.pdf'");
            }
        }
    }
}
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
    class ReturnContent
    {
        public string download_url
        {
            get;
            set;
        }
        public string status
        {
            get;
            set;
        }
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
            var template_id = "bf077b23b4a407ae";
            var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}";
            var data = new
            {
                date = "15/05/2022",
                invoice_no = "435568799",
                sender_address1 = "3244 Jurong Drive",
                sender_address2 = "Falmouth Maine 1703",
                sender_phone = "255-781-6789",
                sender_email = "dev@ironsoftware.com",
                rece_addess1 = "2354 Lakeside Drive",
                rece_addess2 = "New York 234562 ",
                rece_phone = "34333-84-223",
                rece_email = "info@ironsoftware.com",
                items = new[] {
            new {
              item_name = "Oil",
                unit = 1,
                unit_price = 100,
                total = 100
            },
            new {
              item_name = "Rice",
                unit = 2,
                unit_price = 200,
                total = 400
            },
            new {
              item_name = "Orange",
                unit = 7,
                unit_price = 20,
                total = 1400
            }
          },
                total = "total",
                footer_email = "info@ironsoftware.com"
            };
            var json_content = JsonSerializer.Serialize(data);
            var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
            var byteContent = new ByteArrayContent(buffer);
            Console.WriteLine(json_content);
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
            var response = await client.PostAsync(url, byteContent);
            var ret = await response.Content.ReadAsStringAsync();
            var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
            if (returnContent.status == "success")
            {
                Console.WriteLine($"Downloading {returnContent.download_url}...");
                var download_response = await client.GetAsync(returnContent.download_url);
                using (var stream = await download_response.Content.ReadAsStreamAsync())
                {
                    var fileInfo = new FileInfo(@"F:/generated_document.pdf");
                    using (var fileStream = fileInfo.OpenWrite())
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                }
                Console.WriteLine("PDF file has been downloaded and saved as 'generated_document.pdf'");
            }
        }
    }
}
Imports System
Imports System.IO
Imports System.Net.Http
Imports System.Text.Json
Imports System.Threading.Tasks
Namespace csharp
	Friend Class ReturnContent
		Public Property download_url() As String
		Public Property status() As String
	End Class
	Friend Class Program
		Shared Async Function Main(ByVal args() As String) As Task
			Dim api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw="
			Dim template_id = "bf077b23b4a407ae"
			Dim url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}"
			Dim data = New With {
				Key .date = "15/05/2022",
				Key .invoice_no = "435568799",
				Key .sender_address1 = "3244 Jurong Drive",
				Key .sender_address2 = "Falmouth Maine 1703",
				Key .sender_phone = "255-781-6789",
				Key .sender_email = "dev@ironsoftware.com",
				Key .rece_addess1 = "2354 Lakeside Drive",
				Key .rece_addess2 = "New York 234562 ",
				Key .rece_phone = "34333-84-223",
				Key .rece_email = "info@ironsoftware.com",
				Key .items = {
					New With {
						Key .item_name = "Oil",
						Key .unit = 1,
						Key .unit_price = 100,
						Key .total = 100
					},
					New With {
						Key .item_name = "Rice",
						Key .unit = 2,
						Key .unit_price = 200,
						Key .total = 400
					},
					New With {
						Key .item_name = "Orange",
						Key .unit = 7,
						Key .unit_price = 20,
						Key .total = 1400
					}
				},
				Key .total = "total",
				Key .footer_email = "info@ironsoftware.com"
			}
			Dim json_content = JsonSerializer.Serialize(data)
			Dim buffer = System.Text.Encoding.UTF8.GetBytes(json_content)
			Dim byteContent = New ByteArrayContent(buffer)
			Console.WriteLine(json_content)
			Dim client = New HttpClient()
			client.DefaultRequestHeaders.Add("X-API-KEY", api_key)
			Dim response = Await client.PostAsync(url, byteContent)
			Dim ret = Await response.Content.ReadAsStringAsync()
			Dim returnContent = JsonSerializer.Deserialize(Of ReturnContent)(ret)
			If returnContent.status = "success" Then
				Console.WriteLine($"Downloading {returnContent.download_url}...")
				Dim download_response = Await client.GetAsync(returnContent.download_url)
				Using stream = Await download_response.Content.ReadAsStreamAsync()
					Dim fileInfo As New FileInfo("F:/generated_document.pdf")
					Using fileStream = fileInfo.OpenWrite()
						Await stream.CopyToAsync(fileStream)
					End Using
				End Using
				Console.WriteLine("PDF file has been downloaded and saved as 'generated_document.pdf'")
			End If
		End Function
	End Class
End Namespace
VB   C#

APITemplate io和IronPDF在C# PDF庫的比較:圖11

這是生成的 PDF 文件:

APITemplate io 與 IronPDF 的 C# PDF 函式庫比較:圖 12

批量 PDF 生成

APITemplate 的批量 PDF 生成功能在一次 API 呼叫中創建多個文件時是遊戲改變者。 以下是我如何使用它的更詳細範例:

using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace csharp
{
    class ReturnContent
    {
        public string download_url { get; set; }
        public string status { get; set; }
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
            var template_id = "d4f77b23b4ab09fa"; 
            var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}";
            var membershipCards = new List<object>
            {
                new
                {
                    name = "Iron Dev 1",
                    email = "dev1@ironsoftware.com",
                    membership_id = "M001",
                    expiry_date = "2024-12-31"
                },
                new
                {
                    name = "Iron Dev 2",
                    email = "dev2@ironsoftware.com",
                    membership_id = "M002",
                    expiry_date = "2025-06-30"
                },
                new
                {
                    name = "Iron Dev 3",
                    email = "dev3@ironsoftware.com",
                    membership_id = "M003",
                    expiry_date = "2024-09-15"
                }
            };
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
            for (int i = 0; i < membershipCards.Count; i++)
            {
                var json_content = JsonSerializer.Serialize(membershipCards[i]);
                var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
                var byteContent = new ByteArrayContent(buffer);
                Console.WriteLine($"Creating PDF for {((dynamic)membershipCards[i]).name}...");
                var response = await client.PostAsync(url, byteContent);
                var ret = await response.Content.ReadAsStringAsync();
                var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
                if (returnContent.status == "success")
                {
                    Console.WriteLine($"Downloading {returnContent.download_url}...");
                    var download_response = await client.GetAsync(returnContent.download_url);
                    using (var stream = await download_response.Content.ReadAsStreamAsync())
                    {
                        var fileInfo = new FileInfo($"F:/membership_card_{i + 1}.pdf");
                        using (var fileStream = fileInfo.OpenWrite())
                        {
                            await stream.CopyToAsync(fileStream);
                        }
                    }
                    Console.WriteLine($"PDF file has been downloaded and saved as 'membership_card_{i + 1}.pdf'");
                }
                else
                {
                    Console.WriteLine($"Failed to create PDF for {((dynamic)membershipCards[i]).name}. Status: {returnContent.status}");
                }
            }
        }
    }
}
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace csharp
{
    class ReturnContent
    {
        public string download_url { get; set; }
        public string status { get; set; }
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
            var template_id = "d4f77b23b4ab09fa"; 
            var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}";
            var membershipCards = new List<object>
            {
                new
                {
                    name = "Iron Dev 1",
                    email = "dev1@ironsoftware.com",
                    membership_id = "M001",
                    expiry_date = "2024-12-31"
                },
                new
                {
                    name = "Iron Dev 2",
                    email = "dev2@ironsoftware.com",
                    membership_id = "M002",
                    expiry_date = "2025-06-30"
                },
                new
                {
                    name = "Iron Dev 3",
                    email = "dev3@ironsoftware.com",
                    membership_id = "M003",
                    expiry_date = "2024-09-15"
                }
            };
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
            for (int i = 0; i < membershipCards.Count; i++)
            {
                var json_content = JsonSerializer.Serialize(membershipCards[i]);
                var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
                var byteContent = new ByteArrayContent(buffer);
                Console.WriteLine($"Creating PDF for {((dynamic)membershipCards[i]).name}...");
                var response = await client.PostAsync(url, byteContent);
                var ret = await response.Content.ReadAsStringAsync();
                var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
                if (returnContent.status == "success")
                {
                    Console.WriteLine($"Downloading {returnContent.download_url}...");
                    var download_response = await client.GetAsync(returnContent.download_url);
                    using (var stream = await download_response.Content.ReadAsStreamAsync())
                    {
                        var fileInfo = new FileInfo($"F:/membership_card_{i + 1}.pdf");
                        using (var fileStream = fileInfo.OpenWrite())
                        {
                            await stream.CopyToAsync(fileStream);
                        }
                    }
                    Console.WriteLine($"PDF file has been downloaded and saved as 'membership_card_{i + 1}.pdf'");
                }
                else
                {
                    Console.WriteLine($"Failed to create PDF for {((dynamic)membershipCards[i]).name}. Status: {returnContent.status}");
                }
            }
        }
    }
}
'INSTANT VB NOTE: 'Option Strict Off' is used here since dynamic typing is used:
Option Strict Off

Imports System
Imports System.IO
Imports System.Net.Http
Imports System.Text.Json
Imports System.Threading.Tasks
Imports System.Collections.Generic
Namespace csharp
	Friend Class ReturnContent
		Public Property download_url() As String
		Public Property status() As String
	End Class
	Friend Class Program
		Shared Async Function Main(ByVal args() As String) As Task
			Dim api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw="
			Dim template_id = "d4f77b23b4ab09fa"
			Dim url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={template_id}"
			Dim membershipCards = New List(Of Object) From {
				New With {
					Key .name = "Iron Dev 1",
					Key .email = "dev1@ironsoftware.com",
					Key .membership_id = "M001",
					Key .expiry_date = "2024-12-31"
				},
				New With {
					Key .name = "Iron Dev 2",
					Key .email = "dev2@ironsoftware.com",
					Key .membership_id = "M002",
					Key .expiry_date = "2025-06-30"
				},
				New With {
					Key .name = "Iron Dev 3",
					Key .email = "dev3@ironsoftware.com",
					Key .membership_id = "M003",
					Key .expiry_date = "2024-09-15"
				}
			}
			Dim client = New HttpClient()
			client.DefaultRequestHeaders.Add("X-API-KEY", api_key)
			For i As Integer = 0 To membershipCards.Count - 1
				Dim json_content = JsonSerializer.Serialize(membershipCards(i))
				Dim buffer = System.Text.Encoding.UTF8.GetBytes(json_content)
				Dim byteContent = New ByteArrayContent(buffer)
'INSTANT VB NOTE: In the following line, Instant VB substituted 'Object' for 'dynamic' - this will work in VB with Option Strict Off:
				Console.WriteLine($"Creating PDF for {CType(membershipCards(i), Object).name}...")
				Dim response = Await client.PostAsync(url, byteContent)
				Dim ret = Await response.Content.ReadAsStringAsync()
				Dim returnContent = JsonSerializer.Deserialize(Of ReturnContent)(ret)
				If returnContent.status = "success" Then
					Console.WriteLine($"Downloading {returnContent.download_url}...")
					Dim download_response = Await client.GetAsync(returnContent.download_url)
					Using stream = Await download_response.Content.ReadAsStreamAsync()
						Dim fileInfo As New FileInfo($"F:/membership_card_{i + 1}.pdf")
						Using fileStream = fileInfo.OpenWrite()
							Await stream.CopyToAsync(fileStream)
						End Using
					End Using
					Console.WriteLine($"PDF file has been downloaded and saved as 'membership_card_{i + 1}.pdf'")
				Else
'INSTANT VB NOTE: In the following line, Instant VB substituted 'Object' for 'dynamic' - this will work in VB with Option Strict Off:
					Console.WriteLine($"Failed to create PDF for {CType(membershipCards(i), Object).name}. Status: {returnContent.status}")
				End If
			Next i
		End Function
	End Class
End Namespace
VB   C#

此程式碼在單一 API 呼叫中生成多張會員卡。 每張卡皆根據個別會員資訊進行自訂。 以下是由此代碼生成的卡片:

APITemplate io 與 IronPDF C# PDF 庫比較:圖 13

圖片生成

雖然 PDF 生成是 APITemplate 的主要焦點,但其圖像生成功能同樣令人印象深刻。您可以使用控制台中的圖像模板生成社交媒體圖像。 它還提供響應式圖像的智能裁剪。橫幅生成API與圖像API相同。 以下是我如何使用它的更複雜範例:

using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
    class ReturnContent
    {
        public string download_url { get; set; }
        public string status { get; set; }
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
            var template_id = "f4377b23b4aeeed0";
            var url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}";
            var json_content = @"{
    ""overrides"": [
        {
            ""name"": ""rect_image_bg"",
            ""stroke"": ""grey"",
            ""src"": ""https://images.unsplash.com/photo-1542401886-65d6c61db217?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHwzfHxkZXNlcnR8ZW58MHwwfHx8MTYyMTUxOTI2OA&ixlib=rb-1.2.1&q=80&w=1080""
        },
        {
            ""name"": ""rect_container"",
            ""stroke"": ""grey"",
            ""backgroundColor"": ""rgba(255, 255, 255, 0.62)""
        },
        {
            ""name"": ""text_quote"",
            ""text"": ""Just witnessed the most breathtaking sunset over the Sahara. The way the light dances on the dunes, painting the sky in shades of orange and purple, is truly magical. Nature's artistry at its finest! 🌅🐫 #DesertAdventures #SaharaSkies"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#414141""
        },
        {
            ""name"": ""text_footer"",
            ""text"": ""2024-07-30 - Twitter - iPhone 16 Pro"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#666666""
        },
        {
            ""name"": ""circle_profile"",
            ""stroke"": ""grey"",
            ""src"": ""https://images.unsplash.com/photo-1520998116484-6eeb2f72b5b9?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHw2Mnx8aGFwcHl8ZW58MHwwfHx8MTYyMTY5MjkwNw&ixlib=rb-1.2.1&q=80&w=1080""
        },
        {
            ""name"": ""text_name"",
            ""text"": ""Sarah Wanderlust"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#4E4E4E""
        },
        {
            ""name"": ""text_twitter"",
            ""text"": ""@sarahexplores"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#4E4E4E""
        }
    ]
}";
            var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
            var byteContent = new ByteArrayContent(buffer);
            Console.WriteLine(json_content);
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
            var response = await client.PostAsync(url, byteContent);
            var ret = await response.Content.ReadAsStringAsync();
            var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
            if (returnContent.status == "success")
            {
                Console.WriteLine($"Downloading {returnContent.download_url}...");
                var download_response = await client.GetAsync(returnContent.download_url);
                using (var stream = await download_response.Content.ReadAsStreamAsync())
                {
                    var fileInfo = new FileInfo("image.jpeg");
                    using (var fileStream = fileInfo.OpenWrite())
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                }
            }
        }
    }
}
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
    class ReturnContent
    {
        public string download_url { get; set; }
        public string status { get; set; }
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw=";
            var template_id = "f4377b23b4aeeed0";
            var url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}";
            var json_content = @"{
    ""overrides"": [
        {
            ""name"": ""rect_image_bg"",
            ""stroke"": ""grey"",
            ""src"": ""https://images.unsplash.com/photo-1542401886-65d6c61db217?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHwzfHxkZXNlcnR8ZW58MHwwfHx8MTYyMTUxOTI2OA&ixlib=rb-1.2.1&q=80&w=1080""
        },
        {
            ""name"": ""rect_container"",
            ""stroke"": ""grey"",
            ""backgroundColor"": ""rgba(255, 255, 255, 0.62)""
        },
        {
            ""name"": ""text_quote"",
            ""text"": ""Just witnessed the most breathtaking sunset over the Sahara. The way the light dances on the dunes, painting the sky in shades of orange and purple, is truly magical. Nature's artistry at its finest! 🌅🐫 #DesertAdventures #SaharaSkies"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#414141""
        },
        {
            ""name"": ""text_footer"",
            ""text"": ""2024-07-30 - Twitter - iPhone 16 Pro"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#666666""
        },
        {
            ""name"": ""circle_profile"",
            ""stroke"": ""grey"",
            ""src"": ""https://images.unsplash.com/photo-1520998116484-6eeb2f72b5b9?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHw2Mnx8aGFwcHl8ZW58MHwwfHx8MTYyMTY5MjkwNw&ixlib=rb-1.2.1&q=80&w=1080""
        },
        {
            ""name"": ""text_name"",
            ""text"": ""Sarah Wanderlust"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#4E4E4E""
        },
        {
            ""name"": ""text_twitter"",
            ""text"": ""@sarahexplores"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#4E4E4E""
        }
    ]
}";
            var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
            var byteContent = new ByteArrayContent(buffer);
            Console.WriteLine(json_content);
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
            var response = await client.PostAsync(url, byteContent);
            var ret = await response.Content.ReadAsStringAsync();
            var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
            if (returnContent.status == "success")
            {
                Console.WriteLine($"Downloading {returnContent.download_url}...");
                var download_response = await client.GetAsync(returnContent.download_url);
                using (var stream = await download_response.Content.ReadAsStreamAsync())
                {
                    var fileInfo = new FileInfo("image.jpeg");
                    using (var fileStream = fileInfo.OpenWrite())
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                }
            }
        }
    }
}
Imports System
Imports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Namespace csharp
	Friend Class ReturnContent
		Public Property download_url() As String
		Public Property status() As String
	End Class
	Friend Class Program
		Shared Async Function Main(ByVal args() As String) As Task
			Dim api_key = "a9e4MjA2NTg6MTc3Njk6Uk1ZSzVjTWs1T3d6VE9Mdw="
			Dim template_id = "f4377b23b4aeeed0"
			Dim url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}"
			Dim json_content = "{
    ""overrides"": [
        {
            ""name"": ""rect_image_bg"",
            ""stroke"": ""grey"",
            ""src"": ""https://images.unsplash.com/photo-1542401886-65d6c61db217?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHwzfHxkZXNlcnR8ZW58MHwwfHx8MTYyMTUxOTI2OA&ixlib=rb-1.2.1&q=80&w=1080""
        },
        {
            ""name"": ""rect_container"",
            ""stroke"": ""grey"",
            ""backgroundColor"": ""rgba(255, 255, 255, 0.62)""
        },
        {
            ""name"": ""text_quote"",
            ""text"": ""Just witnessed the most breathtaking sunset over the Sahara. The way the light dances on the dunes, painting the sky in shades of orange and purple, is truly magical. Nature's artistry at its finest! 🌅🐫 #DesertAdventures #SaharaSkies"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#414141""
        },
        {
            ""name"": ""text_footer"",
            ""text"": ""2024-07-30 - Twitter - iPhone 16 Pro"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#666666""
        },
        {
            ""name"": ""circle_profile"",
            ""stroke"": ""grey"",
            ""src"": ""https://images.unsplash.com/photo-1520998116484-6eeb2f72b5b9?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxOTc1MDZ8MHwxfHNlYXJjaHw2Mnx8aGFwcHl8ZW58MHwwfHx8MTYyMTY5MjkwNw&ixlib=rb-1.2.1&q=80&w=1080""
        },
        {
            ""name"": ""text_name"",
            ""text"": ""Sarah Wanderlust"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#4E4E4E""
        },
        {
            ""name"": ""text_twitter"",
            ""text"": ""@sarahexplores"",
            ""textBackgroundColor"": ""rgba(246, 243, 243, 0)"",
            ""color"": ""#4E4E4E""
        }
    ]
}"
			Dim buffer = System.Text.Encoding.UTF8.GetBytes(json_content)
			Dim byteContent = New ByteArrayContent(buffer)
			Console.WriteLine(json_content)
			Dim client = New HttpClient()
			client.DefaultRequestHeaders.Add("X-API-KEY", api_key)
			Dim response = Await client.PostAsync(url, byteContent)
			Dim ret = Await response.Content.ReadAsStringAsync()
			Dim returnContent = JsonSerializer.Deserialize(Of ReturnContent)(ret)
			If returnContent.status = "success" Then
				Console.WriteLine($"Downloading {returnContent.download_url}...")
				Dim download_response = Await client.GetAsync(returnContent.download_url)
				Using stream = Await download_response.Content.ReadAsStreamAsync()
					Dim fileInfo As New FileInfo("image.jpeg")
					Using fileStream = fileInfo.OpenWrite()
						Await stream.CopyToAsync(fileStream)
					End Using
				End Using
			End If
		End Function
	End Class
End Namespace
VB   C#

APITemplate io 和 IronPDF 的 C# PDF 庫比較:圖 14

此範例生成一個產品促銷圖像,具有動態內容、自訂的背景顏色,以及嵌入的產品圖像。

QR Code 生成

APITemplate內建的QR碼生成功能極大地增強了我的許多專案。 您可以在 QR 碼的內容中放置數據 URL。 以下是我如何使用它的更複雜範例:

using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
    class ReturnContent
    {
        public string download_url { get; set; }
        public string status { get; set; }
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var api_key = "API-Key";
            var template_id = "Template-Key";
            var url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}";
            var json_content = @"{
    ""overrides"": [
        {
            ""name"": ""background-color"",
            ""stroke"": ""grey"",
            ""backgroundColor"": ""#FFFFFF""
        },
        {
            ""name"": ""qr_1"",
            ""content"": ""http://ironpdf.com/"",
            ""backgroundColor"": ""white"",
            ""color"": ""#000000""
        }
    ]
}";
            var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
            var byteContent = new ByteArrayContent(buffer);
            //Console.WriteLine(json_content);
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
            var response = await client.PostAsync(url, byteContent);
            var ret = await response.Content.ReadAsStringAsync();
            var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
            Console.WriteLine(returnContent.status);
            if (returnContent.status == "success")
            {
                Console.WriteLine($"Downloading {returnContent.download_url}...");
                var download_response = await client.GetAsync(returnContent.download_url);
                using (var stream = await download_response.Content.ReadAsStreamAsync())
                {
                    var fileInfo = new FileInfo(@"F:/QRimage.jpeg");
                    using (var fileStream = fileInfo.OpenWrite())
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                }
            }
        }
    }
}
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace csharp
{
    class ReturnContent
    {
        public string download_url { get; set; }
        public string status { get; set; }
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var api_key = "API-Key";
            var template_id = "Template-Key";
            var url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}";
            var json_content = @"{
    ""overrides"": [
        {
            ""name"": ""background-color"",
            ""stroke"": ""grey"",
            ""backgroundColor"": ""#FFFFFF""
        },
        {
            ""name"": ""qr_1"",
            ""content"": ""http://ironpdf.com/"",
            ""backgroundColor"": ""white"",
            ""color"": ""#000000""
        }
    ]
}";
            var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
            var byteContent = new ByteArrayContent(buffer);
            //Console.WriteLine(json_content);
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("X-API-KEY", api_key);
            var response = await client.PostAsync(url, byteContent);
            var ret = await response.Content.ReadAsStringAsync();
            var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);
            Console.WriteLine(returnContent.status);
            if (returnContent.status == "success")
            {
                Console.WriteLine($"Downloading {returnContent.download_url}...");
                var download_response = await client.GetAsync(returnContent.download_url);
                using (var stream = await download_response.Content.ReadAsStreamAsync())
                {
                    var fileInfo = new FileInfo(@"F:/QRimage.jpeg");
                    using (var fileStream = fileInfo.OpenWrite())
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                }
            }
        }
    }
}
Imports System
Imports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Namespace csharp
	Friend Class ReturnContent
		Public Property download_url() As String
		Public Property status() As String
	End Class
	Friend Class Program
		Shared Async Function Main(ByVal args() As String) As Task
			Dim api_key = "API-Key"
			Dim template_id = "Template-Key"
			Dim url = $"https://rest.apitemplate.io/v2/create-image?template_id={template_id}"
			Dim json_content = "{
    ""overrides"": [
        {
            ""name"": ""background-color"",
            ""stroke"": ""grey"",
            ""backgroundColor"": ""#FFFFFF""
        },
        {
            ""name"": ""qr_1"",
            ""content"": ""http://ironpdf.com/"",
            ""backgroundColor"": ""white"",
            ""color"": ""#000000""
        }
    ]
}"
			Dim buffer = System.Text.Encoding.UTF8.GetBytes(json_content)
			Dim byteContent = New ByteArrayContent(buffer)
			'Console.WriteLine(json_content);
			Dim client = New HttpClient()
			client.DefaultRequestHeaders.Add("X-API-KEY", api_key)
			Dim response = Await client.PostAsync(url, byteContent)
			Dim ret = Await response.Content.ReadAsStringAsync()
			Dim returnContent = JsonSerializer.Deserialize(Of ReturnContent)(ret)
			Console.WriteLine(returnContent.status)
			If returnContent.status = "success" Then
				Console.WriteLine($"Downloading {returnContent.download_url}...")
				Dim download_response = Await client.GetAsync(returnContent.download_url)
				Using stream = Await download_response.Content.ReadAsStreamAsync()
					Dim fileInfo As New FileInfo("F:/QRimage.jpeg")
					Using fileStream = fileInfo.OpenWrite()
						Await stream.CopyToAsync(fileStream)
					End Using
				End Using
			End If
		End Function
	End Class
End Namespace
VB   C#

APITemplate io 與 IronPDF C# PDF 函式庫比較:圖 15

文件和支援

作為經常從事 PDF 生成和操作的 C# 開發人員,我發現文檔和支持的質量可以決定一個項目的成敗。 讓我們深入探討我在 IronPDF 和 APITemplate 的文件和支持方面的經驗。

IronPDF

文件資料

IronPDF 的文件內容全面且結構良好,這對我的項目有很大幫助。 以下是我經驗的詳細介紹:IronPDF 的文件可在 https://ironpdf.com/docs/ 獲取,內容非常全面。以下是我欣賞的一些關鍵方面:

  1. 入門指南: 文檔以清晰的逐步指南開始,指導如何通過 NuGet 安裝 IronPDF 並創建您的第一個 PDF。 這幫助我能夠在初期專案中快速運行。

  2. API 參考: API 參考資料非常全面,涵蓋了所有的類和方法。 每個項目都包含 C# 示例,這些示例在我實現特定功能時非常有價值。

  3. 程式碼範例: 整篇文件中有許多程式碼片段和完整的範例。 這些在我需要實現更複雜的 PDF 操作時特別有幫助。

  4. 教學與操作指南: IronPDF 提供詳細的教學,涵蓋從 HTML 建立 PDF、添加浮水印或處理表單等常見任務。 這些指引我完成更高級的使用案例。

  5. 故障排除部分: 文檔包括一個故障排除部分,以解決常見問題。 這幫助我在遇到錯誤或意外行為時節省了時間。

支援

IronPDF 的 聯繫 在我的經驗中,響應迅速,支援渠道非常有幫助:

  1. 電子郵件支援: 當我遇到複雜問題時,我曾使用過他們的電子郵件支援。 回應時間通常在24小時之內,而且支援團隊對該產品非常了解。

  2. 社群論壇: IronPDF 維護一個社群論壇,開發者可以在此提問並分享解決方案。 我既找到了我問題的答案,也根據我的經驗提供了解決方案。

  3. Stack Overflow: IronPDF 團隊積極監控 [ironpdf] 標籤 在 Stack Overflow 上。 我收到過對我在那裡提出的問題的有幫助的回應。

  4. 定期更新: IronPDF 經常釋出包含錯誤修正和新功能的更新。 changelog 非常詳細,有助於我了解每個版本中的新增或更改內容。

  5. 遷移指南: 當主要版本之間有重大變更時,IronPDF 提供了遷移指南。 這些在將我的項目更新到較新版本的庫方面至關重要。

APITemplate

APITemplate 的文檔和支援結構與 IronPDF 不同,反映了其作為雲端服務的特性。這是我的經歷:

文件資料

APITemplate 的文件可在 https://docs.apitemplate.io/reference/api-reference.html 上獲取,專注於 API 的使用。 以下是關鍵點:

  1. API 參考: 文件提供了明確的 API 參考,詳細說明了所有可用的端點、所需的參數和回應格式。 這一直是我在將 APITemplate 整合到我的 C# 應用程式中時的首選資源。

  2. 身份驗證: 有一個專門的身份驗證部分,清楚說明如何使用 API 金鑰。 這在我剛開始使用這項服務時是至關重要的。

支援

APITemplate 的支援結構更側重於電子郵件支援:

  1. 電子郵件支援: 當我遇到問題或有疑問時,我使用他們的電子郵件支援。 回應時間一般在1-2個工作日內。

  2. 常見問題解答部分: 文件包括了常見問題解答部分,以解答常見問題。 這通常是我遇到問題時的第一個求助站。

授權

IronPDF 價格和授權

APITemplate io 和 IronPDF 比較 C# PDF 函式庫:圖16

IronPDF 提供多種定價方案,以滿足不同的需求:

  1. Lite: 定價為 $749,適合單一開發者從事單一項目。 這是一筆一次性費用,使其成為小型專案或個人開發者的實惠選擇。

  2. 專業版:以 $1,499,此選項支援最多 10 名開發人員、10 個地點和 10 個專案。 此級別還包括一次性費用,並為中小型團隊提供更多靈活性。

  3. Unlimited:定價為 $2,999,此層級允許無限制的開發者、地點和項目。 這對於需要廣泛使用且無限制的大型團隊和企業而言是理想的選擇。

    IronPDF 也為大型組織和需要將 PDF 功能集成到商業產品中的企業提供企業與 OEM 重新分發許可證。 它還提供一個 免費試用 測試。

APITemplate 定價和授權

APITemplate 提供了另一種方法,其基於 API 的 PDF 生成服務定價通常基於 API 調用次數,這使其對不同的使用模式更具彈性。

  1. 基本方案:通常以較低的價格起點開始,每月有有限次數的 API 調用。 這適用於有最少 PDF 生成需求的小型專案或企業。

  2. 標準計劃:此計劃包含更多的 API 調用和附加功能,適合中型企業。

  3. 企業方案:針對高量用戶設計,提供最多的 API 呼叫次數以及優先支援和自訂整合等高級功能。

    APITemplate 的授權相當簡單,通常與每月或每年的訂閱模式相關聯。

主要差異

  1. 定價模型:IronPDF 採用一次性收費模式,對於持續且大量使用而言,從長遠來看可能是具有成本效益的。 另一方面,APITemplate 使用訂閱制模型,這種模式在使用上可以更靈活和具伸縮性。

  2. 支援和更新:IronPDF 購買時包含一年支援和更新服務,並可選擇延長此期限。 APITemplate 的訂閱計劃通常包含持續的支持和更新作為套裝的一部分。

為什麼選擇 IronPDF?

IronPDF 和 APITemplate 都提供從 HTML 內容生成 PDF 的功能,但 IronPDF 的實現更強大且更靈活。 以下是比較:

IronPDF

using IronPdf;
var renderer = new ChromePdfRenderer();
var html = @"
<html>
<head>
    <style>
        body { font-family: Arial, sans-serif; }
        .header { color: #0066cc; font-size: 24px; }
        .content { margin-top: 20px; }
    </style>
</head>
<body>
    <div class='header'>Dynamic Report</div>
    <div class='content'>
        <p>This report was generated on: <script>document.write(new Date().toLocaleString());</script></p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("IronPDF_report.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();
var html = @"
<html>
<head>
    <style>
        body { font-family: Arial, sans-serif; }
        .header { color: #0066cc; font-size: 24px; }
        .content { margin-top: 20px; }
    </style>
</head>
<body>
    <div class='header'>Dynamic Report</div>
    <div class='content'>
        <p>This report was generated on: <script>document.write(new Date().toLocaleString());</script></p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("IronPDF_report.pdf");
Imports IronPdf
Private renderer = New ChromePdfRenderer()
Private html = "
<html>
<head>
    <style>
        body { font-family: Arial, sans-serif; }
        .header { color: #0066cc; font-size: 24px; }
        .content { margin-top: 20px; }
    </style>
</head>
<body>
    <div class='header'>Dynamic Report</div>
    <div class='content'>
        <p>This report was generated on: <script>document.write(new Date().toLocaleString());</script></p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
</body>
</html>"
Private pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("IronPDF_report.pdf")
VB   C#

APITemplate

using System.Net.Http;
using System.Text.Json;
var apiKey = "your_api_key";
var templateId = "your_template_id";
var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={templateId}";
var data = new
{
    header = "Dynamic Report",
    content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    date = DateTime.Now.ToShortDateString()
};
var json = JsonSerializer.Serialize(data);
var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", apiKey);
var response = await client.PostAsync(url, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("APITemplate_report.pdf", pdfBytes);
using System.Net.Http;
using System.Text.Json;
var apiKey = "your_api_key";
var templateId = "your_template_id";
var url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={templateId}";
var data = new
{
    header = "Dynamic Report",
    content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    date = DateTime.Now.ToShortDateString()
};
var json = JsonSerializer.Serialize(data);
var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-KEY", apiKey);
var response = await client.PostAsync(url, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("APITemplate_report.pdf", pdfBytes);
Imports System.Net.Http
Imports System.Text.Json
Private apiKey = "your_api_key"
Private templateId = "your_template_id"
Private url = $"https://rest.apitemplate.io/v2/create-pdf?template_id={templateId}"
Private data = New With {
	Key .header = "Dynamic Report",
	Key .content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
	Key .date = DateTime.Now.ToShortDateString()
}
Private json = JsonSerializer.Serialize(data)
Private content = New StringContent(json, System.Text.Encoding.UTF8, "application/json")
Private client = New HttpClient()
client.DefaultRequestHeaders.Add("X-API-KEY", apiKey)
Dim response = Await client.PostAsync(url, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
File.WriteAllBytes("APITemplate_report.pdf", pdfBytes)
VB   C#

主要差異

  1. JavaScript 支援:IronPDF 完全支援在 HTML 中執行 JavaScript,允許生成動態內容。 (例如範例中的當前日期). APITemplate 通常需要事先提供所有數據。

  2. CSS 彈性:使用 IronPDF,您可以直接在 HTML 中完全控制 CSS 樣式。 APITemplate 經常需要預先定義的模板,且定制選項有限。

  3. 性能:IronPDF 在本地處理 HTML,從而加快 PDF 的生成速度,尤其是針對複雜文件。 APITemplate 的雲端方法可能會引入延遲。

  4. 離線功能:IronPDF可離線運作,這對於網路連接受限或有高安全性要求的應用程式非常有幫助。 APITemplate始終需要網路連線。

  5. 動態內容:IronPDF允許即時生成更具動態的內容,而APITemplate則通常需要預定義的模板結構。

  6. 自訂化:IronPDF 提供對 PDF 生成過程的更精細控制,包括頁面大小、邊距和其他 PDF 特定設定的選項。

  7. 一致性:IronPDF 使用自己的渲染引擎,確保在不同環境中的渲染一致。APITemplate 的輸出可能會因其伺服器配置不同而有所變化。

結論

在多個 C# 專案中廣泛使用 IronPDF 和 APITemplate 之後,我開始欣賞每個工具的獨特優勢。 然而,在我大多數與 PDF 相關的任務中,IronPDF 一直證明是更優的選擇。APITemplate 雖有其優勢,特別是在簡單、基於模板的文件生成方面,但我發現 IronPDF 的多功能性使其能同樣有效地處理這些任務,並在需要時提供處理更複雜 PDF 操作的能力。

總而言之,儘管這兩個工具各有其優勢,但在 C# 開發中的 PDF 操作方面,IronPDF 始終被證明是更強大、更靈活且性價比更高的解決方案。 它強大的功能集、卓越的性能和全面的支持使其成為我進行任何 PDF 相關任務的首選,從最簡單的文件生成到最複雜的 PDF 操作。

下一個 >
C#中的PDFA庫(.NET開發人員的比較清單)

準備開始了嗎? 版本: 2024.10 剛剛發布

免費 NuGet 下載 總下載次數: 10,993,239 查看許可證 >