產品比較

IronPDF和Docraptor - 全面比較

發佈 2022年3月22日
分享:

1. 介紹

如果您希望將您的 HTML 網站轉換為其他格式,您來對地方了。本文將討論如何將您的 HTML、CSS 和 JS 轉換為 PDF。如今一切都是以技術為基礎的,而這些技術的工程師需要節省時間的解決方案 —— 在最常用的編程語言之一,.NET 的 C# 中。在 C# 中,處理 PDF 文件和操作它們的傳統方法既複雜又耗時。PDF 文件的最常見用途是:

  • PDF 渲染
  • HTML 到 PDF 生成

為了應對這些 PDF 轉換並解決因此產生的任何問題,開發了許多工具。本文將比較兩個開發者間最受讚譽的用於 PDF 轉換的 C# 庫。相關工具如下:

  • DocRaptor
  • IronPDF

2. IronPDF

IronPDF 是在 .NET 和 .NET Core 開發中進行 HTML 網站轉換的夢幻工具。它不僅可以轉換 HTML,還提供了許多其他功能。在 .NET Core 和框架專案中,IronPDF 允許開發人員生成、修改和提取 PDF 文件。開發人員可以使用 IronPDF 庫迅速從 HTML 文件創建或轉換 PDF。

IronPDF 允許您自動從 PDF 文件中讀取信息並將其注入到您的 .NET 應用程式和數據存儲系統中。舊 PDF 文件存儲的內容可被導入、遷移和索引到您的文件管理和業務流程應用程式中。

2.1. IronPDF 功能

2.1.1. PDF 轉換

此功能包括從不同格式(例如 HTML、HTML 字串、MVC 視圖、Web 表單和 URL)創建 PDF。

2.1.2. PDF 圖像化

這允許用戶從 PDF 創建圖像並 建立PDF 從圖像中提取。它包括圖像提取、支持不同的圖像擴展名以及 PDF 打印。

2.1.3. PDF 文件 IO

IronPDF 還提供 128 位加密功能,為 PDF 加密密碼並對 PDF 進行數字簽名。

2.1.4. 編輯 PDF

IronPDF 提供各種 PDF 格式化功能,如添加水印、添加頁面、刪除頁面、背景、前景等等。簡而言之,IronPDF 提供了所有你能想到的與 PDF 相關的操作。

2.1.5. PDF內容提取

在許多情況下,你可以直接從 PDF 中提取嵌入的文本。如果這不起作用,你的讀者可能實際上是嵌入在圖像中的。使用 IronOCR 庫來掃描文檔中的視覺文本,而不是純文本。

2.1.6. 頁眉和頁腳

在創建 PDF 或向現有的 PDF 中添加時,可以添加頁眉和頁腳。打印選項屬性允許為每個文檔頁面設計頁眉和頁腳。在 Chrome PDF 渲染器對像上訪問這些選項。此示例在 .NET Core 控制台應用程序中工作。

2.1.7. 兼容性

IronPDF 支持幾乎所有與 C# 兼容的操作系統和框架,如:

  • 支持:Windows, Azure

    • .NET Core 2.1, 3.0, 3.1, .NET 6 & 5

      • .NET Standard 2.0 通用兼容性

      • Azure

      • AWS

      • Docker

      • Linux

3. DocRaptor

DocRaptor 是一個專業的文件轉換解決方案,但與 IronPDF 不同,它對多個編程字典提供有限的功能。它是一個基於 API 的工具,可以與任何語言集成。它質量高且速度快,從而為您節省時間。它還提供將 XML 文件轉換為 XLSX 的功能。

DocRaptor 提供為您托管文件的服務。它具有 CSS 和 JS 支持。這些都是對於沒有自己伺服器的小型企業來說非常好的功能。

3.1. DocRaptor 功能

3.1.1. HTML 轉換為 PDF

DocRaptor 使 HTML、CSS 和 JS 轉換為 PDF 和 XLS 文件變得快捷且簡單。只需將您的 HTML 內容和所需的參數以表單編碼文本或 JSON 對象形式發送到 Docs API。

