Saltar al pie de página
USANDO IRONPDF

Biblioteca PDF de .NET Core

IronPDF is available for Microsoft Windows .NET Framework 4.x, as well as a recent release for .NET Core 3.1 and the latest .NET version.

IronPDF for .NET Core is available through the NuGet official page IronPdf package on NuGet.

The current .NET Core release is cross-platform, supporting Linux, Unix, and macOS client operating systems, as well as Mono, with MAUI, and Blazor compatibility.

Existing and new customers receive free upgrades to the .NET Core build of IronPDF within their existing Support & Upgrade coverage. This is provided with every IronPDF commercial license. This ensures your investment in IronPDF is future-proofed.

Existing customers who wish to extend expired support & update cover can purchase an extension to the IronPDF license.

IronPDF: A .NET PDF Library

IronPDF is a C# PDF library that can be used in .NET Core projects. It provides all the necessary APIs to manipulate PDF documents straightforwardly and intuitively. There are other PDF-generating libraries on the market, but this library has been designed as simply as possible to avoid confusion.

The main goal of this project is to provide a PDF library for .NET applications. It comes with many useful features, such as generating PDF files from HTML strings, converting PDFs to other formats, manipulating existing PDF documents, and generating PDF files directly from .NET Core projects. The IronPDF library also offers the ability to print PDF files with just a few lines of code. IronPDF can be used as a PDF converter. It can create multi-page spread tables using its accessible functions.

Let's begin using the IronPDF library in our project.

Create C# Project

The latest version of Visual Studio is recommended for creating this .NET project to ensure a smooth user experience. The IronPDF library is also compatible with a .NET Core project. The choice depends on the user, as the installation and use of IronPDF are identical across all .NET Frameworks. Follow the steps below to create a project in Visual Studio.

  • Start Visual Studio.
  • Click on "Create a new project".

.NET Core PDF Library, Figure 1: Create a new project in Visual Studio Create a new project in Visual Studio

  • Search for "Console" in the search field, and select "Console App" with the C# tag from the search results.

.NET Core PDF Library, Figure 2: Console App selection Console App selection

  • After that, configure the project name according to your requirements.

.NET Core PDF Library, Figure 3: Configure this new application Configure this new application

  • After that, select the latest version of .NET Framework from the dropdown list. This is recommended. Next, click on the Create button.

.NET Core PDF Library, Figure 4: .NET Framework selection .NET Framework selection

The project will now be created. You can also use existing .NET Core projects with IronPDF. First, you need to install the library. The next section shows how to install the library.

Installation of the IronPDF Library

To install the IronPDF library from the command line, run the following command:

Install-Package IronPdf

You can get more information on the IronPDF website and the IronPDF NuGet page.

After installation, you will be able to use it in your .NET project. For more details about installation, visit the IronPDF installation guide.

Code Example

A web page for PDF files

using IronPdf;

var renderer = new ChromePdfRenderer();

// Choose Screen or Print CSS media
renderer.RenderingOptions.CssMediaType = Rendering.PdfCssMediaType.Screen;

// Set the width of the responsive virtual browser window in pixels
renderer.RenderingOptions.ViewPortWidth = 1280;

// Set the paper size of the output PDF
renderer.RenderingOptions.PaperSize = Rendering.PdfPaperSize.A2;

// Render the URL as PDF
var pdf = renderer.RenderUrlAsPdf("https://www.amazon.com/");

