Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
The Portable Document Format (PDF) is the most popular document format for representing text, links, buttons, graphics, and much more in a single document. Manipulating PDFs in the C# programming language is near impossible without using a PDF API for C#. In this article, we will explore how to interact with and manipulate PDF documents using two different APIs, and also compare both APIs on their performance, features, and licensing.
The PDF APIs we will discuss in this article are:
IronPDF is a powerful HTML-to-PDF conversion API. IronPDF is the ideal solution for converting HTML sites in .NET and .NET Core development. It not only transforms HTML, but also has a variety of additional functions. IronPDF allows developers to create, alter, and retrieve PDF documents in .NET Core and .NET Framework projects. Using the IronPDF package, developers may easily produce or change PDFs from HTML pages.
A PDF can be easily edited, stamped, and headers and footers added. It also makes it incredibly easy to read PDF text and extract pictures. IronPDF uses a .NET Chromium engine to render HTML pages to PDF files.
This feature includes PDF creations from different formats such as HTML, HTML Strings, MVC views, Web Forms, and URLs.
This allows users to create images from PDFs and to create PDFs from images. It includes image extraction, support for different image extensions, and PDF printing.
IronPDF also provides features for 128-bit encryption, locking with passwords, and digitally signing.
This feature of IronPDF provides all types of PDF formatting, such as adding watermarks, adding pages, removing pages, adding backgrounds, adding foregrounds, and much more. In short, IronPDF provides all the capabilities you need for manipulating PDFs.
In many cases, you can extract embedded text from PDFs directly. If that doesn't work, your text is probably actually embedded in an image. Use the IronOCR library to scan documents for visual text, not plain text.
Headers and footers can be added when a PDF is created or added to existing PDFs. The Print Options property allows you to craft a header and footer for each document page. Access these options on the Chrome PDF Renderer object. This sample works inside a .NET Core console app.
IronPDF supports almost all operating systems and frameworks compatible with C#, including the following:
PDFShift is an HTML-to-PDF conversion API tool that enables organizations to convert HTML pages to PDF in a matter of seconds. Parallel conversions, asynchronous queries, raw HTML support, and other capabilities are available through the cloud-server-based API tool. PDFShift is a simple-to-use solution that supports a wide range of developer languages, including Ruby, Python, JavaScript, Node, and PHP to make the conversion process easier.
PDFShift allows customers to establish custom headers and footers, apply custom CSS, encrypt files, and much more to give enterprises complete control over their conversions.
PDFShift supports parallel conversions, allowing users to convert multiple documents at once to increase conversion speed.
Create custom headers and footers with page numbers, use custom CSS and JavaScript, encrypt your documents, and more.
PDFShift supports raw HTML-to-PDF conversion without making pages public.
PDFShift converts HTML to high-fidelity PDF documents in a matter of seconds.
To be alerted when a conversion is complete, use our sophisticated real-time system. Use the powerful PDFShift API to convert HTML to PDF and integrate the system with only three lines of code.
Open the Visual Studio software and go to the File menu. Select "new project" and then select a console application. In this article, we are going to use a console application to generate PDF documents.
Enter the project name and select the path in the appropriate text box. Then, click the create button. Select the required .NET framework, as in the screenshot below:
The Visual Studio project will now generate the structure for the selected application, and if you have selected the console, Windows, and web application, it will open the program.cs file where you can enter the code and build/run the application.
Now we can add the library and test the program.
The IronPDF library can be downloaded and installed in four different ways. These are:
The Visual Studio software provides the NuGet Package Manager option to install the package directly to the solution. The below screenshot shows how to open the NuGet Package Manager.
It provides a search box to show the list of available package libraries from the NuGet website. In the package manager, we need to search for the keyword "IronPDF," as in the below screenshot
In the above image, we can see the list of related packages from the search. We need to select the IronPDF option and install the package to our solution.
In the Visual Studio menu, Go to Tools > NuGet Package manager > Package manager console
Enter the following line in the package manager console tab:
Install-Package IronPdf
Now the package will download/install to the current project and be ready to use.
The third way is to download the NuGet package directly from the webpage.
Download the latest package directly from the IronPDF Download Page. After the download, follow the steps below to add the package to the project.
PDFShift can't be integrated into a project — instead, it works remotely. You need to submit a POST request to PDFShift's API using the C# RestClient package by simply giving your API key as the user argument of simple authentication. The server receives your request, processes it, and gives back the output file all, and the working on the PDF conversion API is done by HTTP post request. PDFShift offers an API in many languages and works remotely for all of them.
Both tools include this functionality for HTML conversion, although they do so in somewhat different ways.
Creating a PDF file in C# using a URL is just as easy as the above example with just these three lines of code. The following code will demonstrate how to create PDF files from a URL.
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
// Create a PDF from a URL or local file path
using var pdf = Renderer.RenderUrlAsPdf("https://www.amazon.com/?tag=hp2-brobookmark-us-20");
// Export to a file or Stream
pdf.SaveAs("url.pdf");
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
// Create a PDF from a URL or local file path
using var pdf = Renderer.RenderUrlAsPdf("https://www.amazon.com/?tag=hp2-brobookmark-us-20");
// Export to a file or Stream
pdf.SaveAs("url.pdf");
Imports IronPdf
Private Renderer = New IronPdf.ChromePdfRenderer()
' Create a PDF from a URL or local file path
Private pdf = Renderer.RenderUrlAsPdf("https://www.amazon.com/?tag=hp2-brobookmark-us-20")
' Export to a file or Stream
pdf.SaveAs("url.pdf")
Here is the output of the above code.
It's quite easy to convert HTML to PDF using the IronPDF C# .NET library.
var pdf = new ChromePdfRenderer();
PdfDocument doc = pdf.RenderHtmlAsPdf("<h1>This is a heading</h1>");
mypdf.SaveAs("FirstPDFDocument.pdf");
var pdf = new ChromePdfRenderer();
PdfDocument doc = pdf.RenderHtmlAsPdf("<h1>This is a heading</h1>");
mypdf.SaveAs("FirstPDFDocument.pdf");
Dim pdf = New ChromePdfRenderer()
Dim doc As PdfDocument = pdf.RenderHtmlAsPdf("<h1>This is a heading</h1>")
mypdf.SaveAs("FirstPDFDocument.pdf")
Converting a URL with PDFShift is very easy. All you have to do is send a POST request with the source parameter set to the URL, as with the following:
using System;
using RestSharp;
using Newtonsoft.Json;
using System.IO;
using RestSharp.Authenticators;
using RestSharp.Serialization;
using System.Net.Mail;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace PDFShiftExample
{
class Program
{
static void Main(string [] args)
{
IRestClient client = new RestClient("https://api.pdfshift.io/v3/convert/pdf");
client.Authenticator = new HttpBasicAuthenticator("api", "your_api_key");
IRestRequest request = new RestRequest(Method.POST);
var json = new
{
source = "https://www.example.com"
};
request.AddJsonBody(json);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
{
// Check why status is not int 2xx.
}
else
{
File.WriteAllBytes("result.pdf", response.RawBytes);
}
}
}
}
using System;
using RestSharp;
using Newtonsoft.Json;
using System.IO;
using RestSharp.Authenticators;
using RestSharp.Serialization;
using System.Net.Mail;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace PDFShiftExample
{
class Program
{
static void Main(string [] args)
{
IRestClient client = new RestClient("https://api.pdfshift.io/v3/convert/pdf");
client.Authenticator = new HttpBasicAuthenticator("api", "your_api_key");
IRestRequest request = new RestRequest(Method.POST);
var json = new
{
source = "https://www.example.com"
};
request.AddJsonBody(json);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
{
// Check why status is not int 2xx.
}
else
{
File.WriteAllBytes("result.pdf", response.RawBytes);
}
}
}
}
Imports System
Imports RestSharp
Imports Newtonsoft.Json
Imports System.IO
Imports RestSharp.Authenticators
Imports RestSharp.Serialization
Imports System.Net.Mail
Imports System.Net
Imports System.Collections.Generic
Imports Newtonsoft.Json.Linq
Namespace PDFShiftExample
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim client As IRestClient = New RestClient("https://api.pdfshift.io/v3/convert/pdf")
client.Authenticator = New HttpBasicAuthenticator("api", "your_api_key")
Dim request As IRestRequest = New RestRequest(Method.POST)
Dim json = New With {Key .source = "https://www.example.com"}
request.AddJsonBody(json)
Dim response As IRestResponse = client.Execute(request)
If Not response.IsSuccessful Then
' Check why status is not int 2xx.
Else
File.WriteAllBytes("result.pdf", response.RawBytes)
End If
End Sub
End Class
End Namespace
PDFShift also provides HTML-to-PDF direct conversion, but reads HTML content from HTML files.
namespace PDFShiftExample
{
class Program
{
static void Main(string [] args)
{
IRestClient client = new RestClient("https://api.pdfshift.io/v3/convert/pdf");
client.Authenticator = new HttpBasicAuthenticator("api", "your_api_key");
IRestRequest request = new RestRequest(Method.POST);
string documentContent = File.ReadAllText("document.html");
var json = new
{
source = documentContent
};
request.AddJsonBody(json);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
{
// Check why status is not int 2xx.
}
else
{
File.WriteAllBytes("result.pdf", response.RawBytes);
}
}
}
}
namespace PDFShiftExample
{
class Program
{
static void Main(string [] args)
{
IRestClient client = new RestClient("https://api.pdfshift.io/v3/convert/pdf");
client.Authenticator = new HttpBasicAuthenticator("api", "your_api_key");
IRestRequest request = new RestRequest(Method.POST);
string documentContent = File.ReadAllText("document.html");
var json = new
{
source = documentContent
};
request.AddJsonBody(json);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
{
// Check why status is not int 2xx.
}
else
{
File.WriteAllBytes("result.pdf", response.RawBytes);
}
}
}
}
Namespace PDFShiftExample
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim client As IRestClient = New RestClient("https://api.pdfshift.io/v3/convert/pdf")
client.Authenticator = New HttpBasicAuthenticator("api", "your_api_key")
Dim request As IRestRequest = New RestRequest(Method.POST)
Dim documentContent As String = File.ReadAllText("document.html")
Dim json = New With {Key .source = documentContent}
request.AddJsonBody(json)
Dim response As IRestResponse = client.Execute(request)
If Not response.IsSuccessful Then
' Check why status is not int 2xx.
Else
File.WriteAllBytes("result.pdf", response.RawBytes)
End If
End Sub
End Class
End Namespace
Adding headers and footers to PDFs is a must-have when dealing with PDFs. Both the tools under discussion support this option.
Using IronPDF you can add headers and footers in two distinct ways.
TextHeaderFooter allows text-based headers to be added, with the option to merge in dynamic data.
HtmlHeaderFooter allows the developer to render HTML headers and footers to PDF files, also allowing the templating of dynamic data. It is more flexible but harder to use.
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a coverpage will be appended
Renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
Renderer.RenderingOptions.TextHeader.CenterText = "{url}";
Renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
Renderer.RenderingOptions.TextHeader.FontSize = 12;
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a coverpage will be appended
Renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
Renderer.RenderingOptions.TextHeader.CenterText = "{url}";
Renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
Renderer.RenderingOptions.TextHeader.FontSize = 12;
Imports IronPdf
Private Renderer = New IronPdf.ChromePdfRenderer()
Renderer.RenderingOptions.FirstPageNumber = 1 ' use 2 if a coverpage will be appended
Renderer.RenderingOptions.TextHeader.DrawDividerLine = True
Renderer.RenderingOptions.TextHeader.CenterText = "{url}"
Renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica
Renderer.RenderingOptions.TextHeader.FontSize = 12
You can customize the resulting document by adding a custom header or footer. These are frequently used to identify the current page or display your company's logo on every page.
using System;
using RestSharp;
using Newtonsoft.Json;
using System.IO;
using RestSharp.Authenticators;
using RestSharp.Serialization;
using System.Net.Mail;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace PDFShiftExample
{
class Program
{
static void Main(string [] args)
{
IRestClient client = new RestClient("https://api.pdfshift.io/v3/convert/pdf");
client.Authenticator = new HttpBasicAuthenticator("api", "your_api_key");
IRestRequest request = new RestRequest(Method.POST);
var json = new
{
source = "https://quillbot.com/",
footer = new { source = "<div style=\"font-size: 12px\">Page {{page}} of {{total}}</div>", spacing = "50px" }
};
request.AddJsonBody(json);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
{
// Check why status is not int 2xx.
}
else
{
File.WriteAllBytes("result.pdf", response.RawBytes);
}
}
}
}
using System;
using RestSharp;
using Newtonsoft.Json;
using System.IO;
using RestSharp.Authenticators;
using RestSharp.Serialization;
using System.Net.Mail;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace PDFShiftExample
{
class Program
{
static void Main(string [] args)
{
IRestClient client = new RestClient("https://api.pdfshift.io/v3/convert/pdf");
client.Authenticator = new HttpBasicAuthenticator("api", "your_api_key");
IRestRequest request = new RestRequest(Method.POST);
var json = new
{
source = "https://quillbot.com/",
footer = new { source = "<div style=\"font-size: 12px\">Page {{page}} of {{total}}</div>", spacing = "50px" }
};
request.AddJsonBody(json);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
{
// Check why status is not int 2xx.
}
else
{
File.WriteAllBytes("result.pdf", response.RawBytes);
}
}
}
}
Imports System
Imports RestSharp
Imports Newtonsoft.Json
Imports System.IO
Imports RestSharp.Authenticators
Imports RestSharp.Serialization
Imports System.Net.Mail
Imports System.Net
Imports System.Collections.Generic
Imports Newtonsoft.Json.Linq
Namespace PDFShiftExample
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim client As IRestClient = New RestClient("https://api.pdfshift.io/v3/convert/pdf")
client.Authenticator = New HttpBasicAuthenticator("api", "your_api_key")
Dim request As IRestRequest = New RestRequest(Method.POST)
Dim json = New With {
Key .source = "https://quillbot.com/",
Key .footer = New With {
Key .source = "<div style=""font-size: 12px"">Page {{page}} of {{total}}</div>",
Key .spacing = "50px"
}
}
request.AddJsonBody(json)
Dim response As IRestResponse = client.Execute(request)
If Not response.IsSuccessful Then
' Check why status is not int 2xx.
Else
File.WriteAllBytes("result.pdf", response.RawBytes)
End If
End Sub
End Class
End Namespace
Watermarking PDFs using a programming language is quite a difficult task. Both IronPDF and PDFShift provide support for watermarking PDFs.
IronPDF provides methods to 'watermark' PDF documents with HTML. Watermarks may be set to render above or below existing content and have a built-in capacity for opacity, rotation, and hyperlinks.
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
using var Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
Pdf.WatermarkAllPages("<h2 style='color:red'>SAMPLE</h2>", IronPdf.Editing.WaterMarkLocation.MiddleCenter, 50, -45, "https://www.nuget.org/packages/IronPdf");
Pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
using var Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
Pdf.WatermarkAllPages("<h2 style='color:red'>SAMPLE</h2>", IronPdf.Editing.WaterMarkLocation.MiddleCenter, 50, -45, "https://www.nuget.org/packages/IronPdf");
Pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
Imports IronPdf
Private Renderer = New IronPdf.ChromePdfRenderer()
Private Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
Pdf.WatermarkAllPages("<h2 style='color:red'>SAMPLE</h2>", IronPdf.Editing.WaterMarkLocation.MiddleCenter, 50, -45, "https://www.nuget.org/packages/IronPdf")
Pdf.SaveAs("C:\Path\To\Watermarked.pdf")
Users need a watermark to clearly identify on PDFs.
using System;
using RestSharp;
using Newtonsoft.Json;
using System.IO;
using RestSharp.Authenticators;
using RestSharp.Serialization;
using System.Net.Mail;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace PDFShiftExample
{
class Program
{
static void Main(string [] args)
{
IRestClient client = new RestClient("https://api.pdfshift.io/v3/convert/pdf");
client.Authenticator = new HttpBasicAuthenticator("api", "your_api_key");
IRestRequest request = new RestRequest(Method.POST);
var json = new
{
source = "https://www.example.com",
watermark = new { image = "https://pdfshift-dev.netlify.com/images/logo/logo-violet.png", offset_x = 50, offset_y = "100px", rotate = 45 }
};
request.AddJsonBody(json);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
{
// Check why status is not int 2xx.
}
else
{
File.WriteAllBytes("result.pdf", response.RawBytes);
}
}
}
}
using System;
using RestSharp;
using Newtonsoft.Json;
using System.IO;
using RestSharp.Authenticators;
using RestSharp.Serialization;
using System.Net.Mail;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace PDFShiftExample
{
class Program
{
static void Main(string [] args)
{
IRestClient client = new RestClient("https://api.pdfshift.io/v3/convert/pdf");
client.Authenticator = new HttpBasicAuthenticator("api", "your_api_key");
IRestRequest request = new RestRequest(Method.POST);
var json = new
{
source = "https://www.example.com",
watermark = new { image = "https://pdfshift-dev.netlify.com/images/logo/logo-violet.png", offset_x = 50, offset_y = "100px", rotate = 45 }
};
request.AddJsonBody(json);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
{
// Check why status is not int 2xx.
}
else
{
File.WriteAllBytes("result.pdf", response.RawBytes);
}
}
}
}
Imports System
Imports RestSharp
Imports Newtonsoft.Json
Imports System.IO
Imports RestSharp.Authenticators
Imports RestSharp.Serialization
Imports System.Net.Mail
Imports System.Net
Imports System.Collections.Generic
Imports Newtonsoft.Json.Linq
Namespace PDFShiftExample
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim client As IRestClient = New RestClient("https://api.pdfshift.io/v3/convert/pdf")
client.Authenticator = New HttpBasicAuthenticator("api", "your_api_key")
Dim request As IRestRequest = New RestRequest(Method.POST)
Dim json = New With {
Key .source = "https://www.example.com",
Key .watermark = New With {
Key .image = "https://pdfshift-dev.netlify.com/images/logo/logo-violet.png",
Key .offset_x = 50,
Key .offset_y = "100px",
Key .rotate = 45
}
}
request.AddJsonBody(json)
Dim response As IRestResponse = client.Execute(request)
If Not response.IsSuccessful Then
' Check why status is not int 2xx.
Else
File.WriteAllBytes("result.pdf", response.RawBytes)
End If
End Sub
End Class
End Namespace
IronPDF is a library that offers a free developer license. IronPDF also offers a special price structure: the light package begins at \$liteLicense
, with no hidden costs. It is also possible to redistribute SaaS and OEM products. All licenses include a 30-day money-back guarantee, a year of software support and upgrades, development/testing/staging/production validity, and a perpetual license (one-time purchase). IronPDF licenses provide maximal performance for user needs. Go to this link to see IronPDF's Entire Pricing Structure and Licensing.
The PDFShift PDF conversion API offers five different licensing packages on both a monthly and yearly basis. A system of "credits" is used for purchasing the various packages, and the details of this are listed as follows:
There are also file size limits: the free package has a limit of 1MB per file, while for the other packages the limit is 5MB per file.
For more information and pricing, visit the PDFShift Pricing Page.
IronPDF is a free application for indie developers that provides a variety of features and the capability to modify PDF files and convert them to other formats. IronPDF provides the best editing and formatting tools for PDF processing. It converts HTML-to-PDF results into a vector file suitable for high-quality commercial printing. As an outcome, you'll get a PDF that is clear and high-quality. For more details, check the Iron Software Licensing and Pricing Information.
PDFShift is an HTML-to-PDF conversion API that is high-quality, high-fidelity, and powerful. It offers an easy-to-learn endpoint with an array of tools approaching a complete set of functions, as well as a package for several languages. PDFShift uses postMessage to send requests to the server that can handle the parallel conversion of documents — meaning that you can convert multiple documents at the same time.
IronPDF licenses are developer-based, which means you should always purchase a license based on the number of developers who will use the product. PDFShift licenses, on the other hand, are monthly and yearly credits-based, which means you will receive specific credits per month based on your subscribed package. IronPDF supports OME and SaaS distribution, which PDFShift does not. IronPDF licenses are one-time purchases and you can use them for a lifetime, whereas PDFShift offers monthly and yearly licenses.
After a quick comparison of both tools, we can conclude that the IronPDF library offers substantially more features than PDFShift. PDFShift provides only a small number of features for manipulating PDFs. IronPDF converts URLs to PDF with just three lines of code, but PDFShift needs many more lines of code to be able to perform the same task. Integrating IronPDF is easy and can be done in only a few minutes. PDFShift works in a cloud-based system and does not need to be integrated; however, it does depend on other APIs such as Rest Sharp, and so, in fact, it is a complex procedure.
Further, Iron Software is currently offering a five-tool package for the price of just two. The tools included in the Iron Suite are:
Please visit this IronSuite Page to explore the IRONSUITE.
9 .NET API products for your office documents