在生產環境中測試,無水印。
在任何需要的地方都能運行。
獲得 30 天的全功能產品。
在幾分鐘內上手運行。
試用產品期間完全訪問我們的支援工程團隊
ActivePDF Toolkit
是一個軟體元件,用於處理 PDF 檔案(包括從不同來源產生 PDF 檔案)並設置其屬性(例如頁首、頁尾、邊距或浮水印)。
IronPDF
是一個具競爭力定價的C# PDF 函式庫,還提供這些功能。
在這裡,我們將介紹如何在 .NET Visual Studio 專案中使用這兩個軟體元件的功能、程式碼範例和逐步操作,讓您能夠自行決定哪個最適合您的應用程式。
Iron Software 是一家市場領先的元件提供商,提供 IronPDF 以用於處理 PDF 文件。 一種全面的方法,可以輕鬆從不同格式生成 PDF 文件並以程式設計方式設置所有屬性。 由於只需幾行程式碼即可生成一致、可靠和準確的 PDF 文件,因此受到開發人員的青睞。
IronPDF 專為 C#、.NET、VB、ASPX、ASP.NET、MVC 和 .NET Core 設計。 它支援 Visual Studio、NuGet、Linux、Azure、Docker 等。
ActivePDF 是一家提供多種組件來處理 PDF 文件的軟體公司。 與單一組件IronPDF不同,ActivePDF提供不同的PDF文件解決方案。 例如,要減小 PDF 文件的大小,您可以使用ActivePDF Compressor
。 要從 HTML 資源創建 PDF,請使用ActivePDF WebGrabber
。
在本文中,我們將使用ActivePDF WebGrabber來與IronPDF進行比較,一起來看看吧:
ActivePDF WebGrabber 是 ActivePDF 的一個獨立組件,專門用於從 HTML 資源(如 URL、HTML 文件或 HTML 字串)生成 PDF 文件。 它還提供設置頁面屬性功能,例如頁首、頁尾、邊距、水印或書籤,以根據我們的需求創建 PDF 文件。
讓我們來看看兩個組件的對比。
IronPDF | ActivePDF |
---|---|
IronPDF converts HTML sources to PDF files. | ActivePDF converts HTML sources to PDF files. |
IronPDF supports .NET Core. | ActivePDF does not support .NET Core. |
IronPDF supports .NET 4.0 or higher. | ActivePDF supports .NET 4.6.2 or higher. |
IronPDF supports macOS. | ActivePDF does not support macOS. |
IronPDF can apply CSS to set WaterMark properties. | ActivePDF does not support CSS to set WaterMark properties. |
IronPDF can set Paper Orientation of PDF files. | ActivePDF can set Paper Orientation of PDF files. |
IronPDF provides the RenderDelay function to delay the PDF conversion. | ActivePDF provides the TimeoutSpan function to delay the PDF conversion. |
IronPDF provides predefined functions to set Header or Footer. | ActivePDF requires setting Header and Footer by raw HTML and CSS. |
IronPDF provides a predefined function to draw a horizontal line to separate content. | ActivePDF does not provide a line to separate headers and footers. |
To save the PDF file, we can set the directory and file name in one line. | We have to set file directory and file name separately. |
Need to write fewer lines of code with a simple programming structure. | Need to write many lines of code. |
License starts from $749 . | License starts from $1180 . |
您可以透過兩種方式將 IronPDF 程式庫加入專案,採用哪一種方式都沒有差別。
瀏覽 IronPDF
,然後安裝它。
或者:
tools
封裝管理器主控台
Install-Package IronPdf
我們也可以下載 IronPDF.dll,然後在項目中添加其引用。
如果您可以通過撰寫using IronPdf;
命名空間來訪問IronPDF
,這意味著IronPDF已成功導入到您的專案中,並準備好使用。
下載 WebGrabber-install.exe,然後選擇下載文件。下載完成後,雙擊下載的文件。然後從 ActivePDF 請求激活密鑰以使用以下15天評估密鑰:001-AEALX-LC6Z5-7YD95-S3D8J-3LR25。
安裝成功後,前往以下目錄:
C:\Program Files\ActivePDF\WebGrabber\bin\
在此目錄中,您會獲得APWebGrabber.Net45.dll
文件。在您的 Visual Studio 專案中添加它的引用。
現在,如果您可以通過撰寫using APWebGrabber;
命名空間來訪問WebGrabber
,這表示ActivePDF WebGrabber已成功導入到您的專案中,您可以使用它。
ActivePDF文檔提供了有關ActivePDF WebGrabber安裝的更多資訊。
我們已經介紹了這兩個組件及其安裝過程,現在我們將開始通過執行不同任務來比較它們。 這將讓我們了解兩者的程式結構,並決定哪一個最適合我們的專案。 為了更好地理解,我們將在每個任務中執行一個具體的用例並提供用來實現的程式碼。
在第一個比較中,我們將使用一個情境,該情境需要通過 HTML 字串創建一個 PDF 文件並將其保存到目標位置。 首先,我們開始使用IronPDF來實現這個使用案例:
/**
HTML String to PDF
anchor-html-string-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to IronPDF</h2> ";
//convert HTML string to PDF file
using var PDF = converter.RenderHtmlAsPdf(html);
//Save the file
PDF.SaveAs("E:/sample.pdf");
}
/**
HTML String to PDF
anchor-html-string-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to IronPDF</h2> ";
//convert HTML string to PDF file
using var PDF = converter.RenderHtmlAsPdf(html);
//Save the file
PDF.SaveAs("E:/sample.pdf");
}
'''
'''HTML String to PDF
'''anchor-html-string-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New ChromePdfRenderer()
'HTML Source
Dim html As String = "<h1>Hello World!</h1> <h2>Welcome to IronPDF</h2> "
'convert HTML string to PDF file
Dim PDF = converter.RenderHtmlAsPdf(html)
'Save the file
PDF.SaveAs("E:/sample.pdf")
End Sub
輸出:
上述程式碼將在Local Disk E:
中建立一個名為sample.pdf
的 PDF 檔案,其截圖如下:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to ActivePDF WebGrabber</h2>";
//assign source html to WebGrabber
wg.CreateFromHTMLText = html;
//specify file directory
wg.OutputDirectory = "E:/";
// file name
wg.NewDocumentName = "sample.pdf";
//convert source HTML to PDF file
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to ActivePDF WebGrabber</h2>";
//assign source html to WebGrabber
wg.CreateFromHTMLText = html;
//specify file directory
wg.OutputDirectory = "E:/";
// file name
wg.NewDocumentName = "sample.pdf";
//convert source HTML to PDF file
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'HTML Source
Dim html As String = "<h1>Hello World!</h1> <h2>Welcome to ActivePDF WebGrabber</h2>"
'assign source html to WebGrabber
wg.CreateFromHTMLText = html
'specify file directory
wg.OutputDirectory = "E:/"
' file name
wg.NewDocumentName = "sample.pdf"
'convert source HTML to PDF file
wg.ConvertToPDF()
End Sub
以下螢幕截圖是此代碼新生成的sample.pdf
文件:
在此比較中,我們使用的案例是需要從名為myHtmlFile.html
的HTML文件生成PDF文件,該文件位於E:/
目錄中,並且具有以下HTML和CSS代碼:
<html>
<style>
li{
font-size:x-large;
color: magenta;
font-style: italic;
}
</style>
<body>
<h1>I am Heading</h1>
<h2>Items List:</h2>
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</body>
</html>
<html>
<style>
li{
font-size:x-large;
color: magenta;
font-style: italic;
}
</style>
<body>
<h1>I am Heading</h1>
<h2>Items List:</h2>
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</body>
</html>
現在,我們將使用這兩個組件將 myHtmlFile.html
文件轉換為 PDF 文件。 讓我們從IronPDF開始。
/**
HTML File to PDF
anchor-html-file-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new IronPdf.ChromePdfRenderer();
//render html file to pdf
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
/**
HTML File to PDF
anchor-html-file-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new IronPdf.ChromePdfRenderer();
//render html file to pdf
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''HTML File to PDF
'''anchor-html-file-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New IronPdf.ChromePdfRenderer()
'render html file to pdf
Dim PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html")
'save to target location
PDF.SaveAs("E:/Sample.pdf")
End Sub
以下螢幕截圖是使用上述代碼生成的新Sample.pdf
文件:
我們可以看到 HTML 頁面 myHtmlFile.html
成功轉換為 PDF 文件 Sample.pdf
,並且 CSS 樣式也已應用。
閱讀 IronPDF 文件 以了解更多關於如何在我們的 .NET 專案中使用 IronPDF。
讓我們使用 ActivePDF WebGrabber 執行相同的任務。
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify file path to be converted
wg.URL = "E:/myHtmlFile.html";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//newly generated file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify file path to be converted
wg.URL = "E:/myHtmlFile.html";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//newly generated file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'specify file path to be converted
wg.URL = "E:/myHtmlFile.html"
'specify the directory for newly generated file
wg.OutputDirectory = "E:/"
'newly generated file name
wg.NewDocumentName = "Sample.pdf"
'convert HTML file to PDF
wg.ConvertToPDF()
End Sub
以下截圖是使用上述代碼新生成的Sample.pdf
文件:
假設我們有一個網址 https://yandex.com/ 且我們想要生成該網頁的PDF文件。 為此,兩個組件都提供了一個功能。 首先,我們將看看如何通過IronPDF來完成這項工作。
/**
URL to PDF
anchor-url-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//Specify URL
using var PDF = converter.RenderUrlAsPdf("https://yandex.com/");
//Save the file
PDF.SaveAs("E:/Sample.pdf");
}
/**
URL to PDF
anchor-url-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//Specify URL
using var PDF = converter.RenderUrlAsPdf("https://yandex.com/");
//Save the file
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''URL to PDF
'''anchor-url-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New ChromePdfRenderer()
'Specify URL
Dim PDF = converter.RenderUrlAsPdf("https://yandex.com/")
'Save the file
PDF.SaveAs("E:/Sample.pdf")
End Sub
以下截圖是由上述程式碼新生成的Sample.pdf
文件
您可以造訪URL 範例的網頁,來比較和查看 IronPDF 文件的匹配準確度。
現在,我們將使用 ActivePDF WebGrabber 執行相同的任務。
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify URL
wg.URL = "https://yandex.com/";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert specified URL webpage to PDF
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify URL
wg.URL = "https://yandex.com/";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert specified URL webpage to PDF
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'specify URL
wg.URL = "https://yandex.com/"
'specify the directory for newly generated file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert specified URL webpage to PDF
wg.ConvertToPDF()
End Sub
以下截圖顯示了由上述代碼新生成的Sample.pdf
文件:
在此比較中,我們將使用 HTML 字串創建 PDF 文件,然後在頁面中央添加水印。 讓我們從IronPDF開始。
IronPDF 提供以下功能以添加水印:
WatermarkPage(WaterMark HTML 字串, PageIndexToWaterMark, WaterMarkLocation, Opacity, Rotation, Hyperlink)
我們可以使用WaterMarkLocation
來在以下位置設置水印:
左上角
頂部中心
右上角
中左
中間偏中
中右
BottomLeft
底部中心
右下角
讓我們看看如何使用上述功能來設置水印:
/**
Watermark PDF
anchor-watermark-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//source html string
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//add above string as PDF file content
using var PDF = converter.RenderHtmlAsPdf(html);
//HTML string for WaterMark
string WMStr = "<h1 style='color:red'>WaterMark</h1>";
//add WaterMark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter, 100, -45, "");
//save the document
PDF.SaveAs("E:/Sample.pdf");
}
/**
Watermark PDF
anchor-watermark-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//source html string
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//add above string as PDF file content
using var PDF = converter.RenderHtmlAsPdf(html);
//HTML string for WaterMark
string WMStr = "<h1 style='color:red'>WaterMark</h1>";
//add WaterMark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter, 100, -45, "");
//save the document
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''Watermark PDF
'''anchor-watermark-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New ChromePdfRenderer()
'source html string
Dim html As String = "<h1 style='text-align:center'>WaterMark Example</h1>"
'add above string as PDF file content
Dim PDF = converter.RenderHtmlAsPdf(html)
'HTML string for WaterMark
Dim WMStr As String = "<h1 style='color:red'>WaterMark</h1>"
'add WaterMark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter, 100, -45, "")
'save the document
PDF.SaveAs("E:/Sample.pdf")
End Sub
以下截圖顯示了由上述代碼新生成的Sample.pdf
文件:
我們可以添加任何類型的浮水印,並通過 CSS 設置其屬性。 現在,我們將使用 ActivePDF WebGrabber 執行相同的任務。
ActivePDF WebGrabber 不像 IronPDF 提供專門的浮水印功能。 但我們可以使用AddStampText()
函數作為解決此問題的替代方法:
AddStampText(float x, float y, string stampText);
stampText 是 TextStamp 的實際文本。
注意:ActivePDF WebGrabber 不支援 TextStamp 的 CSS 樣式。我們必須透過其他提供的函數設置,如下所示:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML source for Page content
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//assign page content source
wg.CreateFromHTMLText = html;
//add text stamp as WaterMark
wg.AddStampText(270.0f, 350.0f, "WaterMark");
//specify WaterMark's font size
wg.StampFontSize = 20;
//specify WaterMark's font family
wg.StampFont = "Times New Roman";
//specify WaterMark's opacity
wg.StampFontTransparency = 1f;
//specify WaterMark's rotation
wg.StampRotation = 45.0f;
//specify WaterMark's color
wg.StampColorNET = new ADK.PDF.Color() { Red = 255, Green = 0, Blue = 0, Gray = 0 };
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML source for Page content
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//assign page content source
wg.CreateFromHTMLText = html;
//add text stamp as WaterMark
wg.AddStampText(270.0f, 350.0f, "WaterMark");
//specify WaterMark's font size
wg.StampFontSize = 20;
//specify WaterMark's font family
wg.StampFont = "Times New Roman";
//specify WaterMark's opacity
wg.StampFontTransparency = 1f;
//specify WaterMark's rotation
wg.StampRotation = 45.0f;
//specify WaterMark's color
wg.StampColorNET = new ADK.PDF.Color() { Red = 255, Green = 0, Blue = 0, Gray = 0 };
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'HTML source for Page content
Dim html As String = "<h1 style='text-align:center'>WaterMark Example</h1>"
'assign page content source
wg.CreateFromHTMLText = html
'add text stamp as WaterMark
wg.AddStampText(270.0F, 350.0F, "WaterMark")
'specify WaterMark's font size
wg.StampFontSize = 20
'specify WaterMark's font family
wg.StampFont = "Times New Roman"
'specify WaterMark's opacity
wg.StampFontTransparency = 1F
'specify WaterMark's rotation
wg.StampRotation = 45.0F
'specify WaterMark's color
wg.StampColorNET = New ADK.PDF.Color() With {
.Red = 255,
.Green = 0,
.Blue = 0,
.Gray = 0
}
'specify directory for newly created file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert above sources to PDF file
wg.ConvertToPDF()
End Sub
以下螢幕截圖是新生成的Sample.pdf
文件。
假設我們在本地磁碟 E
中有一個名為myHtmlFile.html
的簡單網頁,寬度為100%
,並設有black
顏色的邊框
。 我們將從中生成 PDF 文件並設置頁邊距。 讓我們從IronPDF開始。
要設定邊距,IronPDF 提供了 ChromePdfRenderOptions
類別,具有以下屬性:
MarginBottom 用來設定頁面底部的邊距。
注意:預設情況下,IronPDF 會在左、上、右、下各設置20mm
的邊距,以提高頁面的可讀性。 如果不需要,我們可以將其設為0mm
。
/**
Set Margins
anchor-margins-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new ChromePdfRenderer();
//specify left Margin
converter.RenderingOptions.MarginLeft = 50;
//specify top Margin
converter.RenderingOptions.MarginTop = 40;
//render html file to PDF
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to the target location
PDF.SaveAs("E:/Sample.pdf");
}
/**
Set Margins
anchor-margins-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new ChromePdfRenderer();
//specify left Margin
converter.RenderingOptions.MarginLeft = 50;
//specify top Margin
converter.RenderingOptions.MarginTop = 40;
//render html file to PDF
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to the target location
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''Set Margins
'''anchor-margins-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create html to PDF converter
Dim converter = New ChromePdfRenderer()
'specify left Margin
converter.RenderingOptions.MarginLeft = 50
'specify top Margin
converter.RenderingOptions.MarginTop = 40
'render html file to PDF
Dim PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html")
'save to the target location
PDF.SaveAs("E:/Sample.pdf")
End Sub
以下截圖顯示了由上述代碼新生成的Sample.pdf
文件:
可以看出,PDF 頁面距離左側是 50mm
,距離頂部是 40
,左邊距是 20mm
,這是默認
的。 我們可以看到,使用 IronPDF 的 ChromePdfRenderOptions
類來設置任何一邊的邊距是多麼簡單。
閱讀更多關於PDF 生成設置的詳細資訊:如何處理 PDF 文件的邊距和其他屬性。
現在,我們將使用 ActivePDF WebGrabber 設定頁面邊距。
要設置頁面邊距,ActivePDF WebGrabber 提供了SetMargins()
函式,我們可以按照以下方式使用它:
設定邊距(上邊距, 下邊距, 左邊距, 右邊距)
我們將使用此函數來設置頁面邊距:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber()
//specify source HTML file path
wg.URL = "E:/myHtmlFile.html";
//Margins
wg.SetMargins(1, 0, 1.5f, 0);
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber()
//specify source HTML file path
wg.URL = "E:/myHtmlFile.html";
//Margins
wg.SetMargins(1, 0, 1.5f, 0);
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: WebGrabber wg = new WebGrabber() wg.URL = "E:/myHtmlFile.html";
New WebGrabber() wg.URL = "E:/myHtmlFile.html"
Dim wg As New WebGrabber() wg.URL
'Margins
wg.SetMargins(1, 0, 1.5F, 0)
'specify directory for newly created file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert HTML file to PDF
wg.ConvertToPDF()
End Sub
以下截圖顯示了由上述代碼新生成的Sample.pdf
文件:
我們可以看到 PDF 頁面從左側有 1.5f
的邊距,從頂部有 1f
的邊距。使用這兩個組件,我們可以輕鬆地根據需要設置頁面邊距。
閱讀更多關於如何使用ActivePDF 設置邊距的信息。
在此比較中,我們將了解如何設置 PDF 文件的頁眉和頁腳。我們將使用兩個組件提供的功能和技術,通過這些方法我們可以以程式方式在 PDF 頁面上打印自定義的頁眉和頁腳。
IronPDF 提供以下屬性,可用於設定頁首和頁尾:
DrawDividerLine: 繪製一條水平線,以將頁面內容與頁眉或頁腳分隔開來。
我們可以在大括號 {}
中使用 IronPDF 的以下預定義函數作為頁首或頁尾:
{pdf-title} 設定文件標題。
讓我們來看看以下示例,其中我們將使用上述功能設置頁眉和頁腳:
/**
Set Header Footers
anchor-headers-and-footers-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new IronPdf.ChromePdfRenderer();
//Page Content source
string html = "<h1 style='text-align:center;'>Page Content</h2>";
//Assign source to converter
using var PDF = converter.RenderHtmlAsPdf(html);
//Add Header settings
converter.RenderingOptions.TextHeader = new TextHeaderFooter()
{
LeftText = "Header Text",
RightText = "{date} {time}",
DrawDividerLine=true,
FontSize=13
};
//Add Footer settings
converter.RenderingOptions.TextFooter = new TextHeaderFooter()
{
RightText = "Page {page} of {total-pages}",
FontSize = 12
};
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
/**
Set Header Footers
anchor-headers-and-footers-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new IronPdf.ChromePdfRenderer();
//Page Content source
string html = "<h1 style='text-align:center;'>Page Content</h2>";
//Assign source to converter
using var PDF = converter.RenderHtmlAsPdf(html);
//Add Header settings
converter.RenderingOptions.TextHeader = new TextHeaderFooter()
{
LeftText = "Header Text",
RightText = "{date} {time}",
DrawDividerLine=true,
FontSize=13
};
//Add Footer settings
converter.RenderingOptions.TextFooter = new TextHeaderFooter()
{
RightText = "Page {page} of {total-pages}",
FontSize = 12
};
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''Set Header Footers
'''anchor-headers-and-footers-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create html to PDF converter
Dim converter = New IronPdf.ChromePdfRenderer()
'Page Content source
Dim html As String = "<h1 style='text-align:center;'>Page Content</h2>"
'Assign source to converter
Dim PDF = converter.RenderHtmlAsPdf(html)
'Add Header settings
converter.RenderingOptions.TextHeader = New TextHeaderFooter() With {
.LeftText = "Header Text",
.RightText = "{date} {time}",
.DrawDividerLine=True,
.FontSize=13
}
'Add Footer settings
converter.RenderingOptions.TextFooter = New TextHeaderFooter() With {
.RightText = "Page {page} of {total-pages}",
.FontSize = 12
}
'save to target location
PDF.SaveAs("E:/Sample.pdf")
End Sub
以下截圖顯示了由上述代碼新生成的Sample.pdf
文件:
我們可以看到
Header Text
列印在頁首的左側。DateTime
列印在頁首的右側。頁面 CurrentPage of TotalPages 在頁腳的右側。
閱讀更多有關使用 IronPDF 設定HTML 到 PDF 屬性的資訊。
現在讓我們使用 ActivePDF WebGrabber 設置頁眉和頁腳:
ActivePDF WebGrabber 提供了 HeaderHTML
和 FooterHTML
屬性來分別設置頁首和頁尾。 原始 HTML 被作為頁面頁首或頁尾傳遞給這些屬性。 與 IronPDF 不同,ActivePDF WebGrabber 並未提供預定義的函數來設置頁眉和頁腳的對齊方式,因此我們必須使用 HTML 和 CSS 屬性來進行設置,如下所示:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//Page content source
string html = @"<h1 style='text-align:center;'>Page Content</h2>";
//assign above source to WebGrabber
wg.CreateFromHTMLText = html;
//specify Footer height
wg.FooterHeight = 0.5f;
//Add Footer setting
wg.FooterHTML = "<div style='text-align: right;'>%cp% of %tp%</div>";
//create object for datetime
DateTime now = DateTime.Now;
//specify header height
wg.HeaderHeight = 0.5f;
//Add Header setting
wg.HeaderHTML = "<div style='float: left;'>Header Text</div>";
//append Header settings
wg.HeaderHTML = $"<div style='float: right;'>{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}</div>";
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//Page content source
string html = @"<h1 style='text-align:center;'>Page Content</h2>";
//assign above source to WebGrabber
wg.CreateFromHTMLText = html;
//specify Footer height
wg.FooterHeight = 0.5f;
//Add Footer setting
wg.FooterHTML = "<div style='text-align: right;'>%cp% of %tp%</div>";
//create object for datetime
DateTime now = DateTime.Now;
//specify header height
wg.HeaderHeight = 0.5f;
//Add Header setting
wg.HeaderHTML = "<div style='float: left;'>Header Text</div>";
//append Header settings
wg.HeaderHTML = $"<div style='float: right;'>{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}</div>";
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'Page content source
Dim html As String = "<h1 style='text-align:center;'>Page Content</h2>"
'assign above source to WebGrabber
wg.CreateFromHTMLText = html
'specify Footer height
wg.FooterHeight = 0.5F
'Add Footer setting
wg.FooterHTML = "<div style='text-align: right;'>%cp% of %tp%</div>"
'create object for datetime
Dim now As DateTime = DateTime.Now
'specify header height
wg.HeaderHeight = 0.5F
'Add Header setting
wg.HeaderHTML = "<div style='float: left;'>Header Text</div>"
'append Header settings
wg.HeaderHTML = $"<div style='float: right;'>{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}</div>"
'specify directory for newly created file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert above sources to PDF file
wg.ConvertToPDF()
End Sub
以下截圖是從上述程式碼新生成的Sample.pdf
文件:
閱讀更多有關如何使用ActivePDF WebGrabber 設定頁首和頁尾的信息。
DateTime
函數Name | Detail |
---|---|
ActivePDF DocConverter | It is used to convert popular file types to and from PDF format. |
ActivePDF WebGrabber | It grabs the HTML from many sources and converts it to PDF files. |
ActivePDF DocSpace | It provides Batch Process Automation, and a user interface for display, generate, converting, manipulating, and interacting with PDF and other file formats. |
ActivePDF Toolkit | It is used to create, modify, view, extract, manipulate, and automate the document content to and from PDF files. |
ActivePDF Portal | It enables the users to view and modify PDF documents from any source in a standard web browser. |
ActivePDF CADConverter | It is used to convert CAD files into PDF. |
ActivePDF Xtractor | It is used to extract and find the text and images from PDF files. |
ActivePDF Spooler | It allows the developer to print the PDF file page on paper. |
ActivePDF Redactor | It is used to hide sensitive information from the viewer. |
ActivePDF Server | It provides the printing solution for different purposes. |
ActivePDF 並未在其ActivePDF 網站上提供有關其套件的任何資訊。 要獲取有關授權的信息,您必須聯繫他們的銷售人員。 然而,您必須清楚地知道您正在尋找哪種類型的生產許可證。 他們沒有提供價格清單,年度授權的價格從 $1,180 起,但可能根據使用範圍而更高,必須詳細說明以取得報價。
IronPDF 提供透明的定價,授權從$749起,並具多種自訂選項。 如果您有任何問題,請聯絡團隊。