// Save the PDF to a local file
pdf.SaveAs("Amazon.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

// Choose Screen or Print CSS media
renderer.RenderingOptions.CssMediaType = Rendering.PdfCssMediaType.Screen;

// Set the width of the responsive virtual browser window in pixels
renderer.RenderingOptions.ViewPortWidth = 1280;

// Set the paper size of the output PDF
renderer.RenderingOptions.PaperSize = Rendering.PdfPaperSize.A2;

// Render the URL as PDF
var pdf = renderer.RenderUrlAsPdf("https://www.amazon.com/");

// Save the PDF to a local file
pdf.SaveAs("Amazon.pdf");
Imports IronPdf

Private renderer = New ChromePdfRenderer()

' Choose Screen or Print CSS media
renderer.RenderingOptions.CssMediaType = Rendering.PdfCssMediaType.Screen

' Set the width of the responsive virtual browser window in pixels
renderer.RenderingOptions.ViewPortWidth = 1280

' Set the paper size of the output PDF
renderer.RenderingOptions.PaperSize = Rendering.PdfPaperSize.A2

' Render the URL as PDF
Dim pdf = renderer.RenderUrlAsPdf("https://www.amazon.com/")

' Save the PDF to a local file
pdf.SaveAs("Amazon.pdf")
$vbLabelText   $csharpLabel

This example shows how to convert a complex website UI to PDF, for example, the Amazon website, by following these steps:

  • Set the Media Type to Screen
  • Set the viewport width
  • Set the paper size of the output PDF. Page size is a significant factor in PDF files
  • Render the URL to PDF, using the Amazon URL as a source

Output

.NET Core PDF Library, Figure 5: Output PDF file rendered from Amazon website Output PDF file rendered from Amazon website

Simple PDF Creation

using IronPdf;

// Instantiate renderer
var renderer = new IronPdf.ChromePdfRenderer();

// Create a PDF from an HTML string using C#
using var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");

// Export to a file or Stream
pdf.SaveAs("output.pdf");

/****** Advanced Example with HTML Assets ******/
// Load external html assets: images, CSS, and JavaScript.
// An optional BasePath 'C:\\site\\assets\\' is set as the file location to load assets from
using var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");

// Save the PDF with assets to a file
myAdvancedPdf.SaveAs("html-with-assets.pdf");
using IronPdf;

// Instantiate renderer
var renderer = new IronPdf.ChromePdfRenderer();

// Create a PDF from an HTML string using C#
using var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");

// Export to a file or Stream
pdf.SaveAs("output.pdf");

/****** Advanced Example with HTML Assets ******/
// Load external html assets: images, CSS, and JavaScript.
// An optional BasePath 'C:\\site\\assets\\' is set as the file location to load assets from
using var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");

// Save the PDF with assets to a file
myAdvancedPdf.SaveAs("html-with-assets.pdf");
Imports IronPdf

' Instantiate renderer
Private renderer = New IronPdf.ChromePdfRenderer()

' Create a PDF from an HTML string using C#
Private pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")

' Export to a file or Stream
pdf.SaveAs("output.pdf")

'''**** Advanced Example with HTML Assets *****
' Load external html assets: images, CSS, and JavaScript.
' An optional BasePath 'C:\\site\\assets\\' is set as the file location to load assets from
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")

' Save the PDF with assets to a file
myAdvancedPdf.SaveAs("html-with-assets.pdf")
$vbLabelText   $csharpLabel

The code above demonstrates how to use the HTML-to-PDF functionality of IronPDF. To use IronPDF, importing the namespace is necessary. Write using IronPdf; at the top of the program file to use it in the project.

The ChromePdfRenderer object is available for web support. The RenderHtmlAsPdf function can be used for converting HTML strings to PDF files. The function parameter accepts various types of sources, including an HTML string. You can also use images in your PDF document by setting the base path of images. After that, the SaveAs function is used to save the PDF file locally. You can choose simple HTML like the above and incorporate CSS, images, and JavaScript.

Output

.NET Core PDF Library, Figure 6: PDF file output from Hello World HTML text PDF file output from Hello World HTML text

Headers & Footers

// Initialize the first page number
renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a cover page will be appended

// Set header options
renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
renderer.RenderingOptions.TextHeader.CenterText = "{url}";
renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
renderer.RenderingOptions.TextHeader.FontSize = 12;
// Initialize the first page number
renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a cover page will be appended

// Set header options
renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
renderer.RenderingOptions.TextHeader.CenterText = "{url}";
renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
renderer.RenderingOptions.TextHeader.FontSize = 12;
' Initialize the first page number
renderer.RenderingOptions.FirstPageNumber = 1 ' use 2 if a cover page will be appended

' Set header options
renderer.RenderingOptions.TextHeader.DrawDividerLine = True
renderer.RenderingOptions.TextHeader.CenterText = "{url}"
renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica
renderer.RenderingOptions.TextHeader.FontSize = 12
$vbLabelText   $csharpLabel

The above example demonstrates how to set headers and footers in the PDF file. IronPDF supports repeating headers in the document. IronPDF provides TextHeader and TextFooter properties to set various attributes of text, such as fonts, text position, etc. It can also convert HTML files to PDF files. Everything is straightforward with IronPDF. It can also merge PDF files efficiently, perform webpage-to-PDF conversions, enable automatic page numeration, and create digital signatures for PDFs using IronPDF. Furthermore, it produces PDF files of minimal file size with efficient compression.

Summary

IronPDF is a complete PDF library that supports all the latest versions of .NET Core and .NET Frameworks. IronPDF is based on a business model that offers a secure way to create and edit business documents using the IronPDF library. Its advanced features enable the user to create dynamic and creative PDF documents in .NET Core projects. There is the option to try the free trial for production testing.

.NET Core PDF Library, Figure 7: IronPDF Professional license IronPDF Professional license

You can also currently buy the suite of five Iron Software packages for the price of just two. Get more information from the IronPDF licensing page.

Preguntas Frecuentes

¿Cómo genero archivos PDF desde HTML en .NET Core?

Puedes generar archivos PDF desde HTML en .NET Core usando el método RenderHtmlAsPdf de IronPDF, que te permite convertir cadenas HTML o archivos directamente en documentos PDF.

¿Es IronPDF compatible con el desarrollo multiplataforma?

Sí, IronPDF es compatible con el desarrollo multiplataforma y admite sistemas operativos como Windows, Linux, Unix y macOS, lo que lo hace versátil para diversos entornos de implementación.

¿Cómo puedo integrar una biblioteca de PDF en mi proyecto .NET Core?

Puedes integrar IronPDF en tu proyecto .NET Core instalándolo a través de NuGet. Simplemente ejecuta el comando dotnet add package IronPdf en el directorio de tu proyecto.

¿Puedo usar IronPDF para convertir páginas web a PDFs?

Sí, IronPDF proporciona funcionalidad para convertir páginas web completas a PDFs renderizando URLs directamente en formato PDF, facilitando el archivado de contenido web.

¿IronPDF admite la adición de encabezados y pies de página a los PDFs?

IronPDF admite la adición de encabezados y pies de página a tus archivos PDF, permitiendo un formato de documento consistente y profesional.

¿Cuáles son los beneficios de usar IronPDF para la manipulación de PDF?

IronPDF ofrece beneficios como facilidad de uso, API robusta para manipulación de PDFs, soporte multiplataforma, y características como fusión de PDFs y adición de firmas digitales.

¿IronPDF ofrece compresión de archivos para PDFs?

Sí, IronPDF proporciona opciones de compresión de archivos eficientes, asegurando que tus archivos PDF permanezcan mínimos en tamaño sin comprometer la calidad.

¿Hay una prueba gratuita para IronPDF?

IronPDF ofrece una prueba gratuita que permite a los usuarios probar sus características en entornos de producción antes de tomar una decisión de compra.

¿Cómo puedo actualizar IronPDF en un proyecto .NET Core existente?

Para actualizar IronPDF en un proyecto .NET Core existente, puedes usar el Administrador de Paquetes NuGet para verificar actualizaciones y aplicarlas según sea necesario, asegurándote de tener las características y correcciones más recientes.

¿Dónde puedo encontrar información de licencias para IronPDF?

La información de licencias para IronPDF se puede encontrar en su sitio web oficial, proporcionando detalles sobre diferentes opciones de licencia y planes de soporte.

¿IronPDF es totalmente compatible con .NET 10?

Sí, IronPDF es compatible con las últimas versiones de .NET, incluyendo .NET 10. La página del producto menciona explícitamente la compatibilidad con .NET 10, 9, 8, 7, 6, .NET Standard y .NET Framework. Los usuarios pueden aprovechar todas las funciones de IronPDF en proyectos que utilizan .NET 10.

¿Qué plataformas y tipos de proyectos admite IronPDF cuando se dirige a .NET 10?

Al usar IronPDF con .NET 10, puede compilar para Windows, Linux y macOS, incluyendo entornos Docker, Azure y AWS. Los tipos de proyectos .NET compatibles incluyen web (p. ej., Blazor, MVC), escritorio (WPF y MAUI), consola y bibliotecas. IronPDF se ejecuta de forma nativa sin necesidad de soluciones alternativas.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más