Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Adobe created the Portable Document Format (PDF) in 1992 to enable the distribution of documents, including text formatting and graphics, in a way that is independent of application software, hardware, and operating systems. Each PostScript-based PDF file contains the text, fonts, vector graphics, raster images, and other components required to show a fixed-layout flat page. In this article, we are comparing Puppeteer and IronPDF.
The well-known Puppeteer library, which is used for headless Chrome automation, has been ported to C# and is called Puppeteer Sharp. The best of Puppeteer is brought to .NET (or .NET Core) through Puppeteer Sharp. Puppeteer is capable of many things, including creating PDF files from HTML. Puppeteer Sharp is a .NET port of the Node library of the official Puppeteer.
Since they can be viewed on any device and cannot be changed, PDFs make excellent sharing formats for documents. They are therefore perfect for papers like packing slips, invoices, and other types of paperwork where you don't want the recipient to be able to make modifications.
HTML templates are a wonderful technique to create PDFs since they make it simple to manage the document's layout. Additionally, adopting a template guarantees that your PDF will always look consistent, despite changes to the data. The minimum platform versions are .NET Core 2.0 and .NET Framework 4.6.1.
IronPDF is a powerful PDF library for PDF processing that enables developers to quickly produce, read, and edit PDF documents. The IronPDF library converts HTML to PDF using the Chrome engine. The library supports Xamarin, Blazor, Unity, HoloLens apps, Windows Forms, HTML, ASPX, Razor HTML, NET Core, ASP.NET, and WPF among other web components. Both classic Windows applications and ASP.NET web apps can use Microsoft.NET and.NET Core programming.
IronPDF is a stand-alone PDF processing component. IronPDF helps you to produce visually appealing PDFs with a title and footer by fusing HTML5, JavaScript, CSS, and pictures. The API library comes with a strong HTML-to-PDF converter that works with PDF files, as well as a stand-alone PDF conversion engine that is not dependent on any external resources.
Go to the File menu in Visual Studio after starting it up. After choosing "new project," choose "console application." In this article, we'll create PDF documents using a console application.
Select the file path and enter the project name in the relevant text box. As seen in the screenshot below, select the necessary Dot Net Framework after clicking the Create button.
The selected application's structure will now be generated by the Visual Studio project, and if you choose a console, Windows, or web application, the program.cs file will be opened so you can add the code and build/run the application.
Next, we can add the library to test the code.
We can accomplish this by including the Puppeteer Sharp NuGet package in your project. The Puppeteer Library can be downloaded and set up in four different ways.
Which are:
The NuGet Package Manager can be accessed as seen in the following screenshot.
The search box is available, and it displays a list of packages from the NuGet website. As shown in the screenshot below, you will need to search for "Puppeteer" in the package manager.
The list of relevant search items is shown in the image above. To install the package to the solution, we must choose the necessary option.
The following line into the terminal tab of the package manager:
Install-Package PuppeteerSharp or dotnet add package PuppeteerSharp
The package is now downloading/installing to the active project and is prepared for use.
The NuGet package can be downloaded directly from the website as a third option.
To download the most recent package directly from the website, click this link. To add the package to the project after downloading, adhere to the instructions listed below.
There are four ways to download and set up the IronPDF Library.
Which are:
The NuGet Package management feature of the Visual Studio software allows you to install a package right into a solution. How to launch the NuGet Package Manager is demonstrated in the screenshot below.
To display a list of packages from the NuGet website, a search box is available. As shown in the screenshot below, search for "IronPDF" in the package manager.
The list of relevant search items is displayed in the above graphic. For the package to be installed on the solution, we must make the necessary choice.
Navigate to Tools > NuGet Package Manager > Package Manager in Visual Studio.
The following line into the terminal tab of the package manager:
Install-Package IronPDF or dotnet add package IronPdf
The third option is to directly download the NuGet package from the website.
For a direct internet download of the latest version, click this link. To add the package to the project after downloading, follow these steps.
Both PDF libraries enable us to create attractive PDFs from HTML pages. Let's examine how to create a PDF document.
PDF can be easily created with the help of the Puppeteer Sharp. Below is a simple example of how to create a PDF using Puppeteer.
static async Task Main(string[] args)
{
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath=""// Enter you brower exe path here.
}))
{
using (var page = await browser.NewPageAsync())
{
await page.GoToAsync("http://www.google.com");
await page.EvaluateExpressionHandleAsync("document.fonts.ready");
await page.PdfAsync(outputFile);
}
}
}
static async Task Main(string[] args)
{
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath=""// Enter you brower exe path here.
}))
{
using (var page = await browser.NewPageAsync())
{
await page.GoToAsync("http://www.google.com");
await page.EvaluateExpressionHandleAsync("document.fonts.ready");
await page.PdfAsync(outputFile);
}
}
}
Shared Async Function Main(ByVal args() As String) As Task
Using browser = Await Puppeteer.LaunchAsync(New LaunchOptions With {
.Headless = True,
.ExecutablePath=""
})
Using page = Await browser.NewPageAsync()
Await page.GoToAsync("http://www.google.com")
Await page.EvaluateExpressionHandleAsync("document.fonts.ready")
Await page.PdfAsync(outputFile)
End Using
End Using
End Function
Next, we employ the PuppeteerSharp
. A new headless Chrome instance can be started with the LaunchAsync
method. The async
keyword is being used here so that we can anticipate the async
methods that PuppeteerSharp
offers. It has two parameter one is the Headless which is A web browser without a graphical user interface is known as a "headless browser." it is set as true in the given example. Another parameter is Executablepath
of the browser which is available.
Once we have a new page, we use the GoToAsync
function to set the content of the page to our HTML from the given URL. To check whether the page font loading has been completed where are using a function called EvaluateExpressionHandleAsync
. In order to create the PDF and save it to the Demopuppetteer.pdf file, we are finally using the PdfAsync
function. Which will generate PDF documents and save them in the given location.
We can easily create a PDF document with IronPDF. From a URL, it will produce an HTML file and convert it to a PDF file. IronPDF's built-in Chrome browser will help us get the HTML string.
PDF documents are simple to create with the next few steps.
class program
{
var url="https://www.google.co.in/";
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
var Pdf = Renderer.RenderUrlAsPdf(url);
Pdf.SaveAs("result.pdf");
or
var Renderer = new IronPdf.ChromePdfRenderer().
RenderUrlAsPdf(url).SaveAs("result.pdf");
}
class program
{
var url="https://www.google.co.in/";
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
var Pdf = Renderer.RenderUrlAsPdf(url);
Pdf.SaveAs("result.pdf");
or
var Renderer = new IronPdf.ChromePdfRenderer().
RenderUrlAsPdf(url).SaveAs("result.pdf");
}
Friend Class program
Private url ="https://www.google.co.in/"
Private Renderer As New IronPdf.ChromePdfRenderer()
Private Pdf = Renderer.RenderUrlAsPdf(url)
Pdf.SaveAs("result.pdf")
[or] var Renderer = (New IronPdf.ChromePdfRenderer()).RenderUrlAsPdf(url).SaveAs("result.pdf")
End Class
In the aforementioned example, there are two possibilities for turning the link into a document. One way to create a document is by making an IronPDF object, and another way is to create a RenderUrlAsPdf
object.
The aforementioned suggests that we can use RenderUrlAsPdf
to convert it into a document. All that has to be provided in the URL that will generate PDF files.
Both IronPDF and Puppeteer can convert existing HTML pages or HTML code to PDF. They will help us create excellent PDF documents.
The puppeteer library can be used to turn an HTML string into a PDF file. It is easy to use and understand.
Below is an example of an HTML string to PDF conversion code.
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath=""// Enter you brower exe path here.
}))
{
using (var page = await browser.NewPageAsync())
{
await page.SetContentAsync("<h2>Hello world</h2>");
await page.PdfAsync(outputFile);
}
}
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath=""// Enter you brower exe path here.
}))
{
using (var page = await browser.NewPageAsync())
{
await page.SetContentAsync("<h2>Hello world</h2>");
await page.PdfAsync(outputFile);
}
}
Using browser = Await Puppeteer.LaunchAsync(New LaunchOptions With {
.Headless = True,
.ExecutablePath=""
})
Using page = Await browser.NewPageAsync()
Await page.SetContentAsync("<h2>Hello world</h2>")
Await page.PdfAsync(outputFile)
End Using
End Using
We utilize the SetContentAsync
function to set the content of the page to our HTML once we have a new document page like the one seen above. Finally, we are using the PdfAsync
function to generate the PDF and store it in the Demopuppetteer.pdf file. This will create PDFs and store them in the place specified.
With the aid of IronPDF, we can convert HTML strings into PDF documents. Here is an illustration of how to convert an HTML string into a document. Additionally, it can transform any HTML tag into a PDF file.
var Renderer = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello world!!</h1>").SaveAs("Demo.pdf");
var Renderer = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello world!!</h1>").SaveAs("Demo.pdf");
Dim Renderer = (New IronPdf.ChromePdfRenderer()).RenderHtmlAsPdf("<h1>Hello world!!</h1>").SaveAs("Demo.pdf")
The sample that comes with it demonstrates how to translate an HTML string using RenderHtmlAsPdf
. Furthermore, the function that turns HTML into a string can accept any quantity of HTML codes. We can save the document after retrieving the string by using the save as function. Just two seconds are needed to finish the operation.
To know more about the HTML to PDF conventions refer to the link here.
In conclusion, due to IronPDF's outstanding functionality and the abundance of features made available to developers working with PDFs, we highly recommend it. Additionally, it offers first-rate support and documentation, enabling us to make the most of all of IronPDF's features. Puppeteer has few settings and little supporting documentation.
IronPDF supports the creation, reading, editing, and formatting of PDF documents. A given URL can be converted into a PDF file using IronPDF's browser engine. Additionally, it enables the creation of PDF documents from HTML strings that have CSS added to them. The IronPDF library also allows us to fill out PDF forms. One library contains all of IronPDF's functionality.
With Puppeteer, we can create PDF files. Additionally, we have the ability to transform HTML or URL strings into PDF documents. We are able to include CSS in the HTML string. However, to access a particular functionality, we must download a specific library.
Developers can explore IronPDF's features for themselves with its free trial. The IronPDF license comes with various price structures. The basic price for IronPDF starts at $749. There is a one-year fee for product support and updates. IronPDF provides royalty-free redistribution coverage for an extra cost. The Puppeteer PDF Library is an open-source library.
9 .NET API products for your office documents