Saltar al pie de página
USANDO IRONPDF

Convertidor PDF .NET (Tutorial)

1.0 Introduction

Adobe's Portable Document Format (PDF) is widely used for document viewing and exchange. Developers often need to create PDFs to meet client needs, and modern libraries have simplified this process. When selecting a library for a project, it's important to consider features like build, read, and conversion capabilities.

2.0 IronPDF Features

IronPDF is a versatile library for creating, reading, and editing PDF documents, with capabilities to convert HTML to PDF using the Chrome engine. It supports a wide range of web components and can be used with both ASP.NET Web Applications and traditional Windows Applications. The library allows the creation of visually appealing PDFs using HTML5, JavaScript, CSS, and images, and includes a powerful HTML-to-PDF converter.

3.0 Create PDF Documents from URLs

Generating PDF files from web pages is easy with IronPDF's built-in Chrome browser and API library. Simply provide the URL and convert it to a PDF file using the IronPDF API library. Document conversion can be completed quickly with just a few lines of code:

// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified URL to a PDF
var pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified URL to a PDF
var pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
' Create a new instance of the ChromePdfRenderer class
Dim renderer = New IronPdf.ChromePdfRenderer()

' Convert the specified URL to a PDF
Dim pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/")

' Save the PDF to the specified path
pdf.SaveAs("result.pdf")
$vbLabelText   $csharpLabel

The RenderUrlAsPdf method can be used to quickly convert a URL into a PDF document. Simply provide the URL and the desired save location, and IronPDF will generate the PDF file according to the information provided above. This makes it easy to convert web pages into PDF documents with just a few lines of code.

PDF Converter .NET (Developer Tutorial), Figure 1: The generated PDF file from a Google URL The generated PDF file from a Google URL

4.0 Create a PDF from HTML Strings

HTML strings can be quickly converted into PDF files using the IronPDF API library. The following code snippet can turn HTML strings into documents and can translate any HTML tag into a PDF file.

// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified HTML string to a PDF
var pdf = renderer.RenderHtmlAsPdf("<p>Hello world!!</p>");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified HTML string to a PDF
var pdf = renderer.RenderHtmlAsPdf("<p>Hello world!!</p>");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
' Create a new instance of the ChromePdfRenderer class
Dim renderer = New IronPdf.ChromePdfRenderer()

' Convert the specified HTML string to a PDF
Dim pdf = renderer.RenderHtmlAsPdf("<p>Hello world!!</p>")

' Save the PDF to the specified path
pdf.SaveAs("result.pdf")
$vbLabelText   $csharpLabel

This code snippet illustrates how to use the RenderHtmlAsPdf function to convert HTML text into a PDF. The function that converts HTML into a string accepts as much HTML code as needed. Then the process can be quickly and easily completed by using the SaveAs feature to save the document.

PDF Converter .NET (Developer Tutorial), Figure 2: The output PDF file from an HTML string The output PDF file from an HTML string

5.0 Create a PDF File from an HTML File

The IronPDF API library allows for the rapid conversion of HTML files into PDF files. Any HTML tag may be converted into a PDF file using the following sample code.

// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified HTML file to a PDF
var pdf = renderer.RenderHtmlFileAsPdf("test.html");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified HTML file to a PDF
var pdf = renderer.RenderHtmlFileAsPdf("test.html");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
' Create a new instance of the ChromePdfRenderer class
Dim renderer = New IronPdf.ChromePdfRenderer()

' Convert the specified HTML file to a PDF
Dim pdf = renderer.RenderHtmlFileAsPdf("test.html")

' Save the PDF to the specified path
pdf.SaveAs("result.pdf")
$vbLabelText   $csharpLabel

The HTML text is as below:

<p style="color:red">Hello world</p>
<p style="color:red">Hello world</p>
HTML

PDF Converter .NET (Developer Tutorial), Figure 3: The output PDF file from an HTML file The output PDF file from an HTML file

6.0 Create a PDF File from a Rich Text File

