Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
.NET Core, an open-source, cross-platform framework developed by Microsoft, has been gaining popularity for its flexibility, performance, and support for cloud-based applications. However, when it comes to working with PDF files, particularly for tasks like printing PDF documents, developers require a robust and feature-rich PDF library. This is where IronPDF helps the developers.
IronPDF is a comprehensive library designed for the .NET framework, including .NET Core and ASP.NET Core, which simplifies the process of working with PDF documents. It not only allows for the creation and manipulation of PDF files but also provides a seamless way to print these documents, whether it’s directly to a printer or by converting them to formats suitable for print.
In this tutorial, we will delve into the capabilities of IronPDF within a .NET Core environment. From setting up your project and creating your first PDF document to configuring print settings and implementing advanced printing features, we will guide you through each step. This tutorial aims to equip you with the knowledge and tools necessary to handle printing PDF files in your .NET Core applications efficiently.
To start working with PDFs in your .NET application, the first step is to integrate the IronPDF library. IronPDF is a powerful and versatile library that enables .NET developers to create, edit, and, most importantly, print PDF documents with ease. Let’s walk through the installation process:
Creating Your .NET Core Project: Open Visual Studio and select "Create a new project." In the project template selection window, filter by "Web" under "All platforms" and select "ASP.NET Core Web App."
Installing IronPDF: Go to the "NuGet Package Manager" and search for "IronPDF" to install it into your project. Ensure that the IronPDF library is correctly installed and referenced in your project files. You need to include the appropriate using
statements in your code, such as using IronPdf;
To create a PDF document using IronPDF in an ASP.NET Core web application, you will begin by adding some code to one of your controllers. Here's a simple example to get you started:
Create a new controller in your project, which will be responsible for handling PDF creation requests. You can name it PdfController
, for instance.
Inside your new controller, write an action method named CreatePdf
that returns a PDF file as a result.
using IronPdf;
using Microsoft.AspNetCore.Mvc;
namespace YourProjectName.Controllers
{
public class PdfController : Controller
{
// Action method for creating a PDF document
public IActionResult CreatePdf()
{
// Create a new PDF document from HTML content
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>This is a simple PDF document created in an ASP.NET Core web app.</p>");
// Save the generated PDF to the server's memory
var content = pdf.Stream.ToArray();
// Return the PDF to the browser as a downloadable file
return File(content, "application/pdf", "MyFirstPdf.pdf");
}
}
}
using IronPdf;
using Microsoft.AspNetCore.Mvc;
namespace YourProjectName.Controllers
{
public class PdfController : Controller
{
// Action method for creating a PDF document
public IActionResult CreatePdf()
{
// Create a new PDF document from HTML content
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>This is a simple PDF document created in an ASP.NET Core web app.</p>");
// Save the generated PDF to the server's memory
var content = pdf.Stream.ToArray();
// Return the PDF to the browser as a downloadable file
return File(content, "application/pdf", "MyFirstPdf.pdf");
}
}
}
Imports IronPdf
Imports Microsoft.AspNetCore.Mvc
Namespace YourProjectName.Controllers
Public Class PdfController
Inherits Controller
' Action method for creating a PDF document
Public Function CreatePdf() As IActionResult
' Create a new PDF document from HTML content
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>This is a simple PDF document created in an ASP.NET Core web app.</p>")
' Save the generated PDF to the server's memory
Dim content = pdf.Stream.ToArray()
' Return the PDF to the browser as a downloadable file
Return File(content, "application/pdf", "MyFirstPdf.pdf")
End Function
End Class
End Namespace
Start your application and navigate to the CreatePdf
action in your PdfController
. For example, if your application is running on localhost
with port 5000
, go to http://localhost:<Your-Port>/Pdf/CreatePdf
in your web browser.
Upon accessing the URL, the PDF document will be generated and downloaded through your web browser. To view the generated PDF, you will need a PDF viewer installed on your computer.
Once you've mastered the creation of PDF documents within your ASP.NET Core Web App, the next step is to implement printing functionality. IronPDF provides a straightforward way to print a PDF document inside your project, to a printer accessible by the server on which your application is running.
To print a PDF document, you will need to configure the printer settings within your application. IronPDF allows you to specify the printer by its name, which can be a locally installed printer or a network printer. Additionally, you can define other settings such as the paper source or orientation.
Here's an example method within your PdfController
class program that configures the printer settings and initiates the print job:
using IronPdf;
using Microsoft.AspNetCore.Mvc;
namespace YourProjectName.Controllers
{
public class PdfController : Controller
{
// Action method for printing a PDF document
public IActionResult PrintPdf()
{
// HTML string to be converted to PDF
var htmlContent = "<h1>Invoice</h1><p>Thank you for your business!</p>";
// Render the HTML content to a PDF in memory
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Get the print document from the PDF
var printDoc = pdf.GetPrintDocument();
// Set the printer name (replace with your printer's actual name)
printDoc.PrinterSettings.PrinterName = "Your Printer Name";
// Optional: Configure additional printer settings
// e.g., printDoc.PrinterSettings.Copies = 2;
// e.g., printDoc.DefaultPageSettings.Landscape = true;
// Send the document to the printer
printDoc.Print();
// Return a confirmation response to the client
return Content("The document has been sent to the printer.");
}
}
}
using IronPdf;
using Microsoft.AspNetCore.Mvc;
namespace YourProjectName.Controllers
{
public class PdfController : Controller
{
// Action method for printing a PDF document
public IActionResult PrintPdf()
{
// HTML string to be converted to PDF
var htmlContent = "<h1>Invoice</h1><p>Thank you for your business!</p>";
// Render the HTML content to a PDF in memory
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Get the print document from the PDF
var printDoc = pdf.GetPrintDocument();
// Set the printer name (replace with your printer's actual name)
printDoc.PrinterSettings.PrinterName = "Your Printer Name";
// Optional: Configure additional printer settings
// e.g., printDoc.PrinterSettings.Copies = 2;
// e.g., printDoc.DefaultPageSettings.Landscape = true;
// Send the document to the printer
printDoc.Print();
// Return a confirmation response to the client
return Content("The document has been sent to the printer.");
}
}
}
Imports IronPdf
Imports Microsoft.AspNetCore.Mvc
Namespace YourProjectName.Controllers
Public Class PdfController
Inherits Controller
' Action method for printing a PDF document
Public Function PrintPdf() As IActionResult
' HTML string to be converted to PDF
Dim htmlContent = "<h1>Invoice</h1><p>Thank you for your business!</p>"
' Render the HTML content to a PDF in memory
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
' Get the print document from the PDF
Dim printDoc = pdf.GetPrintDocument()
' Set the printer name (replace with your printer's actual name)
printDoc.PrinterSettings.PrinterName = "Your Printer Name"
' Optional: Configure additional printer settings
' e.g., printDoc.PrinterSettings.Copies = 2;
' e.g., printDoc.DefaultPageSettings.Landscape = true;
' Send the document to the printer
printDoc.Print()
' Return a confirmation response to the client
Return Content("The document has been sent to the printer.")
End Function
End Class
End Namespace
Remember to replace "Your Printer Name" with the actual name of the printer in your environment. The printer should be accessible to the server where the ASP.NET Core application is running. When you run the program and go to the URL "**https://localhost:<Your-Port>/Pdf/PrintPdf**
", you'll see the output message indicating that the PDF has been sent to the printer.
Throughout this tutorial, we've explored the functionality and capabilities of IronPDF within the context of an ASP.NET Core application. From setting up your project with IronPDF, creating and manipulating PDF documents, to the more intricate processes involved in printing these documents, IronPDF has proven to be a robust and versatile tool for handling PDFs in .NET Core.
For those interested in utilizing IronPDF, it's worth noting that the library offers a free trial, allowing you to evaluate its features before committing. If you find it suits your needs, IronPDF licenses start from $749, providing a scalable solution for both small and large-scale projects. Below you can see the pricing for IronXL licensing, and you can click here to view more.
IronPrint is Iron Software's .NET printing library, compatible with multiple platforms such as Windows, macOS, Android, and iOS.
This tutorial aims to equip developers with the knowledge and tools necessary to handle printing PDF files in .NET Core applications efficiently using IronPDF.
To start using IronPDF, you need to create a new ASP.NET Core Web project in Visual Studio and install IronPDF via the NuGet Package Manager.
To print a PDF using IronPDF, create or load the PDF document in the controller, configure printer settings, and use the PDF library to send the document to the printer.
In ASP.NET Core, you can create a PDF by rendering HTML content as a PDF document using the ChromePdfRenderer class from IronPDF.
Yes, IronPDF can print directly to a printer by configuring printer settings and initiating a print job within your ASP.NET Core application.
You need to specify the printer name and optionally configure additional settings like the number of copies or page orientation in your application code.
Yes, IronPDF offers a free trial, allowing you to evaluate its features before committing to a purchase.
Detailed documentation on IronPrint is available on Iron Software's website, under the IronPrint section.
IronPDF supports various platforms, including .NET Core, ASP.NET Core, and is compatible with Windows, macOS, Android, and iOS.