Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
This guide will explore the process of converting a byte array into a PDF file using the robust capabilities of the IronPDF .NET library. This transformation is crucial for developers who need to work with PDF files within their .NET applications.
The following topics will be converted in this tutorial:
IronPDF is a .NET library that makes reading, manipulating, and writing PDF documents easy. You can use it in your .NET projects for desktop and Web Applications. IronPDF is available for free for development purposes. This library allows you to convert HTML to PDF, extract text from a PDF, and more. IronPDF is a lightweight .NET PDF library designed specifically with web developers in mind. It is written entirely in C#. IronPDF contains an extensive set of functions that can be used to work with PDF files in a programming environment. Functions are created to improve the workflow and provide access to every aspect of PDF. These include creating, opening, deleting, adding pages, and extracting text from PDF documents. The IronPDF library has many useful features:
Let's start with how to use the IronPDF library to convert the byte array to a PDF file.
Starting with opening Visual Studio, select any C# application template according to your project needs. For this quick tutorial, the Console Application template will be used. You can modify the already existing C++ project file.
Use the latest version of Visual Studio for creating the C# project. Follow the provided steps to create a C# project.
By following the above steps, a C# project will be created. Now it's time to install the IronPDF library.
IronPDF is easy to install too. You get a fast and efficient installation process, cutting down development time and removing the confusion that usually accompanies it.
Installing the IronPDF Library with Package Manager Console is very easy. Once you have the console open, type the following command, hit enter and it will be done!
Install-Package IronPdf
The progress of installing IronPDF in the NuGet Package Manager Console
To facilitate a more seamless installation process for this library and to give you a good understanding of how to use it, downloading the DLL file from the IronPdf website is also recommended. Installation instructions can be found on this installation page.
Although IronPDF is essential for this project, it is necessary to import its namespace into every code file to use it. To do that, add the following line of code at the top of each file:
using IronPdf;
using IronPdf;
Imports IronPdf
As IronPDF is ready to use, adding the following code into your program file will help to convert byte array to PDF file:
using IronPdf;
using System.Text;
// Converting an array of bytes into a PDF file.
byte [] byteArray = { 84, 104, 105, 115, 32, 105, 115, 32, 98, 121, 116, 101, 32, 97, 114, 114, 97, 121};
// Storing encoded bytes into ASCII literals in a string variable
string data = Encoding.ASCII.GetString(byteArray);
string HTML = $"<h1>{data}</h1>";
var renderer = new IronPdf.ChromePdfRenderer();
using var pdf = renderer.RenderHtmlAsPdf(HTML);
pdf.SaveAs("bytearray.pdf");
using IronPdf;
using System.Text;
// Converting an array of bytes into a PDF file.
byte [] byteArray = { 84, 104, 105, 115, 32, 105, 115, 32, 98, 121, 116, 101, 32, 97, 114, 114, 97, 121};
// Storing encoded bytes into ASCII literals in a string variable
string data = Encoding.ASCII.GetString(byteArray);
string HTML = $"<h1>{data}</h1>";
var renderer = new IronPdf.ChromePdfRenderer();
using var pdf = renderer.RenderHtmlAsPdf(HTML);
pdf.SaveAs("bytearray.pdf");
Imports IronPdf
Imports System.Text
' Converting an array of bytes into a PDF file.
Private byteArray() As Byte = { 84, 104, 105, 115, 32, 105, 115, 32, 98, 121, 116, 101, 32, 97, 114, 114, 97, 121}
' Storing encoded bytes into ASCII literals in a string variable
Private data As String = Encoding.ASCII.GetString(byteArray)
Private HTML As String = $"<h1>{data}</h1>"
Private renderer = New IronPdf.ChromePdfRenderer()
Private pdf = renderer.RenderHtmlAsPdf(HTML)
pdf.SaveAs("bytearray.pdf")
The above code converts the byte array to PDF. At first, convert the given byte array to string using ASCII.GetString
function. Then, create an HTML string using the extracted data. After that, initiate ChromePdfRenderer
and call the RenderHtmlAsPdf
function to convert PDF files and create a new document.
Now, save the resultant PDF file document in the local system by using the SaveAs
function.
The output PDF file from the byte array
This is the generated PDF file contents.
This article demonstrated how to easily save Byte Array from PDF files using the IronPDF .NET PDF library. This was accomplished by only writing a few lines of code and with a high percentage of accuracy. Additionally, IronPDF also has many useful features such as HTML to PDF conversion, PDF formatting tools, and numerous more core PDF features that are imperative for PDF editing. IronPDF also eliminates the dependency on Adobe Acrobat.
IronPDF is free for development purposes and also offers a free trial for production testing. IronPDF provides a variety of pricing plans that you can get according to your needs. The price of IronPDF is relatively significantly less than its competitors. With pricing variating from individual to large companies, it proves to be a compelling purchase with impressive performance.
The pricing plan for Iron Software's Suite
In addition, Iron Software offers a suite of five Iron Software packages for the price of just two. Please visit this licensing page, to get more details.
9 .NET API products for your office documents