The IronPDF API library also allows for fast PDF creation from Rich Text Files (RTFs). The sample code for converting RTFs to PDFs can be utilized to convert any number of RTFs into a single PDF file. The code is provided below.

// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified RTF file to a PDF
var pdf = renderer.RenderRtfFileAsPdf("test.rtf");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified RTF file to a PDF
var pdf = renderer.RenderRtfFileAsPdf("test.rtf");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
' Create a new instance of the ChromePdfRenderer class
Dim renderer = New IronPdf.ChromePdfRenderer()

' Convert the specified RTF file to a PDF
Dim pdf = renderer.RenderRtfFileAsPdf("test.rtf")

' Save the PDF to the specified path
pdf.SaveAs("result.pdf")
$vbLabelText   $csharpLabel

PDF Converter .NET (Developer Tutorial), Figure 4: The output PDF file from an RTF file The output PDF file from an RTF file

In the image above, the left side shows the source document, while the right side displays the PDF file after conversion. Additionally, we can utilize the RTF string to create a PDF by using the code provided below.

// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified RTF string to a PDF
var pdf = renderer.RenderRtfStringAsPdf("{\\rtf1...}");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified RTF string to a PDF
var pdf = renderer.RenderRtfStringAsPdf("{\\rtf1...}");

// Save the PDF to the specified path
pdf.SaveAs("result.pdf");
' Create a new instance of the ChromePdfRenderer class
Dim renderer = New IronPdf.ChromePdfRenderer()

' Convert the specified RTF string to a PDF
Dim pdf = renderer.RenderRtfStringAsPdf("{\rtf1...}")

' Save the PDF to the specified path
pdf.SaveAs("result.pdf")
$vbLabelText   $csharpLabel

7.0 Create a PDF File from a Markdown File

Quick PDF production from markdown files is possible thanks to the IronPDF API module. Any number of Markdown files can be converted into a PDF file using the sample code for the conversion, shown below.

// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified Markdown file to a PDF
var pdf = renderer.RenderMarkdownFileAsPdf("Markdown.md");

// Save the PDF to the specified path
pdf.SaveAs("Markdown_result.pdf");
// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified Markdown file to a PDF
var pdf = renderer.RenderMarkdownFileAsPdf("Markdown.md");

// Save the PDF to the specified path
pdf.SaveAs("Markdown_result.pdf");
' Create a new instance of the ChromePdfRenderer class
Dim renderer = New IronPdf.ChromePdfRenderer()

' Convert the specified Markdown file to a PDF
Dim pdf = renderer.RenderMarkdownFileAsPdf("Markdown.md")

' Save the PDF to the specified path
pdf.SaveAs("Markdown_result.pdf")
$vbLabelText   $csharpLabel

PDF Converter .NET (Developer Tutorial), Figure 5: The output PDF file from a Markdown file The output PDF file from a Markdown file

As shown in the image above, the source document is on the left, and the converted PDF file is on the right. The code provided below enables the conversion of an MD string to a PDF. For further information on HTML conversion using IronPDF, please visit this HTML to PDF Conversion Tutorial.

// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified Markdown string to a PDF
var pdf = renderer.RenderMarkdownStringAsPdf("# Hello world\n\nHello world");

// Save the PDF to the specified path
pdf.SaveAs("Markdown_result.pdf");
// Create a new instance of the ChromePdfRenderer class
var renderer = new IronPdf.ChromePdfRenderer();

// Convert the specified Markdown string to a PDF
var pdf = renderer.RenderMarkdownStringAsPdf("# Hello world\n\nHello world");

// Save the PDF to the specified path
pdf.SaveAs("Markdown_result.pdf");
Imports Microsoft.VisualBasic

' Create a new instance of the ChromePdfRenderer class
Dim renderer = New IronPdf.ChromePdfRenderer()

' Convert the specified Markdown string to a PDF
Dim pdf = renderer.RenderMarkdownStringAsPdf("# Hello world" & vbLf & vbLf & "Hello world")

