PDF Converter .NET (Developer 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.
- The IronPDF library supports a variety of inputs for PDF production, including image files to PDF conversion, HTML5 to PDF conversion, ASPX to PDF conversion, and Razor/MVC View conversion.
- The library has tools for creating interactive PDF files, editing and sending interactive forms, dividing PDF files, extracting text and images, text searching, and rasterizing PDF pages into images.
- The library allows the use of a URL as the basis of a PDF document and supports user agents, proxies, cookies, HTTP headers, and form variables for authentication behind HTML login forms.
- IronPDF enables access to protected PDF files with passwords by supplying usernames and passwords.
- The library supports the reading and editing of existing PDF documents.
- Users can add text, graphics, organize bookmarks, watermarks, customize headers and footers to PDF documents with IronPDF, and extract images from PDF files.
- IronPDF allows for splitting and merging pages in a new or existing PDF document and can produce PDF objects from text without the need for Adobe Acrobat Reader.
- CSS media files and CSS files conversion to PDF are supported.
- Users can add new fillable PDF forms or complete existing ones with IronPDF.
- IronPDF can also convert PDF pages into various image formats such as JPEG, PNG, etc.
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")
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.
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")
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.
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")
The HTML text is as below:
<p style="color:red">Hello world</p>
<p style="color:red">Hello world</p>
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")
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")
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")
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")
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 $749 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.
Frequently Asked Questions
How can I convert HTML to PDF in .NET without losing formatting?
You can use IronPDF to convert HTML to PDF without losing formatting by utilizing the Chrome engine. The library supports HTML5, JavaScript, and CSS, ensuring that your PDFs retain their original layout and design.
What methods are available for converting URLs to PDFs?
IronPDF provides the RenderUrlAsPdf
method, which allows for the straightforward conversion of URLs into PDF documents using the ChromePdfRenderer class.
Is there a way to convert Markdown to PDF in C#?
Yes, IronPDF can convert Markdown files to PDFs by using the RenderMarkdownFileAsPdf
method. This allows developers to efficiently transform markdown content into PDF format.
How can I convert RTF files into PDF documents using .NET?
IronPDF enables the conversion of RTF files to PDFs with the RenderRtfFileAsPdf
method, allowing quick and accurate transformation of Rich Text Files into PDF format.
Can I extract text and images from PDF files?
Yes, IronPDF allows you to extract text and images from PDF documents easily, providing functionality to search and manipulate text and images within PDFs.
What options are available for creating interactive PDF forms?
IronPDF supports the creation and editing of interactive PDF forms, allowing developers to add form fields, graphics, bookmarks, and watermarks to their PDF documents.
How can I merge or split PDF documents in .NET?
IronPDF provides functionality for merging and splitting PDF documents, allowing developers to combine multiple PDFs into one or split a single PDF into multiple documents.
What licensing options does IronPDF offer for production use?
IronPDF offers a variety of licensing options for production use, including a Lite bundle with no ongoing costs. Licenses provide permanent use rights, a 30-day money-back guarantee, and a year of product updates and support.
Can IronPDF be used in ASP.NET Web and Windows Applications?
Yes, IronPDF is compatible with both ASP.NET Web Applications and traditional Windows Applications, providing flexibility for developers working in different environments.
Does IronPDF support password-protected PDF files?
IronPDF can handle password-protected PDF files by allowing users to provide the necessary credentials to read and edit these documents.