3.1.2 HTML 轉換為 Excel 格式

許多報告和數據導出都需要支持 PDF 和 Excel。DocRaptor 的基於 HTML 的工具使這變得輕而易舉。!

3.1.3. 文件托管

該文件將保存在無品牌網址上,任何人都可以從任何地方訪問。您可以將其無限期保留,也可以在特定日期或下載次數後將其刪除。

注意:

根據從 NuGet 網站,IronPDF 比 DocRaptor 更受歡迎,總下載量達300萬,每日下載量平均為1300次。另一方面,DocRaptor 的總下載量僅有114,900,日均下載量為51次。

4. 在 Visual Studio 中建立新專案

打開 Visual Studio 軟體並進入文件選單。選擇「新建專案」,然後選擇控制台應用程式。在本文中,我們將使用控制台應用程式來生成 PDF 檔案。

輸入專案名稱並在適當的文字框中選擇路徑。然後,點擊建立按鈕。選擇所需的 .NET 框架,如下圖所示:

Visual Studio 專案現在將為所選應用程式生成結構,如果您選擇了控制台、Windows 和 Web 應用程式,它將打開 program.cs 檔案,您可以在其中輸入程式碼並建構/運行應用程式。

現在我們可以添加庫並測試程序。

5. 安裝 IronPDF 函式庫

IronPDF 函式庫可以通過四種不同的方式下載和安裝。這些方式是:

  • 使用 Visual Studio NuGet 套件管理器
  • 使用 Visual Studio 命令行
  • 從 NuGet 網頁直接下載
  • 從 IronPDF 網頁直接下載

5.1 使用 Visual Studio NuGet 套件管理器

Visual Studio 軟體提供 NuGet 套件管理器選項,可以將套件直接安裝到解決方案中。以下螢幕截圖顯示了如何打開 NuGet 套件管理器。

它提供了搜尋框,顯示來自 NuGet 網站的可用套件庫清單。在套件管理器中,我們需要搜索關鍵字「IronPDF」,如下圖所示:

從上述圖片,我們將獲取相關套件的搜索列表。我們需要選擇IronPDF選項並將套件安裝到我們的方案中。

5.2 使用 Visual Studio 命令列

  • 在 Visual Studio 菜單中,前往 工具-> NuGet 套件管理員 -> 套件管理器主控台
  • 在套件管理器主控台標籤頁中輸入以下行:
Install-Package IronPdf

現在套件將下載/安裝到當前專案並準備好使用。

5.3 從 NuGet 網頁直接下載

第三種方法是直接從網頁下載 NuGet 套件。

  • 瀏覽到鏈接 "https://www.nuget.org/packages/IronPdf/- 從右側選單中選擇下載包選項。
  • 雙擊下載的包;它將自動安裝。
  • 現在重新加載解決方案並在項目中開始使用它。

5.4 直接從 IronPDF 網頁下載

點擊 連結 從網頁直接下載最新的套件。下載後,請按照以下步驟將套件添加到專案中。

  • 在解決方案視窗中右鍵點擊專案。
  • 然後,選擇引用選項,並瀏覽到下載的引用位置。
  • 接下來,點擊確定以添加引用。

6. 安裝 DocRaptor API

DocRaptor 團隊提供了幾乎所有相同的方法來集成 API。這些方法有:

  • 使用 Visual Studio 的 NuGet 套件管理器。
  • 使用 Visual Studio 的 NuGet 套件主控台。
  • 使用 Visual Studio 的命令行。
  • 從 NuGet 網站直接下載。

6.1 使用 Visual Studio 的 NuGet 套件管理器

如之前針對 IronPDF 所解釋的那樣,打開 NuGet 套件管理器的步驟是一樣的。

打開套件管理器後,只需在搜尋欄中輸入 DocRaptor。

如上圖所示,DocRaptor有三個結果。請選擇所需的選項。

6.2. 使用 Visual Studio NuGet 套件管理控制台