' Save the PDF to the specified path
pdf.SaveAs("Markdown_result.pdf")
$vbLabelText   $csharpLabel

For more information on how to use the IronPDF API library, refer to the developer documentation IronPDF Documentation Resource.

8.0 Conclusion

The IronPDF library provides a free license for development, and depending on the developer's needs, several licenses are available for purchase for use in a production environment. The Lite bundle has an initial price of $799 and has no ongoing costs. The licenses come with a permanent license, a 30-day money-back guarantee, a year of product support and upgrades, as well as the possibility of redistribution for SaaS and OEM. They are one-time purchases that can be used for development, staging, and production. IronPDF also offers additional time-limited free licenses and free licenses for redistribution protection. For a complete overview of pricing and licensing information for IronPDF, please visit the IronPDF Licensing Information Page.

Preguntas Frecuentes

¿Cómo puedo convertir HTML a PDF en .NET sin perder formato?

Puede usar IronPDF para convertir HTML a PDF sin perder formato utilizando el motor Chrome. La biblioteca soporta HTML5, JavaScript y CSS, asegurando que sus PDFs mantengan su diseño y formato original.

¿Qué métodos están disponibles para convertir URLs a PDFs?

IronPDF proporciona el método RenderUrlAsPdf, el cual permite la conversión directa de URLs a documentos PDF usando la clase ChromePdfRenderer.

¿Existe una manera de convertir Markdown a PDF en C#?

Sí, IronPDF puede convertir archivos Markdown a PDFs usando el método RenderMarkdownFileAsPdf. Esto permite a los desarrolladores transformar contenido markdown en formato PDF de manera eficiente.

¿Cómo puedo convertir archivos RTF en documentos PDF usando .NET?

IronPDF permite la conversión de archivos RTF a PDFs con el método RenderRtfFileAsPdf, permitiendo una transformación rápida y precisa de archivos de Texto Enriquecido a formato PDF.

¿Puedo extraer texto e imágenes de archivos PDF?

Sí, IronPDF le permite extraer texto e imágenes de documentos PDF fácilmente, proporcionando funcionalidad para buscar y manipular texto e imágenes dentro de PDFs.

¿Qué opciones están disponibles para crear formularios PDF interactivos?

IronPDF soporta la creación y edición de formularios PDF interactivos, permitiendo a los desarrolladores añadir campos de formulario, gráficos, marcadores y marcas de agua a sus documentos PDF.

¿Cómo puedo combinar o dividir documentos PDF en .NET?

IronPDF proporciona funcionalidad para combinar y dividir documentos PDF, permitiendo a los desarrolladores combinar múltiples PDFs en uno o dividir un único PDF en múltiples documentos.

¿Qué opciones de licencia ofrece IronPDF para uso en producción?

IronPDF ofrece una variedad de opciones de licencia para uso en producción, incluyendo un paquete Lite sin costos continuos. Las licencias permiten uso permanente, garantía de devolución del dinero de 30 días, y un año de actualizaciones y soporte del producto.

¿Puede IronPDF ser usado en aplicaciones Web ASP.NET y Windows?

Sí, IronPDF es compatible tanto con Aplicaciones Web ASP.NET como con Aplicaciones tradicionales de Windows, proporcionando flexibilidad a los desarrolladores que trabajan en diferentes entornos.

¿IronPDF soporta archivos PDF protegidos por contraseña?

IronPDF puede manejar archivos PDF protegidos por contraseña permitiendo a los usuarios proporcionar las credenciales necesarias para leer y editar estos documentos.

.NET 10: ¿IronPDF es totalmente compatible con proyectos orientados a .NET 10?

Sí. IronPDF es totalmente compatible con .NET 10, incluyendo nuevas mejoras en el entorno de ejecución y el lenguaje C#, en entornos de escritorio, web, microservicios y nube/contenedor. Funciona de inmediato con proyectos .NET 10 sin necesidad de soluciones alternativas ni API personalizadas.

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