Skip to footer content
USING IRONPDF

Topics Covered in Tutorial

The following topics will be covered in this tutorial:

  • IronPDF
  • Steps to Create PDF Files Programmatically
  • Step 1: Create a C# Project
  • Step 2: Install the IronPDF Library
    • Method 1: NuGet Package Manager Console
    • Method 2: Using the DLL File
  • Step 3: Add the IronPDF Namespace
  • Step 4: Convert Byte Array to PDF File
    • Output
  • Conclusion


IronPDF: C# PDF Library

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.

Steps to Convert Byte Array to PDF

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.

Step 1: Create a C# Project

Use the latest version of Visual Studio for creating the C# project. Follow the provided steps to create a C# project.

  • Open the Visual Studio on your machine.
  • Create a C# Console Application or modify an already existing C# application.
  • Give an appropriate name according to your project.
  • Select the .NET Framework 6.0, the latest framework that comes with long support. You can choose any other framework according to requirements but the latest version is strongly recommended.

By following the above steps, a C# project will be created. Now it's time to install the IronPDF library.

Step 2: 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.

Method 1: NuGet Package Manager Console

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

Save Byte Array to PDF C# (Code Example), Figure 1: The progress of installing IronPDF in the NuGet Package Manager Console The progress of installing IronPDF in the NuGet Package Manager Console

Method 2: Using a DLL file

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 website directly is also recommended. Installation instructions can be found on this Installation Guide.

Step 3: Add the IronPDF Namespace

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
$vbLabelText   $csharpLabel

Step 4: Convert Byte Array to PDF Document

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 };

// Convert the byte array into a string using ASCII encoding
string data = Encoding.ASCII.GetString(byteArray);

// Create an HTML string with the data
string HTML = $"<h1>{data}</h1>";

// Initialize PDF renderer
var renderer = new IronPdf.ChromePdfRenderer();

// Render HTML to PDF
using var pdf = renderer.RenderHtmlAsPdf(HTML);

// Save the PDF file
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 };

// Convert the byte array into a string using ASCII encoding
string data = Encoding.ASCII.GetString(byteArray);

// Create an HTML string with the data
string HTML = $"<h1>{data}</h1>";

// Initialize PDF renderer
var renderer = new IronPdf.ChromePdfRenderer();

// Render HTML to PDF
using var pdf = renderer.RenderHtmlAsPdf(HTML);

// Save the PDF file
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 }



' Convert the byte array into a string using ASCII encoding

Private data As String = Encoding.ASCII.GetString(byteArray)



' Create an HTML string with the data

Private HTML As String = $"<h1>{data}</h1>"



' Initialize PDF renderer

Private renderer = New IronPdf.ChromePdfRenderer()



' Render HTML to PDF

Private pdf = renderer.RenderHtmlAsPdf(HTML)



' Save the PDF file

pdf.SaveAs("bytearray.pdf")
$vbLabelText   $csharpLabel

The above code converts the byte array to PDF. At first, convert the given byte array to a string using the 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.

Output

Save Byte Array to PDF C# (Code Example), Figure 2: The output PDF file from the byte array The output PDF file from the byte array

This is the generated PDF file contents.

Conclusion

This article demonstrated how to easily save a 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 varying from individual to large companies, it proves to be a compelling purchase with impressive performance.

Save Byte Array to PDF C# (Code Example), Figure 3: The pricing plan for Iron Software's Suite 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 Information Page, to get more details.

Frequently Asked Questions

What is the library used to manipulate and create PDF documents in .NET?

IronPDF is a .NET library designed for reading, manipulating, and writing PDF documents. It is available for use in .NET desktop and web applications and offers functionalities like converting HTML to PDF, extracting text, and more.

How do I convert a byte array to a PDF file using C#?

To convert a byte array to a PDF file using C#, you can use the IronPDF library. First, install the library, then use the ChromePdfRenderer class to render HTML content from the byte array data as a PDF and save it using the SaveAs method.

How can I install the PDF manipulation library in my project?

You can install IronPDF using the NuGet Package Manager Console with the command 'Install-Package IronPdf'. Alternatively, you can download and use the DLL file directly from the IronPDF website.

Is the PDF library free to use?

IronPDF is free for development purposes. It also offers a free trial for production testing. Various pricing plans are available for production use, catering to different needs from individual developers to large companies.

What are the system requirements for using the PDF library with C#?

IronPDF can be used in projects that target the latest .NET frameworks. It is recommended to use it with the latest version of Visual Studio and .NET Framework 6.0 for optimal performance.

What are some features of the PDF library?

IronPDF offers a variety of features including reading and writing PDFs, converting HTML to PDF with CSS styling, extracting pages or text from PDFs, and adding watermarks or text overlays.

Can the PDF library convert HTML to PDF?

Yes, IronPDF can convert HTML to PDF, with support for CSS styling. This feature allows developers to generate PDFs from web content seamlessly.

How do I add the PDF library namespace in my C# project?

To use IronPDF in your C# project, you need to import its namespace by adding 'using IronPdf;' at the top of each code file where you plan to use the library's functionalities.

What is the advantage of using this PDF library over others?

IronPDF is lightweight and written entirely in C#, making it a good fit for .NET applications. It offers a robust set of PDF manipulation features while being cost-effective compared to its competitors.

What support and resources are available for users of the PDF library?

IronPDF provides comprehensive documentation, example code, and a variety of licensing options. It is supported by a responsive customer service team to assist with any technical queries.

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.