Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
The ActivePDF Toolkit
is a software component used to work with PDF files (including generating PDF files from different sources) and setting its properties (like Header, Footer, Margin or WaterMark).
IronPDF
is a C# PDF Library that also provides these functions, with competitive pricing.
Here we'll walk through the functions, code examples, and step-by-step actions for how to use both software components in a .NET Visual Studio project, so you can decide for yourself what's best for your application.
Iron Software is a market-leading component provider, which offers IronPDF to use for working with PDF files. An all inclusive way to easily generate PDF files from different formats and set all properties programmatically. It is favored by developers because of the consistent, reliable, and accurate PDF file output using just a few lines of code.
IronPDF is designed for C#, .NET, VB, ASPX, ASP.NET, MVC, and .NET Core. It supports Visual Studio, NuGet, Linux, Azure, Docker and more.
ActivePDF is a software company that provides many components to deal with PDF files. Unlike the single component IronPDF, ActivePDF provides different solutions for PDF files. For example, to reduce the size of PDF files, you can use ActivePDF Compressor
. To create PDF files from HTML sources, use ActivePDF WebGrabber
.
In this article, we will use ActivePDF WebGrabber for comparison with IronPDF, let's take a look at it:
ActivePDF WebGrabber is a separate component of ActivePDF specifically used to generate PDF files from HTML sources like URL, HTML File, or HTML string. It also provides the functions to set page properties like Header, Footer, Margin, WaterMark, or BookMark to create PDF files according to our requirements.
Let's take a look at the side-by-side comparison of both components.
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 . |
You can add IronPDF library in your project two different ways, with no difference which one you adopt.
IronPDF
, then install it.Alternatively:
tools
package manager console
Install-Package IronPdf
We can also download IronPDF.dll, then add its reference in the project.
If you can access IronPDF
by writing using IronPdf;
namespace, it means IronPDF successfully imported into your project and is ready for use.
Download WebGrabber-install.exe, and select download file. Once it downloads, double click on the downloaded file. Then request an activation key from ActivePDF for use the following 15-day evaluation key: 001-AEALX-LC6Z5-7YD95-S3D8J-3LR25.
After successful installation, go to the following directory: C:\Program Files\ActivePDF\WebGrabber\bin\
In this directory, you get the APWebGrabber.Net45.dll
file. Add its reference in your Visual Studio project.
Now, if you can access WebGrabber
by writing using APWebGrabber;
namespace, it means ActivePDF WebGrabber successfully imported into your project and you can use it.
ActivePDF Documentation is available to learn more about ActivePDF WebGrabber installation.
We have seen the introduction of these two components and their installation processes, and now we will start the comparison by performing different tasks using both. This will let us understand the programming structure of both and decide which one is the best for our projects. For better understanding, we will execute a specific use case in each task and provide the code used to implement.
In the first comparison, we will take a use case where we need to create a PDF file by HTML string and save it to the target location. Firstly, we start to implement this use case by 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
Output:
The above code will create a PDF file sample.pdf
in Local Disk E:
and its screenshot is:
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
The following screenshot is the newly generated sample.pdf
file from this code:
In this comparison, we take the use case that we need to generate a PDF file from an HTML file named myHtmlFile.html
which exists in E:/
directory, and it has the following HTML and CSS code:
<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>
Now, we will convert the myHtmlFile.html
file to a PDF file using both components. Let's start with 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
The following screenshot is of the newly generated Sample.pdf
file using the above code:
We can see that the HTML page myHtmlFile.html
successfully converted to PDF file Sample.pdf
, and the CSS styles are also applied.
Read IronPDF documentation for more about how we can use IronPDF in our .NET project.
Let's perform the same task using 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
The following screenshot is of the newly generated Sample.pdf
file, using the above code:
Let's suppose we have a URL https://yandex.com/ and we want to generate a PDF file of its webpage. For this, both components provide a function. First, we will see how it can be done by 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
The following screenshot is of the newly generated Sample.pdf
file by the above code
You can visit the webpage of the URL sample to compare and see how accurately the IronPDF file matches.
Now, we will do the same task using 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
The following screenshot is of the newly generated Sample.pdf
file by the above code:
In this comparison, we will create a PDF file using an HTML string, and then add a WaterMark in the center of the page. Let's start with IronPDF.
IronPDF provides the following function to add WaterMark:
WatermarkPage(WaterMark HTML String, PageIndexToWaterMark, WaterMarkLocation,Opacity, Rotation, Hyperlink)
We can use the WaterMarkLocation
to set the WaterMark on the following positions:
Let's see how to use the above functions to set the WaterMark:
/**
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
The following screenshot is of the newly generated Sample.pdf
file by the above code:
We can add any type of WaterMark and set its properties by CSS. Now, we will do the same task using ActivePDF WebGrabber.
ActivePDF WebGrabber does not provide a specific function for WaterMark, unlike IronPDF. But we can use the AddStampText()
function as a workaround for this purpose:
AddStampText(float x, float y, string stampText);
Note: ActivePDF WebGrabber does not support CSS styling for TextStamp. We have to set it by other provided functions as follows:
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
The following screenshot is of the newly generated Sample.pdf
file.
Let's suppose we have a simple web page named myHtmlFile.html
in our Local Disk E
, which has 100%
width and a border
with black
color. We will generate a PDF file from it and set the page Margin. Let's start with IronPDF.
To set the Margins, IronPDF provides the ChromePdfRenderOptions
class, which has the following properties:
Note: By default, IronPDF sets a 20mm
mMargin from the left, top, right, and the bottom to make the page more readable. We can set it 0mm
if we don't need it.
/**
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
The following screenshot is of the newly generated Sample.pdf
file by the above code:
It can be seen that the PDF page has 50mm
from the left side, 40
from the top, and the left side Margin is 20mm
which is by default
. We can see how simple it is to set the Margin of any side by using the ChromePdfRenderOptions
class of IronPDF.
Read more about PDF Generation Settings for further detail: how to work with margins and other properties of the PDF file.
Now, we will set the page Margin using ActivePDF WebGrabber.
To set the page Margins, ActivePDF WebGrabber provides the SetMargins()
function, and we can use it as follows: SetMargins(Top Margin, Bottom Margin, Left Margin, Right Margin)
We will use this function to set the page margin:
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
The following screenshot is of the newly generated Sample.pdf
file by the above code:
We can see that the PDF page has a 1.5f
Margin from the left side and 1f
from the top. Using both components, we can easily set page margins according to our requirements.
Read more on how to set margins with ActivePDF.
In this comparison, we will see how to set the Header and Footer of a PDF file. We will use both components' provided functions and techniques, through which we can print custom Headers and Footers on PDF pages programmatically.
IronPDF provides the following properties, which can be used to set both Headers and Footers:
We can use the following predefined functions of IronPDF in Curly Brackets {}
for Header or Footer:
Let's take a look at the following example, in which we will set page Header and Footer by using the above functions:
/**
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
The following screenshot is of the newly generated Sample.pdf
file by the above code:
We can see that
Header Text
is printed on the left side of the Header.DateTime
is printed on the right side of the Header.Page CurrentPage of TotalPages
on the right side of the Footer.Read more about setting HTML to PDF properties using IronPDF.
Let's now use ActivePDF WebGrabber to set page Header and Footers:
ActivePDF WebGrabber provides the HeaderHTML
and FooterHTML
properties to set the Header and Footer respectively. The raw HTML is passed to these properties as the Page Header or Footer. Unlike IronPDF, ActivePDF WebGrabber does not provide predefined functions to set the alignment of Header and Footer, so we have to set it using HTML and CSS properties as follows:
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
The following screenshot is of the newly generated Sample.pdf
file from the above code:
Read more about how to set headers and footers with ActivePDF WebGrabber.
DateTime
function of the .NET frameworkName | 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 does not provide any information about their packages on their ActivePDF website. To get information about licensing, you must contact their salesperson. However, you must know exactly what type of production license you are looking for. They do not provide a list of prices, and while prices start at $1,180 for an annual license, it can be higher depending on scope of use and must be detailed in order to get a quote.
IronPDF provides transparent pricing with licenses from $749, with many customizable options. Contact the team if you have any questions.
Explore the API Reference for IronPDF C# Library, including details of all of IronPDF’s features, classes, method fields, namespaces, and enums.
View the API Reference9 .NET API products for your office documents