PDF API C# (Code Example Tutorial)
1. Introduction
Adobe's Portable Document Format (PDF) is essential for various operations in many companies, including generating documents and invoices. Developers also use it to meet client requirements. Libraries have simplified the process of creating PDFs. When choosing a library, consider aspects such as build, read, and conversion capabilities.
2. IronPDF Features
IronPDF is a robust PDF converter and API library that allows developers to generate, read, and manipulate PDF documents. It uses the Chrome engine to convert HTML to PDF and supports a variety of web components and .NET applications. It enables the creation of visually appealing PDFs using HTML5, JavaScript, CSS, and images, and includes a powerful HTML-to-PDF translator and an independent PDF conversion engine.
- The IronPDF library supports a variety of inputs for PDF production, including converting image files to PDF, transforming HTML5 documents into PDFs, generating PDFs from ASPX pages, and using Razor/MVC views for PDF creation.
- The library has tools for creating interactive PDF files, editing forms, dividing PDF files, extracting text and images, text searching, and converting PDF pages to images.
- In addition to using user agents, proxies, cookies, HTTP headers, and form variables for authentication in HTML login forms, the library also offers the usage of links as the foundation for PDF documents.
- IronPDF offers access to password-protected PDF files by requesting user names and passwords.
- With the IronPDF API, pre-existing PDF files can be read and edited.
- The library can extract pictures from PDF files and add text, graphics, bookmarks for document navigation, watermarks, custom headers, and footers to PDF documents.
- IronPDF enables users to divide and combine pages in a new or existing PDF document, and it can create PDF objects from text without using Acrobat Reader.
- CSS files can be transformed into PDF files, and CSS media queries can be converted into PDF documents.
- IronPDF enables users to fill out existing PDF forms and create new forms.
3. Create PDF Documents from URLs
With the assistance of the IronPDF API library, generating PDF files becomes very easy by creating an HTML file from a URL and converting it to a PDF file using the built-in Chrome browser in IronPDF.
The methods listed below make it simple to create PDF documents with just a few lines of code:
// Instantiate the ChromePdfRenderer object from IronPdf
IronPdf.ChromePdfRenderer renderer = new IronPdf.ChromePdfRenderer();
// Render the contents of a URL as a PDF document
var pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/");
// Save the rendered PDF document to a specified file path
pdf.SaveAs("result.pdf");
// Instantiate the ChromePdfRenderer object from IronPdf
IronPdf.ChromePdfRenderer renderer = new IronPdf.ChromePdfRenderer();
// Render the contents of a URL as a PDF document
var pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/");
// Save the rendered PDF document to a specified file path
pdf.SaveAs("result.pdf");
' Instantiate the ChromePdfRenderer object from IronPdf
Dim renderer As New IronPdf.ChromePdfRenderer()
' Render the contents of a URL as a PDF document
Dim pdf = renderer.RenderUrlAsPdf("https://www.google.co.in/")
' Save the rendered PDF document to a specified file path
pdf.SaveAs("result.pdf")
According to the information above, the RenderUrlAsPdf
method can be used to convert the link into a document by providing the link and the save location.
The PDF file generated from a URL
4. Create a PDF from HTML Strings
The IronPDF API library makes it easy to convert HTML strings into PDF files. Below is an example code for converting HTML strings into documents, and it allows the translation of any HTML tag into PDF files.
// Use the ChromePdfRenderer to convert an HTML string to a PDF
IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("Hello world!!").SaveAs("result.pdf");
// Use the ChromePdfRenderer to convert an HTML string to a PDF
IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("Hello world!!").SaveAs("result.pdf");
' Use the ChromePdfRenderer to convert an HTML string to a PDF
IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("Hello world!!").SaveAs("result.pdf")
This example code demonstrates how to convert an unlimited HTML text using RenderHtmlAsPdf
, then save the document using the SaveAs
method and the whole process is completed in just a matter of seconds.
A PDF file generated from an HTML string
5. Reading PDF Documents
With the help of the IronPDF API library, it is possible to read and extract data from existing PDF documents. The code below shows an example of how to do this:
// Load an existing PDF file into a PdfDocument object
var pdfDocument = IronPdf.PdfDocument.FromFile("result.pdf");
// Extract all text from the PDF document into a string
string AllText = pdfDocument.ExtractAllText();
// Load an existing PDF file into a PdfDocument object
var pdfDocument = IronPdf.PdfDocument.FromFile("result.pdf");
// Extract all text from the PDF document into a string
string AllText = pdfDocument.ExtractAllText();
' Load an existing PDF file into a PdfDocument object
Dim pdfDocument = IronPdf.PdfDocument.FromFile("result.pdf")
' Extract all text from the PDF document into a string
Dim AllText As String = pdfDocument.ExtractAllText()
In this code, the FromFile
function is used to read the PDF from an existing file and convert it into a PdfDocument
object. This object can be used to access the text and images present on the PDF pages. The ExtractAllText
method can be used to create a string containing every word on the PDF pages.
For more information on how to use the IronPDF API library, refer to the code tutorials and documentation.
6. Conclusion
The IronPDF library provides a free license for development, and different licenses are available for purchase for use in a production environment based on the developer's needs. The Lite package has a starting price of $749 and does not require any ongoing fees. The licenses offer redistribution options for SaaS and OEM and come with a permanent license, a 30-day money-back guarantee, and a year of product support and updates. They are suitable for development, staging, and production and require a one-time purchase. Moreover, IronPDF provides additional complimentary time-limited licenses. IronPDF also offers free licenses for redistribution coverage.
For more information on IronPDF's complete pricing and licensing details, please visit the IronPDF licensing details page.
Frequently Asked Questions
What is the purpose of a PDF API library?
IronPDF is a powerful PDF converter and API library for PDF processing that enables developers to easily generate, read, and manipulate PDF documents. It uses the Chrome engine to convert HTML to PDF and supports a variety of web components and .NET applications.
What are the main features of a PDF library?
IronPDF allows developers to generate, read, and manipulate PDF documents. It supports converting HTML, image files, ASPX pages, and Razor/MVC views into PDFs. Additionally, it offers tools for creating interactive PDFs, editing forms, extracting text and images, and more.
How can I create a PDF from a URL?
You can create a PDF from a URL using IronPDF by instantiating the ChromePdfRenderer object and using its RenderUrlAsPdf method. This allows the contents of a URL to be rendered as a PDF document.
Can a PDF library convert HTML strings into PDF files?
Yes, IronPDF can convert HTML strings into PDF files. The ChromePdfRenderer can be used to render HTML strings into PDF documents, which are then saved using the SaveAs method.
How do I read and extract data from existing PDF documents?
To read and extract data from existing PDFs, load the PDF into a PdfDocument object using the FromFile method. Then, use the ExtractAllText method to extract all text from the PDF document into a string.
What are the licensing options for a PDF library?
IronPDF offers a free license for development and various paid licenses for production use, including options for SaaS and OEM redistribution. These licenses are available with a one-time purchase, permanent license, a 30-day money-back guarantee, and a year of product support and updates.
Can a PDF library handle password-protected PDF files?
Yes, IronPDF can access password-protected PDF files by requesting usernames and passwords, allowing you to read and edit these documents.
Does a PDF library support interactive PDF file creation?
Yes, IronPDF supports the creation of interactive PDF files, including editing forms, adding bookmarks, watermarks, and custom headers and footers.
What input formats are supported for PDF production?
IronPDF supports converting image files, HTML5 documents, ASPX pages, Razor/MVC views, and CSS files into PDF documents.
How can I create PDFs from URLs using an API?
Using the IronPDF API, you can easily create PDFs from URLs by using the built-in Chrome browser to render the contents of a URL as a PDF document with just a few lines of code.