在 Visual Studio 的選單中,前往工具 -> NuGet 套件管理員 -> 套件管理控制台。在套件管理控制台標籤中輸入以下命令:install-Package DocRaptor。現在,套件將會下載/安裝到當前項目,並準備就緒。

6.3. 直接從 NuGet 網站下載

第三種方式是直接從網頁下載 NuGet 套件。

  • 瀏覽至鏈接 "https://www.nuget.org/packages/DocRaptor/".
  • 從右邊選單中選取下載包選項。
  • 雙擊下載的包,將自動安裝。
  • 接下來,重新加載解決方案並在項目中開始使用它。

7. 從 HTML 生成 PDF

兩個工具都包含這個 HTML 轉換功能,儘管它們的實現方式略有不同。

7.1. 使用 IronPDF 從 HTML 生成 PDF

使用 IronPDF 轉換頁面不需要使用 JSON 和加密技術,其實非常簡單。IronPDF 提供了多種不同的方法。例如:

  • HTML 文件轉換為 PDF
var Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("pixel-perfect.pdf");
var Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("pixel-perfect.pdf");
Dim Renderer = New IronPdf.ChromePdfRenderer()
Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("pixel-perfect.pdf")
VB   C#
  • URL轉PDF
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");

Pdf.SaveAs("url.pdf"); 
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");

Pdf.SaveAs("url.pdf"); 
Dim Renderer As New IronPdf.ChromePdfRenderer()
Dim Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/")

Pdf.SaveAs("url.pdf")
VB   C#
  • ASPX 頁面轉換為 PDF,還有更多功能。
private void Form1_Load(object sender, EventArgs e)
{

IronPdf.AspxToPdf.RenderThisPageAsPdf();
//Changes the ASPX output into a pdf instead of HTML

}
private void Form1_Load(object sender, EventArgs e)
{

IronPdf.AspxToPdf.RenderThisPageAsPdf();
//Changes the ASPX output into a pdf instead of HTML

}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

IronPdf.AspxToPdf.RenderThisPageAsPdf()
'Changes the ASPX output into a pdf instead of HTML

End Sub
VB   C#

7.2. 使用 DocRaptor 生成 PDF

DocRaptor 使用支持 JSON 的 HTTP POST 請求進行轉換,但僅提供將 URL 和 HTML 文件轉換為 PDF 的功能。

