- Home
- .NET code examples
- Create a PDF using HTML & CSS in ASP.NET Core
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.
C# coding challenges
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.
- Visual Studio 2019. Version 16.8.4 or above (may work with lower versions). It will work with the free community version.
- .NET 5.0 SDK, or above.
Get The Application Working
These are the steps to get the application working.
- Fill out the code example form. We will send you an email where you can download the code example.
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.