Create a PDF using HTML & CSS in ASP.NET Core

There are a number of Nuget packages that allow you to create a dynamic PDF document for free in ASP.NET Core.

PDF documents have the benefits of being secure, have a consistent layout and being able to be opened on all major operating systems.

Such uses for PDF documents on a website include sending out invoices to clients or customers.

In addition, they can also be used to capture the layout of a particular website.

In this code example, we go ahead and create an ASP.NET Core MVC application.

We use the Select.HtmlToPdf.NetCore Nuget package to create PDF's for this application.

There is an example of how to capture a particular website in both mobile, tablet and desktop view.

As well as that, there is an example of how to create an invoice in a web application.

Not only can these PDF documents be outputted to the HTTP response, they can also be saved on the server's file storage.

Software

This is the software that will need to be installed onto your machine.

Get The Application Working

These are the steps to get the application working.

You are now ready to go.

Open the Project in Visual Studio

Open up RoundTheCode.Pdf.sln in Visual Studio.

You should find that the web application runs on https://localhost:3000.

Start the project in Visual Studio.

Open up a browser and navigate to https://localhost:3000/pdf/website. This should generate a PDF document showing RoundTheCode.com layout in mobile, tablet and desktop. It should also save the PDF as RoundTheCode.pdf in the web directory.

Navigate to https://localhost:3000/pdf/invoice. This should generate a PDF document of an invoice. It should also save the PDF as Invoice.pdf in the web directory.

More Information

You can read more information by viewing our "How to Create a PDF Document for Free in ASP.NET Core" article.

In-addition, watch our video tutorial, where we go ahead and create PDF documents using HTML and CSS.

Join our Discord Server

  • Can't get your ASP.NET Core application to work? Ask for help here!
  • Discussions with other ASP.NET Core developers.
  • General chat with the community.
Join