Aspose PDF Converter Tutorial and Comparison
Examine how to work with the Aspose PDF converter in .NET by comparing its programming structure, provided functions, licensing and pricing packages. Follow the step-by-step tutorials and use the code examples to see for yourself which library is best for working with PDFs in your C# project.
Overview
About Aspose PDF API
Aspose API provider is a file format component provider company. The specialized component Aspose PDF DLL is used to deal with PDF files. It allows developers to create and set the properties of PDF documents programmatically. We can also use it to add Watermarks, Text Stamps, Bookmarks, and compress PDF files.
About IronPDF
IronPDF C# Library is provided by Iron Software for generating, editing, and manipulating PDF files in .NET projects. It is known well becuase it requires only a few lines of code with a simple programming structure to get the required PDF files. By using it, we can easily generate PDF files from many sources (such as HTML String, HTML Files, or URLs), and then set its properties (such as Page Number, Headers, Page Margins or Watermarks and more).
1. Aspose PDF Licensing and Pricing
When we need to purchase APIs for our project, pricing and licensing packages can play a very important role in the selection.
Here we compare the main 4 perpetual licenses provided by Aspose PDF to their IronPDF counterparts.
License Coverage | IronPDF | Aspose.PDF |
---|---|---|
# of License Options | 28 customizable license options for your needs | 4 licenses available for general needs |
1 developer, 1 project, 1 location | $399 with 1 yr free support | No license |
1 developer, unlimited projects, 1 location | $699 with 1 yr free support | $999 with standard suport or $1498 with paid support |
1 developer, unlimited projects, unlimited locations | $1,099 with 1 yr free support | $2,997 with standard support or $4,696 with paid support |
Up to 10 developers, unlimited projects, up to 10 locations | $1,799 with 1 yr free support | $4,995 with standard suport or $7,994 with paid support |
1 SaaS/OEM product, unlimited developers, unlimited locations | $1,599 with 1 yr free support | No license |
Unlimited SaaS/OEM products, up to 10 developers, unlimited locations | $5,499 with 1 yr free support | $13,986 with standard suport or $21,985 with paid support |
Purchase a license | IronPDF Licenses | Aspose PDF Licenses |
While Aspose offers multiple tiers of support pricing, IronPDF offers more affordable licenses, customizable options, and free support for all coverage.
Aspose PDF Supported Platforms
Let's look at the supported framework and platforms of Aspose.PDF.
Aspose PDF Supported Frameworks
- .NET Framework 2.0 or above
- .NET Core 2.0
- .NET Core 2.1
Aspose PDF Supported Platforms
- Windows
- MacOS
- Linux
- Azure
Aspose PDF Dependencies
If we want to use the Aspose.PDF component in our project, then we need to make sure that we fulfill the dependencies in our Visual Studio Project:
Aspose PDF for .NET Framework 4.0
- No dependencies.
Aspose PDF For .NET Standard 2.0
- Microsoft.Extensions.DependencyModel (>= 2.0.4)
- System.Diagnostics.PerformanceCounter (>= 4.5.0)
- System.Drawing.Common (>= 4.7.0)
- System.Reflection.Emit (>= 4.7.0)
- System.Security.Cryptography.Pkcs (>= 4.7.0)
- System.Security.Permissions (>= 4.5.0)
- System.Text.Encoding.CodePages (>= 4.5.0)
Aspose PDF For .NET Standard 2.1
- Microsoft.Extensions.DependencyModel (>= 2.0.4)
- System.Diagnostics.PerformanceCounter (>= 4.5.0)
- System.Drawing.Common (>= 4.7.0)
- System.Security.Cryptography.Pkcs (>= 4.7.0)
- System.Security.Permissions (>= 4.5.0)
- System.Text.Encoding.CodePages (>= 4.5.0)
IronPDF Supported Platforms
.Net framework 4.0 or above for
- Windows
- Azure
.NET Standard 2.0 & Core 2 & 3 for
- Windows
- MacOS
- Linux
- Azure
Cloud hosting services included
- Microsoft Azure
- Docker
- AWS
IronPDF can be used with:
- ASP.Net MVC Application
- ASP.Net Web Forms Application
- Console Application
- Cloud Application
- Service
- Function
- Desktop Application.
IronPDF Dependencies
IronPDFPDF for .NET Framework 4.0
- Iron.Assets.Rendering.Windows (>= 20.0.0)
IronPDFPDF for .NET Standard 2.0 or above
- Iron.Assets.Rendering.Universal (>= 20.0.0)
- System.Drawing.Common (>= 4.7.0)
Step 1: Installation
Aspose PDF Download
There are two possible ways that we can use Aspose.PDF components in our project, and there is no difference whichever one you choose.
Aspose.PDF Download via NuGet Package
Open the NuGet Package Manager of your project in Visual Studio and browse Aspose.Pdf
, then install it.
PM > Install-Package Aspose.Pdf
Install with Aspose.PDF.dll
You can also download Aspose.PDF.dll and extract the downloaded file. It will create some folder and files.
- Go to
Bin
folder - Go to the required .Net Framework folder, which includes
Aspose.PDF.dll
. - Add the reference of this file in your Visual Studio project.
Now, you can use Aspose.PDF functions and classes using Aspose.Pdf
namespace.
Install IronPDF
We can also install IronPDF in our project using two different ways.
Install IronPDF with NuGet
The easiest technique is to add IronPDF in the project.
- Go to NuGet Package Manager in Visual Studio project and browse
IronPDF
- Install IronPDF
PM > Install-Package IronPdf
Download IronPDF.dll
Another option is to download IronPDF.dll, then add its reference to the project. After this, we can use IronPDF classes and provided functions from the using IronPdf
namespace.
How To Tutorials
2. HTML String to PDF
Let's take the first major use case: that we want to create a PDF file by HTML string and save it in the target location. Let's compare the code required and start with IronPDF.
2.1. IronPDF Convert HTML String to PDF
using IronPdf;
static void Main(string[] args)
{
//Create rendering converter
var converter = new HtmlToPdf();
//HTML text
string HTML = "<h1>Hello IronPDF!</h1> <h2>Welcome to PDF File</h2> ";
//Convert HTML string to PDF file
var PDF = converter.RenderHtmlAsPdf(HTML);
//Save the file
PDF.SaveAs("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
using IronPdf;
static void Main(string[] args)
{
//Create rendering converter
var converter = new HtmlToPdf();
//HTML text
string HTML = "<h1>Hello IronPDF!</h1> <h2>Welcome to PDF File</h2> ";
//Convert HTML string to PDF file
var PDF = converter.RenderHtmlAsPdf(HTML);
//Save the file
PDF.SaveAs("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'Create rendering converter
Dim converter = New HtmlToPdf()
'HTML text
Dim HTML As String = "<h1>Hello IronPDF!</h1> <h2>Welcome to PDF File</h2> "
'Convert HTML string to PDF file
Dim PDF = converter.RenderHtmlAsPdf(HTML)
'Save the file
PDF.SaveAs("Sample.pdf")
Console.WriteLine("PDF File Successfully Created....")
Console.ReadKey()
End Sub
The above code will create a PDF file Sample.pdf
and save it in the target location.
Note:
- If you do not give the full path and just give the file name as we do in the above example, then the PDF file will be created in the
bin\Debug
folder of your project. - In the case that you want to generate the
Sample.pdf
file inLocal Disk E
then you can write:PDF.SaveAs("E:\\Sample.pdf");
Read more about how to create PDF from HTML and working with PDF files using IronPDF.
2.2. Aspose PDF Convert HTML String to PDF
using Aspose.Pdf;
static void Main(string[] args)
{
//Create new document object
Document doc = new Document();
//Add a page in document object
Page page = doc.Pages.Add();
//Generate HTML String
string HtmlStr = "<h1>Hello Aspose.PDF!</h1> <h2>Welcome to PDF File</h2> ";
//Create html fragment by above HTML string
HtmlFragment HtmlFrg= new HtmlFragment(HtmlStr);
//Add html fragment as paragraph in document page
page.Paragraphs.Add(HtmlFrg);
//Save the file on target location
doc.Save("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
using Aspose.Pdf;
static void Main(string[] args)
{
//Create new document object
Document doc = new Document();
//Add a page in document object
Page page = doc.Pages.Add();
//Generate HTML String
string HtmlStr = "<h1>Hello Aspose.PDF!</h1> <h2>Welcome to PDF File</h2> ";
//Create html fragment by above HTML string
HtmlFragment HtmlFrg= new HtmlFragment(HtmlStr);
//Add html fragment as paragraph in document page
page.Paragraphs.Add(HtmlFrg);
//Save the file on target location
doc.Save("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
Imports Aspose.Pdf
Shared Sub Main(ByVal args() As String)
'Create new document object
Dim doc As New Document()
'Add a page in document object
Dim page As Page = doc.Pages.Add()
'Generate HTML String
Dim HtmlStr As String = "<h1>Hello Aspose.PDF!</h1> <h2>Welcome to PDF File</h2> "
'Create html fragment by above HTML string
Dim HtmlFrg As New HtmlFragment(HtmlStr)
'Add html fragment as paragraph in document page
page.Paragraphs.Add(HtmlFrg)
'Save the file on target location
doc.Save("Sample.pdf")
Console.WriteLine("PDF File Successfully Created....")
Console.ReadKey()
End Sub
The above code will create a new PDF file Sample.pdf
, just like we created using IronPDF.
2.3. Difference between Aspose and IronPDF
Using Aspose.PDF, we first need to create a new Page, HtmlFragment, and add it into the page paragraph, and then save it to the target location. IronPDF has no such type of coding structure and provides a way with many fewer lines of code.
Read more about how to Convert PDF with Aspose PDF DLL and working with Aspose.PDF in .NET applications.
3. HTML File to PDF
Now, let's take another use case: create a PDF file from an existing HTML file.
Note: Assume that we have an HTML file MyHtmlFile.html
which exists in the bin\Debug
folder of the project and we want to create a PDF file from it.
3.1.IronPDF Convert HTML File to PDF
using IronPdf;
static void Main(string[] args)
{
//Create HTML to PDF converter
var converter = new IronPdf.HtmlToPdf();
//Render HTML file to PDF
var PDF = converter.RenderHTMLFileAsPdf("MyHtmlFile.html");
//Save to target location
PDF.SaveAs("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
using IronPdf;
static void Main(string[] args)
{
//Create HTML to PDF converter
var converter = new IronPdf.HtmlToPdf();
//Render HTML file to PDF
var PDF = converter.RenderHTMLFileAsPdf("MyHtmlFile.html");
//Save to target location
PDF.SaveAs("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'Create HTML to PDF converter
Dim converter = New IronPdf.HtmlToPdf()
'Render HTML file to PDF
Dim PDF = converter.RenderHTMLFileAsPdf("MyHtmlFile.html")
'Save to target location
PDF.SaveAs("Sample.pdf")
Console.WriteLine("PDF File Successfully Created....")
Console.ReadKey()
End Sub
The above code will create a new PDF file Sample.pdf
from the MyHtmlFile.html
file.
3.2. Aspose PDF Convert HTML File to PDF
using Aspose.Pdf;
static void Main(string[] args)
{
//create HTML load option object
HtmlLoadOptions options = new HtmlLoadOptions();
//load HTML file in document object
Document pdfDocument = new Document("MyHtmlFile.html", options);
//save to the target location
pdfDocument.Save("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
using Aspose.Pdf;
static void Main(string[] args)
{
//create HTML load option object
HtmlLoadOptions options = new HtmlLoadOptions();
//load HTML file in document object
Document pdfDocument = new Document("MyHtmlFile.html", options);
//save to the target location
pdfDocument.Save("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
Imports Aspose.Pdf
Shared Sub Main(ByVal args() As String)
'create HTML load option object
Dim options As New HtmlLoadOptions()
'load HTML file in document object
Dim pdfDocument As New Document("MyHtmlFile.html", options)
'save to the target location
pdfDocument.Save("Sample.pdf")
Console.WriteLine("PDF File Successfully Created....")
Console.ReadKey()
End Sub
The above code will also create a new PDF file Sample.pdf
from MyHtmlFile.html
, but here we need to specify HtmlLoadOptions
.
4. Work with Headers and Footers
It is a common requirement that we need to add Headers and Footers on PDF pages for different purposes such as including the document name, page numbers, references, date and time, or other similar functions. Both components provide different types of functions to accomplish these:
4.1. IronPDF Headers and Footers Functions
IronPDF has the following properties by which we can easily set Headers and Footers of newly created PDF file pages.
LeftText
to write text on the left side of the Header or Footer.RightText
to write text on the right side of the Header or Footer.CenterText
to write text in the center of the Header or Footer.FontSize
to specify the font size of the text of the Header of Footer.FontFamily
to specify the font family of the Header or Footer.DrawDividerLine
to draw a line that separates page content and the Header or Footer.Spacing
to specify the space between page content and the Header or Footer.
The following example showcases how to use the above properties.
using IronPdf;
static void Main(string[] args)
{
//Create HTML to PDF converter
var converter = new IronPdf.HtmlToPdf();
//Add Header
converter.PrintOptions.Header = new SimpleHeaderFooter()
{
LeftText = "Header Text",
RightText = "{date} {time}",
};
//Add Footer
converter.PrintOptions.Footer = new SimpleHeaderFooter()
{
RightText = "Footer Text"
};
//Add Page Content
var PDF = converter.RenderHtmlAsPdf("<h1>Page Content</h2>");
//save to target location
PDF.SaveAs("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
using IronPdf;
static void Main(string[] args)
{
//Create HTML to PDF converter
var converter = new IronPdf.HtmlToPdf();
//Add Header
converter.PrintOptions.Header = new SimpleHeaderFooter()
{
LeftText = "Header Text",
RightText = "{date} {time}",
};
//Add Footer
converter.PrintOptions.Footer = new SimpleHeaderFooter()
{
RightText = "Footer Text"
};
//Add Page Content
var PDF = converter.RenderHtmlAsPdf("<h1>Page Content</h2>");
//save to target location
PDF.SaveAs("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'Create HTML to PDF converter
Dim converter = New IronPdf.HtmlToPdf()
'Add Header
converter.PrintOptions.Header = New SimpleHeaderFooter() With {
.LeftText = "Header Text",
.RightText = "{date} {time}"
}
'Add Footer
converter.PrintOptions.Footer = New SimpleHeaderFooter() With {.RightText = "Footer Text"}
'Add Page Content
Dim PDF = converter.RenderHtmlAsPdf("<h1>Page Content</h2>")
'save to target location
PDF.SaveAs("Sample.pdf")
Console.WriteLine("PDF File Successfully Created....")
Console.ReadKey()
End Sub
The above code will create a PDF file, Sample.pdf
, and print Header Text
on the left side of the Header, Date Time
on the right side of the Header, and Footer Text
on the right side of the Footer.
Read more about how to Add Header and Footers in an HTML to PDF conversion with full list of functions provided by IronPDF.
4.2. Aspose PDF Headers and Footers Functions
To deal with Headers and Footers, Aspose.PDF
introduced the TextStamp
class. By using it, we can easily add Headers and Footers on PDF file pages and set their properties. There are many subclasses of TextStamp
, but here we will discuss the basic three classes and their properties which are commonly used in our daily work.
VerticalAlignment (used to set the vertical alignment of TextStamp and has the following properties)
- None for no vertical alignment.
- Top sets the vertical alignment to the top.
- Center sets vertical alignment in the center.
- Bottom sets vertical alignment the bottom.
HorizontalAlignment (used to set the horizontal alignment of TextStamp and has the following properties)
- None for no horizontal alignment.
- Left sets horizontal alignment to left.
- Right sets horizontal alignment to right.
- Center sets horizontal alignment in the center.
- Justify Text will be aligned on both left and right margins.
- FullJustify all lines will be left-aligned and right-aligned
TextState (used to set the properties of the text, and has some basic properties)
- Font sets the font of the text
- FontStyles sets the font style of the text.
- FontSize sets the font size of the text.
- Color sets the color of the text.
- Underline sets the underline for the text.
- StrikeOut sets the strikeout style for the text.
See the following example for how to use the above properties to set Header and Footer.
using Aspose.Pdf;
static void Main(string[] args)
{
Document doc = new Document();
Page page = doc.Pages.Add();
HtmlFragment html = new HtmlFragment("<h1>Page Content</h2>");
page.Paragraphs.Add(html);
//Add Header text
TextStamp title = new TextStamp("Header Text");
title.VerticalAlignment = VerticalAlignment.Top;
title.HorizontalAlignment = HorizontalAlignment.Left;
title.TextState.FontSize = 20;
doc.Pages[1].AddStamp(title);
//Add Header Datetime
TextStamp datetime = new TextStamp(System.DateTime.Now.ToString());
datetime.VerticalAlignment = VerticalAlignment.Top;
datetime.HorizontalAlignment = HorizontalAlignment.Right;
datetime.TextState.FontSize = 20;
doc.Pages[1].AddStamp(datetime);
//Add Footer text
TextStamp footer = new TextStamp("Footer Text");
footer.VerticalAlignment = VerticalAlignment.Bottom;
footer.HorizontalAlignment = HorizontalAlignment.Right;
footer.TextState.FontSize = 20;
doc.Pages[1].AddStamp(footer);
doc.Save("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
using Aspose.Pdf;
static void Main(string[] args)
{
Document doc = new Document();
Page page = doc.Pages.Add();
HtmlFragment html = new HtmlFragment("<h1>Page Content</h2>");
page.Paragraphs.Add(html);
//Add Header text
TextStamp title = new TextStamp("Header Text");
title.VerticalAlignment = VerticalAlignment.Top;
title.HorizontalAlignment = HorizontalAlignment.Left;
title.TextState.FontSize = 20;
doc.Pages[1].AddStamp(title);
//Add Header Datetime
TextStamp datetime = new TextStamp(System.DateTime.Now.ToString());
datetime.VerticalAlignment = VerticalAlignment.Top;
datetime.HorizontalAlignment = HorizontalAlignment.Right;
datetime.TextState.FontSize = 20;
doc.Pages[1].AddStamp(datetime);
//Add Footer text
TextStamp footer = new TextStamp("Footer Text");
footer.VerticalAlignment = VerticalAlignment.Bottom;
footer.HorizontalAlignment = HorizontalAlignment.Right;
footer.TextState.FontSize = 20;
doc.Pages[1].AddStamp(footer);
doc.Save("Sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
Imports System
Imports Aspose.Pdf
Shared Sub Main(ByVal args() As String)
Dim doc As New Document()
Dim page As Page = doc.Pages.Add()
Dim html As New HtmlFragment("<h1>Page Content</h2>")
page.Paragraphs.Add(html)
'Add Header text
Dim title As New TextStamp("Header Text")
title.VerticalAlignment = VerticalAlignment.Top
title.HorizontalAlignment = HorizontalAlignment.Left
title.TextState.FontSize = 20
doc.Pages(1).AddStamp(title)
'Add Header Datetime
Dim datetime As New TextStamp(DateTime.Now.ToString())
datetime.VerticalAlignment = VerticalAlignment.Top
datetime.HorizontalAlignment = HorizontalAlignment.Right
datetime.TextState.FontSize = 20
doc.Pages(1).AddStamp(datetime)
'Add Footer text
Dim footer As New TextStamp("Footer Text")
footer.VerticalAlignment = VerticalAlignment.Bottom
footer.HorizontalAlignment = HorizontalAlignment.Right
footer.TextState.FontSize = 20
doc.Pages(1).AddStamp(footer)
doc.Save("Sample.pdf")
Console.WriteLine("PDF File Successfully Created....")
Console.ReadKey()
End Sub
This will create the same PDF file Sample.pdf
as we created using IronPDF: Header Text
on the left side of the Header, Date Time
on the right side of the Header and Footer Text
on the right side of page bottom.
You can compare the ease of working with IronPDF and their simple functions to the list provided by Aspose.
Read more about using Aspose Manage Header and Footer of PDF File.
5. Add Page Numbers to PDF File
Let's suppose that we want to create a PDF file from an HTML string, and then add a page number to the Header of the page.
5.1. IronPDF Add Page Numbers to PDF File
using IronPdf;
static void Main(string[] args)
{
//Create HTML to PDF converter
var converter = new IronPdf.HtmlToPdf();
//add header
converter.PrintOptions.Header = new SimpleHeaderFooter()
{
RightText = "Page {page} of {total-pages}",
};
//Source HTML string
string html = "<h1 style='text-align:center'>Welcome To IronPdf</h1>";
//Convert string to PDF file
var PDF = converter.RenderHtmlAsPdf(html);
//Save to target location
PDF.SaveAs("Sample.pdf");
Console.WriteLine("successfully created..!");
}
using IronPdf;
static void Main(string[] args)
{
//Create HTML to PDF converter
var converter = new IronPdf.HtmlToPdf();
//add header
converter.PrintOptions.Header = new SimpleHeaderFooter()
{
RightText = "Page {page} of {total-pages}",
};
//Source HTML string
string html = "<h1 style='text-align:center'>Welcome To IronPdf</h1>";
//Convert string to PDF file
var PDF = converter.RenderHtmlAsPdf(html);
//Save to target location
PDF.SaveAs("Sample.pdf");
Console.WriteLine("successfully created..!");
}
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'Create HTML to PDF converter
Dim converter = New IronPdf.HtmlToPdf()
'add header
converter.PrintOptions.Header = New SimpleHeaderFooter() With {.RightText = "Page {page} of {total-pages}"}
'Source HTML string
Dim html As String = "<h1 style='text-align:center'>Welcome To IronPdf</h1>"
'Convert string to PDF file
Dim PDF = converter.RenderHtmlAsPdf(html)
'Save to target location
PDF.SaveAs("Sample.pdf")
Console.WriteLine("successfully created..!")
End Sub
The above code will create a PDF file Sample.pdf
, insert the HTML data, and add the Page Number
in the page Header.
Output: Here's a screenshot of our newly created sample.pdf
file.
5.2. Aspose PDF Add Page Numbers to PDF File
Aspose.PDF does not provide the predefined function to set Headers and Footers, unlike IronPDF. Using Aspose.PDF, we would need to work with PageNumberStamp
and set its alignment for the Header and Footer on the PDF page. See the example below.
using Aspose.Pdf;
static void Main(string[] args)
{
//Create new document
Document doc = new Document();
//New new page of document
Page page = doc.Pages.Add();
//Source HTML string
string html = "<h1 style='text-align:center'>Welcome To Aspose.PDF</h1>";
//Create HTML fragment for source string
HtmlFragment frag = new HtmlFragment(html);
//Add fragment as page paragraph
page.Paragraphs.Add(frag);
//Create PageNumberStamp
PageNumberStamp pageNumberStamp = new PageNumberStamp();
//Setting its txt to print
pageNumberStamp.Format = "Page # of " + doc.Pages.Count;
pageNumberStamp.VerticalAlignment = VerticalAlignment.Top;
pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Right;
// Add PageNumberStamp to page
page.AddStamp(pageNumberStamp);
//Save document to the target location
doc.Save("sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
using Aspose.Pdf;
static void Main(string[] args)
{
//Create new document
Document doc = new Document();
//New new page of document
Page page = doc.Pages.Add();
//Source HTML string
string html = "<h1 style='text-align:center'>Welcome To Aspose.PDF</h1>";
//Create HTML fragment for source string
HtmlFragment frag = new HtmlFragment(html);
//Add fragment as page paragraph
page.Paragraphs.Add(frag);
//Create PageNumberStamp
PageNumberStamp pageNumberStamp = new PageNumberStamp();
//Setting its txt to print
pageNumberStamp.Format = "Page # of " + doc.Pages.Count;
pageNumberStamp.VerticalAlignment = VerticalAlignment.Top;
pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Right;
// Add PageNumberStamp to page
page.AddStamp(pageNumberStamp);
//Save document to the target location
doc.Save("sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
Imports Aspose.Pdf
Shared Sub Main(ByVal args() As String)
'Create new document
Dim doc As New Document()
'New new page of document
Dim page As Page = doc.Pages.Add()
'Source HTML string
Dim html As String = "<h1 style='text-align:center'>Welcome To Aspose.PDF</h1>"
'Create HTML fragment for source string
Dim frag As New HtmlFragment(html)
'Add fragment as page paragraph
page.Paragraphs.Add(frag)
'Create PageNumberStamp
Dim pageNumberStamp As New PageNumberStamp()
'Setting its txt to print
pageNumberStamp.Format = "Page # of " & doc.Pages.Count
pageNumberStamp.VerticalAlignment = VerticalAlignment.Top
pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Right
' Add PageNumberStamp to page
page.AddStamp(pageNumberStamp)
'Save document to the target location
doc.Save("sample.pdf")
Console.WriteLine("PDF File Successfully Created....")
Console.ReadKey()
End Sub
Output: Here is the screenshot of newly created sample.pdf
file.
6. Add Watermarks
We often need to add Watermarks on our PDF file pages for advertisement, security, or copyright issues. Let's create a PDF file from an HTML string, and then add Watermark using both components.
6.1. IronPDF Add Watermark
To add a watermark on the PDF page, IronPDF provides the WatermarkPage
class.
WatermarkPage
Definition: WatermarkPage (WatermarkText, PageIndex, WaterMarkLocation, Opacity, Rotation, Hyperlink);
WatermarkText
= the actual text written in HTML which displays as Watermark text.PageIndex
= write the page number as the Watermark.Opacity
= set the opacity of the Watermark.Rotation
= set the rotation of the Watermark content clockwise.Hyperlink
= hyperlink that the Watermark will link to.WaterMarkLocation
= set the position of the Watermark, which we can set using the following positions:- TopLeft
- TopCenter
- TopRight
- MiddleLeft
- MiddleCenter
- MiddleRight
- BottomLeft
- BottomCenter
- BottomRight
Let's see the following example, where we will understand how to use the above functions in our project.
using IronPdf;
static void Main(string[] args)
{
//Create HTML to PDF converter
var converter = new IronPdf.HtmlToPdf();
//Create source HTML string
string html = "<h1 style='text-align:center'>Welcome To IronPdf</h1><h2 style='text-align:center'>Page Content</h2>";
//Add string as PDF file content
var PDF = converter.RenderHtmlAsPdf(html);
//Create string for Watermark
string WMStr = "<h1 style='color:red'>Sample WaterMark</h1>";
//Add Watermark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter,100,-45, "");
//save the document
PDF.SaveAs("sample.pdf");
Console.WriteLine("successfully created..!");
}
using IronPdf;
static void Main(string[] args)
{
//Create HTML to PDF converter
var converter = new IronPdf.HtmlToPdf();
//Create source HTML string
string html = "<h1 style='text-align:center'>Welcome To IronPdf</h1><h2 style='text-align:center'>Page Content</h2>";
//Add string as PDF file content
var PDF = converter.RenderHtmlAsPdf(html);
//Create string for Watermark
string WMStr = "<h1 style='color:red'>Sample WaterMark</h1>";
//Add Watermark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter,100,-45, "");
//save the document
PDF.SaveAs("sample.pdf");
Console.WriteLine("successfully created..!");
}
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'Create HTML to PDF converter
Dim converter = New IronPdf.HtmlToPdf()
'Create source HTML string
Dim html As String = "<h1 style='text-align:center'>Welcome To IronPdf</h1><h2 style='text-align:center'>Page Content</h2>"
'Add string as PDF file content
Dim PDF = converter.RenderHtmlAsPdf(html)
'Create string for Watermark
Dim WMStr As String = "<h1 style='color:red'>Sample WaterMark</h1>"
'Add Watermark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter,100,-45, "")
'save the document
PDF.SaveAs("sample.pdf")
Console.WriteLine("successfully created..!")
End Sub
Output: Here is the screenshot of the newly created sample.pdf
file with watermark.
If we want to add a Watermark on multiple pages, but not all, then we can use the WatermarkPages()
function as follows:
WatermarkPages(WaterMark Text, new[] { PageIndex 1, PageIndex 2,...., PageIndex N }, WaterMarkLocation, Opacity, rotation)
If we do want to add a Watermark on all pages, then we can use the WatermarkAllPages()
function like this:WatermarkAllPages(WaterMark Text,WaterMarkLocation, opacity, rotation);
Read more about how to add a watermark to PDFs.
6.2. Aspose PDF Add Watermark
Aspose.PDF does not provide a special function to add text as a Watermark, unlike IronPDF. Instead, we need to use the TextStamp
class. Let's see how that works.
using Aspose.Pdf;
using Aspose.Pdf.Text;
static void Main(string[] args)
{
//create new document
Document pdfDocument = new Document();
//add new page to document
Page page = pdfDocument.Pages.Add();
//source HTML string
string HtmlStr = "<h1 style='text-align:center'>Welcome To Aspose.PDF</h1><h2 style='text-align:center'>Page Content</h2>";
//create HTML fragment by source HTML string
HtmlFragment HtmlFrg = new HtmlFragment(HtmlStr);
//add HTML fragment as page paragraph
page.Paragraphs.Add(HtmlFrg);
//Watermark string
string WMStr = "Sample WaterMark";
//create TextStamp of above string
TextStamp textStamp = new TextStamp(WMStr);
//setting TextStamp properties
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.VerticalAlignment = VerticalAlignment.Center;
textStamp.RotateAngle = 45;
textStamp.TextState.Font = FontRepository.FindFont("Times New Roman");
textStamp.TextState.FontSize = 15F;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
//add to the specific page
pdfDocument.Pages[1].AddStamp(textStamp);
//save to the target location
pdfDocument.Save("sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
using Aspose.Pdf;
using Aspose.Pdf.Text;
static void Main(string[] args)
{
//create new document
Document pdfDocument = new Document();
//add new page to document
Page page = pdfDocument.Pages.Add();
//source HTML string
string HtmlStr = "<h1 style='text-align:center'>Welcome To Aspose.PDF</h1><h2 style='text-align:center'>Page Content</h2>";
//create HTML fragment by source HTML string
HtmlFragment HtmlFrg = new HtmlFragment(HtmlStr);
//add HTML fragment as page paragraph
page.Paragraphs.Add(HtmlFrg);
//Watermark string
string WMStr = "Sample WaterMark";
//create TextStamp of above string
TextStamp textStamp = new TextStamp(WMStr);
//setting TextStamp properties
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.VerticalAlignment = VerticalAlignment.Center;
textStamp.RotateAngle = 45;
textStamp.TextState.Font = FontRepository.FindFont("Times New Roman");
textStamp.TextState.FontSize = 15F;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
//add to the specific page
pdfDocument.Pages[1].AddStamp(textStamp);
//save to the target location
pdfDocument.Save("sample.pdf");
Console.WriteLine("PDF File Successfully Created....");
Console.ReadKey();
}
Imports Aspose.Pdf
Imports Aspose.Pdf.Text
Shared Sub Main(ByVal args() As String)
'create new document
Dim pdfDocument As New Document()
'add new page to document
Dim page As Page = pdfDocument.Pages.Add()
'source HTML string
Dim HtmlStr As String = "<h1 style='text-align:center'>Welcome To Aspose.PDF</h1><h2 style='text-align:center'>Page Content</h2>"
'create HTML fragment by source HTML string
Dim HtmlFrg As New HtmlFragment(HtmlStr)
'add HTML fragment as page paragraph
page.Paragraphs.Add(HtmlFrg)
'Watermark string
Dim WMStr As String = "Sample WaterMark"
'create TextStamp of above string
Dim textStamp As New TextStamp(WMStr)
'setting TextStamp properties
textStamp.HorizontalAlignment = HorizontalAlignment.Center
textStamp.VerticalAlignment = VerticalAlignment.Center
textStamp.RotateAngle = 45
textStamp.TextState.Font = FontRepository.FindFont("Times New Roman")
textStamp.TextState.FontSize = 15F
textStamp.TextState.FontStyle = FontStyles.Bold
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red)
'add to the specific page
pdfDocument.Pages(1).AddStamp(textStamp)
'save to the target location
pdfDocument.Save("sample.pdf")
Console.WriteLine("PDF File Successfully Created....")
Console.ReadKey()
End Sub
Output: And here is the screenshot of the stamped sample.pdf
file.
Read more about using Aspose PDF add stamp and watermark in your files and projects.
6.3. Difference between Aspose and IronPDF Watermarking
When talking about Watermarks on selected pages or multiple pages, there are no specified functions when using Aspose.PDF. But we can do it using page iteration of a PDF file with For Loop
, While Loop
, or ForEach Loop
etc. This does create bulky code and requires us to add different conditions if we want to add a Watermark only on select pages.
Licensing and Pricing
7. Compare License Options
As developers, we all want to complete our projects with minimal cost and resources, and budget can be espeically important. Review the chart to compare what license is right for your needs and budget.
IronPDF offers licenses with a customizable # of developers, projects, and locations so you can meet the needs of your project and pay only for the coverage you need. Check out the HTML to PDF licenses or contact the support team to get a custom quote and free 30 day deployment trial.

Summary
8. Aspose PDF and IronPDF Takeaways
IronPDF | Aspose.PDF |
---|---|
Works with PDF files programmatically. | Works with PDF files programmatically. |
Developed in .NET framework using C#. | Developed in .NET framework using C#. |
Supports Windows, Linux, and MacOS. | Supports Windows, Linux, and MacOS. |
Provides a generalized way to convert .aspx page to PDF file. | No generalized way to convert .aspx pages to PDF file. |
Provides predefined functions for Header and Footer. | No predefined functions for Header and Footer, need to use TextStamp . |
Can set Watermark styling properties Using HTML and CSS. | No support for HTML and CSS for TextStamp styling properties. |
Easily attach a Cover Page to a PDF with just a few lines of code. | Difficult to add a cover page to a PDF file. |
Affordable license pricing. | Expensive license pricing. |
More from Aspose
9. Aspose Components Overview
Aspose provides a range of components to suit your project needs. See the full list below and compare to other IronPDF products for competitive pricing and clear & condensed code functions.
Component | Supports | Usage | IronSoftware Comparison |
---|---|---|---|
Aspose.Words | .Net, Java, C++, Android via Java | Create, edit, convert & print Word files. | |
Aspose.PDF | .Net, Java, C++, Android via Java | Work with PDF files to generate, edit and manipulate the PDFs programmatically. | IronPDF |
Aspose.Cells | .Net, Java, C++, Android via Java, NodeJS via Java, PHP via Java, Python via Java | Create, edit, import, export and convert Excel files into many formats. | IronXL |
Aspose.Email | .Net, Java, C++, Android via Java, Python via .NET | Create, manipulate, convert and send Outlook Emails, and implement Network Protocols such as SMTP, POP3 & IMAP. | |
Aspose.Slides | .Net, .Net Core, Java, C++, Android via Java, Xamarin | Create, manage and convert PowerPoint Presentation and Slides. | |
Aspose.Imaging | .Net, Java | Draw, manipulate, convert, and transform images. | |
Aspose.BarCode | .Net, Java, C++, Android via Java, NodeJS via Java, PHP via Java | Create and scan any type of Barcodes e,g, 1D, 2D, and Postal. | IronBarCode |
Aspose.Diagram | .Net, Java, Node.JS via Java | Work with with Microsoft Visio files to create, edit and convert them on any platform. | |
Aspose.CAD | .Net, Java | Convert AutoCAD, DWG & DXF drawings to PDF & raster images. | |
Aspose.PSD | .Net, Java | Create, edit, convert Adobe Photoshop and Adobe Illustrator files programmatically. |
Tutorial Quick Access
Explore the IronPDF Object Reference
Explore the Object Reference for IronPDF C# Library, including details of all of IronPDF’s features, classes, method fields, namespaces, and enums.
View the Object Reference