using DocRaptor.Client;
using DocRaptor.Model;
using DocRaptor.Api;
using System.IO;
 class Example {
   tatic void Main(string [] args) {
    DocApi docraptor = new DocApi();
    docraptor.Configuration.Username = "YOUR_API_KEY_HERE";
     Doc doc = new Doc(
      test: true,
      //documentContent: System.IO.File.ReadAllText(@"custom-fonts-    content.html"),
        documentUrl: "http://www.docraptor.com/examples/invoice.html",
        name: "docraptor-csharp.pdf",
        documentType: Doc.DocumentTypeEnum.Pdf
      );
          yte [] createResponse = docraptor.CreateDoc(doc);
    }
using DocRaptor.Client;
using DocRaptor.Model;
using DocRaptor.Api;
using System.IO;
 class Example {
   tatic void Main(string [] args) {
    DocApi docraptor = new DocApi();
    docraptor.Configuration.Username = "YOUR_API_KEY_HERE";
     Doc doc = new Doc(
      test: true,
      //documentContent: System.IO.File.ReadAllText(@"custom-fonts-    content.html"),
        documentUrl: "http://www.docraptor.com/examples/invoice.html",
        name: "docraptor-csharp.pdf",
        documentType: Doc.DocumentTypeEnum.Pdf
      );
          yte [] createResponse = docraptor.CreateDoc(doc);
    }
Imports DocRaptor.Client
Imports DocRaptor.Model
Imports DocRaptor.Api
Imports System.IO
 Friend Class Example
   Private tatic Sub Main(ByVal args() As String)
	Dim docraptor As New DocApi()
	docraptor.Configuration.Username = "YOUR_API_KEY_HERE"
	 Dim doc As New Doc(test:= True, documentUrl:= "http://www.docraptor.com/examples/invoice.html", name:= "docraptor-csharp.pdf", documentType:= Doc.DocumentTypeEnum.Pdf)
		  Dim createResponse() As yte = docraptor.CreateDoc(doc)
   End Sub
VB   C#

8. 格式化PDF

IronPDF和DocRaptor都支援PDF的格式化。然而,IronPDF提供單一文件支援,而DocRaptor使用多文件支援。

8.1. 使用 IronPDF 進行格式化

為了確保輸出 PDF 的預期行為,我們在文章中使用了不同的格式樣式。我們將討論其中的一些並與 DocRaptor 進行比較。

  • 自定義字體

IronPDF 支持 Web 字體,包括出色的 Google 字體庫。這使得開發人員能夠完全控制字體,而無需依賴系統字體。

using IronPdf;

ChromePdfRenderer myChromePdfRenderer = new IronPdf.ChromePdfRenderer();
var Renderer = new IronPdf.ChromePdfRenderer();

var html = @"<link href=""https://fonts.googleapis.com/css?family=Lobster""
rel=""stylesheet""><p style=""font-family: 'Lobster', serif; font-size:30px;"" > Hello Google Fonts</p>";

Renderer.RenderingOptions.RenderDelay = 500;
var doc = Renderer.RenderHtmlAsPdf(html);
doc.SaveAs("font.pdf");
using IronPdf;

ChromePdfRenderer myChromePdfRenderer = new IronPdf.ChromePdfRenderer();
var Renderer = new IronPdf.ChromePdfRenderer();

var html = @"<link href=""https://fonts.googleapis.com/css?family=Lobster""
rel=""stylesheet""><p style=""font-family: 'Lobster', serif; font-size:30px;"" > Hello Google Fonts</p>";

Renderer.RenderingOptions.RenderDelay = 500;
var doc = Renderer.RenderHtmlAsPdf(html);
doc.SaveAs("font.pdf");
Imports IronPdf

Private myChromePdfRenderer As ChromePdfRenderer = New IronPdf.ChromePdfRenderer()
Private Renderer = New IronPdf.ChromePdfRenderer()

Private html = "<link href=""https://fonts.googleapis.com/css?family=Lobster""
rel=""stylesheet""><p style=""font-family: 'Lobster', serif; font-size:30px;"" > Hello Google Fonts</p>"

Renderer.RenderingOptions.RenderDelay = 500
Dim doc = Renderer.RenderHtmlAsPdf(html)
doc.SaveAs("font.pdf")
VB   C#
  • 水印

IronPDF 提供使用 HTML 為 PDF 文件添加水印的方法。水印可以設置為在現有內容之上或之下渲染,並且內建有透明度、旋轉和超連結的功能。

using IronPdf;

// Stamps a watermark onto a new or existing PDF
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();

var Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
Pdf.WatermarkAllPages("<h2 style='color:red'>SAMPLE</h2>",   ronPdf.Editing.WaterMarkLocation.MiddleCenter, 50, -45, "https://www.nuget.org/packages/IronPdf");
Pdf.SaveAs(@"C:\Path\To\Watermarked.pdf
using IronPdf;

// Stamps a watermark onto a new or existing PDF
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();

var Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
Pdf.WatermarkAllPages("<h2 style='color:red'>SAMPLE</h2>",   ronPdf.Editing.WaterMarkLocation.MiddleCenter, 50, -45, "https://www.nuget.org/packages/IronPdf");
Pdf.SaveAs(@"C:\Path\To\Watermarked.pdf
Imports IronPdf

' Stamps a watermark onto a new or existing PDF
Private Renderer As New IronPdf.ChromePdfRenderer()

Private Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
Pdf.WatermarkAllPages("<h2 style='color:red'>SAMPLE</h2>", ronPdf.Editing.WaterMarkLocation.MiddleCenter, 50, -45, "https://www.nuget.org/packages/IronPdf")
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'Pdf.SaveAs("TangibleTempVerbatimOpenTagC:\Path\To\Watermarked.pdf
VB   C#
  • 頁碼

IronPDF 的“頁首和頁尾”功能允許我們合併有關頁碼的信息。

// PM> Install-Package IronPdf

using IronPdf;

var html = @"
<p> Hello Iron</p>
<p> This is 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> This is 2nd Page</p>
<div style = 'page-break-after: always;' ></div>
<p> This is 3rd Page</p>";

var Renderer = new IronPdf.ChromePdfRenderer();

Renderer.RenderingOptions.HtmlFooter = new IronPdf.HtmlHeaderFooter()
{

    MaxHeight = 15, //millimeters
    HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
    DrawDividerLine = true
};

var pdfdoc = Renderer.RenderHtmlAsPdf(html);
pdfdoc.SaveAs("pageNumber.pdf");
// PM> Install-Package IronPdf

using IronPdf;

var html = @"
<p> Hello Iron</p>
<p> This is 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> This is 2nd Page</p>
<div style = 'page-break-after: always;' ></div>
<p> This is 3rd Page</p>";

var Renderer = new IronPdf.ChromePdfRenderer();

Renderer.RenderingOptions.HtmlFooter = new IronPdf.HtmlHeaderFooter()
{

    MaxHeight = 15, //millimeters
    HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
    DrawDividerLine = true
};

var pdfdoc = Renderer.RenderHtmlAsPdf(html);
pdfdoc.SaveAs("pageNumber.pdf");
' PM> Install-Package IronPdf

Imports IronPdf

Private html = "
<p> Hello Iron</p>
<p> This is 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> This is 2nd Page</p>
<div style = 'page-break-after: always;' ></div>
<p> This is 3rd Page</p>"

Private Renderer = New IronPdf.ChromePdfRenderer()

Renderer.RenderingOptions.HtmlFooter = New IronPdf.HtmlHeaderFooter() With {
	.MaxHeight = 15,
	.HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
	.DrawDividerLine = True
}

Dim pdfdoc = Renderer.RenderHtmlAsPdf(html)
pdfdoc.SaveAs("pageNumber.pdf")
VB   C#

8.2. 使用 DocRaptor 格式化

DocRaptor 支援 .NET API 中的 PDF 格式化——但相當難以處理。我們來看看之前的三個格式化範例:

  • 自定義字體

在 DocRaptor 中使用自定義字體很容易。它的工作方式與標準網頁相同。以下是一個使用 Google 字體的 CSS 範例:

CSS 編碼:

@font-face {
  font-family: 'Open Sans';
  font-style: normal;
  font-weight: 300;
  src: local('Open Sans Light'), local('OpenSans-Light'), url(http://themes.googleusercontent.com/static/fonts/opensans/v8/DXI1ORHCpsQm3Vp6mXoaTaRDOzjiPcYnFooOUGCOsRk.woff) format('woff');
}
p {
  font-family: Arial, Helvetica, sans-serif;
}
p.custom-font {
  font-family: 'Open Sans', sans-serif;
}
@font-face {
  font-family: 'Open Sans';
  font-style: normal;
  font-weight: 300;
  src: local('Open Sans Light'), local('OpenSans-Light'), url(http://themes.googleusercontent.com/static/fonts/opensans/v8/DXI1ORHCpsQm3Vp6mXoaTaRDOzjiPcYnFooOUGCOsRk.woff) format('woff');
}
p {
  font-family: Arial, Helvetica, sans-serif;
}
p.custom-font {
  font-family: 'Open Sans', sans-serif;
}
HTML

HTML編碼:

<h2>Custom Fonts</h2>
<p>Hi, my name is Arial.</p>
<p class='custom-font'>I like to walk on the beach on warm Open Sans.</p>
<h2>Custom Fonts</h2>
<p>Hi, my name is Arial.</p>
<p class='custom-font'>I like to walk on the beach on warm Open Sans.</p>
HTML

C# 編碼:

class Example
{
    static void Main(string [] args)
    {
        DocApi docraptor = new DocApi();
        docraptor.Configuration.Username = "YOUR_API_KEY_HERE";
         try
        {
            Doc doc = new Doc(
                name: "custom-fonts",
                test: true, // test documents are free but watermarked
                documentContent: System.IO.File.ReadAllText(@"custom-fonts-content.html"), 
                 / documentUrl: "http://docraptor.com/examples/invoice.html", // or use a url
                documentType: Doc.DocumentTypeEnum.Pdf
                // javascript: false, // enables   rocessing
            );
             byte [] create_response = docraptor.CreateDoc(doc);
            File.WriteAllBytes("custom-fonts.pdf", create_response);
        } catch (DocRaptor.Client.ApiException error) {
            Console.Write(error.ErrorContent);
        }
    }
}
class Example
{
    static void Main(string [] args)
    {
        DocApi docraptor = new DocApi();
        docraptor.Configuration.Username = "YOUR_API_KEY_HERE";
         try
        {
            Doc doc = new Doc(
                name: "custom-fonts",
                test: true, // test documents are free but watermarked
                documentContent: System.IO.File.ReadAllText(@"custom-fonts-content.html"), 
                 / documentUrl: "http://docraptor.com/examples/invoice.html", // or use a url
                documentType: Doc.DocumentTypeEnum.Pdf
                // javascript: false, // enables   rocessing
            );
             byte [] create_response = docraptor.CreateDoc(doc);
            File.WriteAllBytes("custom-fonts.pdf", create_response);
        } catch (DocRaptor.Client.ApiException error) {
            Console.Write(error.ErrorContent);
        }
    }
}
Friend Class Example
	Shared Sub Main(ByVal args() As String)
		Dim docraptor As New DocApi()
		docraptor.Configuration.Username = "YOUR_API_KEY_HERE"
		 Try
			Dim doc As New Doc(name:= "custom-fonts", test:= True, documentContent:= System.IO.File.ReadAllText("custom-fonts-content.html"), / documentUrl:= "http://docraptor.com/examples/invoice.html", documentType:= Doc.DocumentTypeEnum.Pdf)
			 Dim create_response() As Byte = docraptor.CreateDoc(doc)
			File.WriteAllBytes("custom-fonts.pdf", create_response)
		Catch [error] As DocRaptor.Client.ApiException
			Console.Write([error].ErrorContent)
		End Try
	End Sub
End Class
VB   C#

輸出

  • 水印

許多PDF中可能會有水印。幸運的是,DocRaptor的HTML-PDF工具使動態生成水印文檔的創建變得輕而易舉。!

CSS編碼:

#watermark {
  flow: static(watermarkflow);
  font-size: 120px;
  opacity: 0.5;
  transform: rotate(-30deg);
  text-align: center;
}
#watermark {
  flow: static(watermarkflow);
  font-size: 120px;
  opacity: 0.5;
  transform: rotate(-30deg);
  text-align: center;
}
HTML

HTML編碼:

<body><div id="watermark">PREVIEW</div>
<div style="page-break-after: always;">Page 1</div>
<div style="page-break-after: always;">Page 2</div>
<div style="page-break-after: always;">Page 3</div>
</body>
<body><div id="watermark">PREVIEW</div>
<div style="page-break-after: always;">Page 1</div>
<div style="page-break-after: always;">Page 2</div>
<div style="page-break-after: always;">Page 3</div>
</body>
HTML

C# 編碼:

class Example
{
    static void Main(string [] args)
    {
        DocApi docraptor = new DocApi();
        docraptor.Configuration.Username = "YOUR_API_KEY_HERE";

        try
        {
            Doc doc = new Doc(
                name: "text-based-watermark",
                test: false, // test documents are free but watermarked
                documentContent: System.IO.File.ReadAllText(@"text-based-watermark-content.html"), 
                // documentUrl: "http://docraptor.com/examples/invoice.html", // or use a url
                documentType: Doc.DocumentTypeEnum.Pdf
                // javascript: false, // enables processing
            );

            byte [] create_response = docraptor.CreateDoc(doc);
            File.WriteAllBytes("text-based-watermark.pdf", create_response);
        } catch (DocRaptor.Client.ApiException error) {
            Console.Write(error.ErrorContent);
        }
    }
class Example
{
    static void Main(string [] args)
    {
        DocApi docraptor = new DocApi();
        docraptor.Configuration.Username = "YOUR_API_KEY_HERE";

        try
        {
            Doc doc = new Doc(
                name: "text-based-watermark",
                test: false, // test documents are free but watermarked
                documentContent: System.IO.File.ReadAllText(@"text-based-watermark-content.html"), 
                // documentUrl: "http://docraptor.com/examples/invoice.html", // or use a url
                documentType: Doc.DocumentTypeEnum.Pdf
                // javascript: false, // enables processing
            );

            byte [] create_response = docraptor.CreateDoc(doc);
            File.WriteAllBytes("text-based-watermark.pdf", create_response);
        } catch (DocRaptor.Client.ApiException error) {
            Console.Write(error.ErrorContent);
        }
    }
Friend Class Example
	Shared Sub Main(ByVal args() As String)
		Dim docraptor As New DocApi()
		docraptor.Configuration.Username = "YOUR_API_KEY_HERE"

		Try
			Dim doc As New Doc(name:= "text-based-watermark", test:= False, documentContent:= System.IO.File.ReadAllText("text-based-watermark-content.html"), documentType:= Doc.DocumentTypeEnum.Pdf)

			Dim create_response() As Byte = docraptor.CreateDoc(doc)
			File.WriteAllBytes("text-based-watermark.pdf", create_response)
		Catch [error] As DocRaptor.Client.ApiException
			Console.Write([error].ErrorContent)
		End Try
	End Sub
VB   C#
  • 頁碼

使用開源 HTML 到 PDF 工具,向 PDF 文件中添加頁碼是困難且有時幾乎不可能的,但 DocRaptor 使這個過程變得輕而易舉。!

CSS編碼:

@page {
  @bottom {
    content: "Page " counter(page, upper-alpha) " of " counter(pages, decimal);
  } } 
@page {
  @bottom {
    content: "Page " counter(page, upper-alpha) " of " counter(pages, decimal);
  } } 
HTML

HTML編碼:

<body>
<div style="page-break-after: always;">Page1</div>
<div style="page-break-after: always;">Page2</div>
<div style="page-break-after: always;">Page3</div>
<div id="page4" style="page-break-after: always;">Page4, with reset page counter</div>
</body>
<body>
<div style="page-break-after: always;">Page1</div>
<div style="page-break-after: always;">Page2</div>
<div style="page-break-after: always;">Page3</div>
<div id="page4" style="page-break-after: always;">Page4, with reset page counter</div>
</body>
HTML

C# 編碼:

class Example
{
    static void Main(string [] args)
    {
        DocApi docraptor = new DocApi();
        docraptor.Configuration.Username = "YOUR_API_KEY_HERE";

        try
        {
            Doc doc = new Doc(
                name: "page-numbers",
                test: true, // test documents are  but watermarked
                documentContent: System.IO.File.ReadAllText(@"page-numbers-content.html"), 
                // documentUrl: "http://docraptor.com/examples/invoice.html", // or use a url
                documentType: Doc.DocumentTypeEnum.Pdf
                // javascript: false, // enables processing
            );

            byte [] create_response = docraptor.CreateDoc(doc);
            File.WriteAllBytes("page-numbers.pdf", create_response);
        } catch (DocRaptor.Client.ApiException error) {
            Console.Write(error.ErrorContent);
        }
    }
}
class Example
{
    static void Main(string [] args)
    {
        DocApi docraptor = new DocApi();
        docraptor.Configuration.Username = "YOUR_API_KEY_HERE";

        try
        {
            Doc doc = new Doc(
                name: "page-numbers",
                test: true, // test documents are  but watermarked
                documentContent: System.IO.File.ReadAllText(@"page-numbers-content.html"), 
                // documentUrl: "http://docraptor.com/examples/invoice.html", // or use a url
                documentType: Doc.DocumentTypeEnum.Pdf
                // javascript: false, // enables processing
            );

            byte [] create_response = docraptor.CreateDoc(doc);
            File.WriteAllBytes("page-numbers.pdf", create_response);
        } catch (DocRaptor.Client.ApiException error) {
            Console.Write(error.ErrorContent);
        }
    }
}
Friend Class Example
	Shared Sub Main(ByVal args() As String)
		Dim docraptor As New DocApi()
		docraptor.Configuration.Username = "YOUR_API_KEY_HERE"

		Try
			Dim doc As New Doc(name:= "page-numbers", test:= True, documentContent:= System.IO.File.ReadAllText("page-numbers-content.html"), documentType:= Doc.DocumentTypeEnum.Pdf)

			Dim create_response() As Byte = docraptor.CreateDoc(doc)
			File.WriteAllBytes("page-numbers.pdf", create_response)
		Catch [error] As DocRaptor.Client.ApiException
			Console.Write([error].ErrorContent)
		End Try
	End Sub
End Class
VB   C#

9. 許可證

DocRaptor 是基於 API 的文件轉換器,可以將 HTML 文件和網址轉換為 PDF,還有將 XML 轉換為 XLSX 文件。它支持八種不同的編程語言。然而,它只提供每月的許可證,並且有文件數量限制,起步是每月五個文件的免費許可證,最高到銀色方案包括 40000 個文件的限制,每月價格為 $1000。DocRaptor 對小型組織非常適用,並提供一個專業小方案,每月限制 325 個文件,價格為 $29。查看此内容 連結 更多價格。

注意:

DocRaptor 不提供一次性購買或基於項目的授權。

IronPDF 是一個提供免費開發者授權的庫。IronPDF 還有一個不同的定價結構:lite 授權包價格從 $749 起,沒有隱藏費用。SaaS 和 OEM 產品的再分發也是可能的。所有授權均提供 30 天退款保證、一年的軟體支援和升級、開發/測試/生產的有效性以及永久授權 (一次性購買)欲查看 IronPDF 的完整價格結構和許可證,請前往 這裡.

注意:

IronPDF 提供連接和合併兩個或更多 PDF 的選項。 它還提供提取頁面、复制頁面、删除特定頁面和多线程 PDF 生成的選項,这是競爭對手所不具備的功能。

10. 總結

從遠端伺服器,IronPDF 不會生成 HTML 到 PDF。在幕後,它啟動了一個符合標準的真正瀏覽器實例。 (無需安裝任何額外的軟體)HTML 以完全精確的方式渲染,並以適合商業印刷最高標準的向量格式呈現。結果是一個清晰、高品質的 PDF。授權和價格資訊在網頁上隨時可用。

DocRaptor 也將任何格式的 HTML 轉換為 PDF,具有最高的準確性和最少的停機時間,這是由於它運行在眾多雲伺服器上。DocRaptor 是一款基於 web 的 API,提供線上 PDF 轉換服務。DocRaptor 的 HTML 到 PDF API 由於有伺服器端 API 客戶端庫的支持,使用起來非常簡便。這些客戶端庫可以在許多知名的伺服器端程式設計語言中找到。網頁有價格資訊。

11. 結論

在上述文章中,我們比較了這兩個工具並得出結論,對於 .NET 或 C# 文件轉換,開發者更偏好 IronPDF 而不是 DocRaptor,原因有很多。IronPDF 提供的功能比 DocRaptor 更多。DocRaptor 為小型組織提供不錯的套件,但價格相當昂貴,並且在長期內不提供持續授權。另一方面,IronPDF 提供更多功能,且以較低的價格提供一次性購買授權。IronPDF 對於小型組織和大型基礎設施組織來說都是較佳選擇。DocRaptor 在不同伺服器端平台處理 PDF 文件時可能會有幫助。此外,IronPDF 套件提供終身授權,沒有持續費用,而 DocRaptor 則有持續費用。

< 上一頁
IronPDF與PDFCrowd之間的比較
下一個 >
IronPDF 和 DynamicPDF - 全面比較

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

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