---
title: "Create PDF from byte array | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/pdf-generation/byte-array/"
md_url: "https://www.nutrient.io/guides/dotnet/pdf-generation/byte-array.md"
last_updated: "2026-05-21T17:12:02.215Z"
description: "Learn how to generate PDF documents programmatically in .NET using Nutrient .NET SDK. Create, manipulate, and output PDF files within your applications."
---

# Create PDFs from byte arrays in C#

To create a PDF document from a byte array, follow the steps below:

1. Create a `GdPicturePDF` object and a `GdPictureImaging` object.

2. Load the source byte array by passing its path to the `CreateGdPictureImageFromByteArray` method of the `GdPictureImaging` object.

3. Create the output PDF document with the `NewPDF` method of the `GdPicturePDF` object.

4. Add the image to the output PDF document with the `AddImageFromGdPictureImage` method of the `GdPicturePDF` object.

5. Save the output PDF document with the `SaveToFile` method of the `GdPicturePDF` object.

6. Release unnecessary resources.

The code below creates a PDF document from a byte array based on an image source:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Create a byte array from an image file.
byte[] byteArray = File.ReadAllBytes(@"C:\temp\source.png");
// Load the source byte array.
int imageId = gdpictureImaging.CreateGdPictureImageFromByteArray(byteArray);
// Create the output PDF document.
gdpicturePDF.NewPDF();
// Add the image to the output PDF document.
gdpicturePDF.AddImageFromGdPictureImage(imageId, false, true);
// Save the output PDF document.
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
// Release unnecessary resources.
gdpicturePDF.CloseDocument();
gdpictureImaging.ReleaseGdPictureImage(imageId);

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Create a byte array from an image file.
    Dim byteArray = File.ReadAllBytes("C:\temp\source.png")
    ' Load the source byte array.
    Dim imageId As Integer = gdpictureImaging.CreateGdPictureImageFromByteArray(byteArray)
    ' Create the output PDF document.
    gdpicturePDF.NewPDF()
    ' Add the image to the output PDF document.
    gdpicturePDF.AddImageFromGdPictureImage(imageId, False, True)
    ' Save the output PDF document.
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
    ' Release unnecessary resources.
    gdpicturePDF.CloseDocument()
    gdpictureImaging.ReleaseGdPictureImage(imageId)
End Using
End Using

```

This example is for illustrative purposes only. Nutrient.NET SDK (formerly GdPicture.NET) offers simpler ways to convert between different file types. For more information, refer to the [conversion](/guides/dotnet/conversion.md) guides.

#### Used methods

- [`AddImageFromGdPictureImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddImageFromGdPictureImage.html)

- [`CloseDocument`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~CloseDocument.html)

- [`CreateGdPictureImageFromByteArray`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~CreateGdPictureImageFromByteArray.html)

- [`NewPDF`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewPDF.html)

- [`ReleaseGdPictureImage`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureImaging~ReleaseGdPictureImage.html)

- [`SaveToFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

---

## Related pages

- [Generate a PDF from HTML in C#](/guides/dotnet/pdf-generation/from-html.md)
- [Generate PDFs in.NET](/guides/dotnet/pdf-generation.md)
- [Create PDFs from scratch in C#](/guides/dotnet/pdf-generation/from-scratch.md)
- [Create thumbnails from PDFs in C#](/guides/dotnet/pdf-generation/thumbnail-preview.md)
- [Create tagged PDFs in C#](/guides/dotnet/pdf-generation/tagged.md)
- [Generate a PDF from a DOCX template in C#](/guides/dotnet/pdf-generation/from-word-template.md)

