---
title: "Save PDF file in C# .NET | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/save-a-file/pdf-stream/"
md_url: "https://www.nutrient.io/guides/dotnet/save-a-file/pdf-stream.md"
last_updated: "2026-05-18T10:58:39.278Z"
description: "Discover how to save PDF files in .NET, including methods for local storage, streaming, and incremental saving. Perfect for developers seeking solutions."
---

# Save PDF files in C#

### Overview

[Overview](https://www.nutrient.io/guides/dotnet/save-a-file/pdf.md)

### To Local Storage

[To Local Storage](https://www.nutrient.io/guides/dotnet/save-a-file/pdf-local-storage.md)

### Incremental

[Incremental](https://www.nutrient.io/guides/dotnet/save-a-file/pdf-incremental.md)

### To Stream

[To Stream](https://www.nutrient.io/guides/dotnet/save-a-file/pdf-stream.md)

### Incremental to Stream

[Incremental to Stream](https://www.nutrient.io/guides/dotnet/save-a-file/pdf-incremental-to-stream.md)

To save a PDF document to a `Stream` object, use the [`SaveToStream` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~SaveToStream.html) of the [`GdPicturePDF` class](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF.html).

Common parameters:

- `Stream` — Destination `Stream`.

- `PackDocument` (optional) — Packs the PDF before saving (smaller file, slower save).

- `Linearize` (optional) — Enables Fast Web View mode. For details, see [linearize PDF](https://www.nutrient.io/guides/dotnet/optimization/linearize.md).

The Fast Web View mode makes it possible to download the content one page at a time from the web. This feature is useful for large documents.

`SaveToStream` returns a `GdPictureStatus`, which should be checked.

Packing removes unused PDF objects and recompresses used objects. You can combine this with [`RemoveUnusedResources` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~RemoveUnusedResources.html) before saving.

To save a PDF document to a `Stream` with packing and Fast Web View enabled:

### C#

```csharp

using GdPicture14;
using System;
using System.IO;

using GdPicturePDF gdPicturePDF = new GdPicturePDF();
using MemoryStream streamPDF = new MemoryStream();

GdPictureStatus status = gdPicturePDF.LoadFromFile(@"C:\temp\source.pdf");
if (status!= GdPictureStatus.OK)
{
    Console.WriteLine($"LoadFromFile failed: {status}");
    return;
}

status = gdPicturePDF.SaveToStream(streamPDF, true, true);
if (status!= GdPictureStatus.OK)
{
    Console.WriteLine($"SaveToStream failed: {status}");
}

```

### VB.NET

```vb

Imports GdPicture14
Imports System.IO

Using gdPicturePDF As New GdPicturePDF(),
      streamPDF As New MemoryStream()

    Dim status As GdPictureStatus = gdPicturePDF.LoadFromFile("C:\temp\source.pdf")
    If status <> GdPictureStatus.OK Then
        Console.WriteLine($"LoadFromFile failed: {status}")
        Return
    End If

    status = gdPicturePDF.SaveToStream(streamPDF, True, True)
    If status <> GdPictureStatus.OK Then
        Console.WriteLine($"SaveToStream failed: {status}")
    End If
End Using

```

## Saving a password-protected PDF to a stream

You can set two password types for a PDF document:

- User password (open password) — Enables opening and viewing a PDF document.

- Owner password (master password or permissions password) — Enables a user to copy, edit, or print a PDF document.

Both password types can be set for the same PDF. This means there are four possible scenarios:

- No passwords are set — Anyone can open and edit a PDF document.

- User password is set — The PDF document can be opened after providing the password. After opening the file, the user can then edit the PDF document.

- Owner password is set — The PDF document can be opened without the password. The user may have limited access to printing, editing, and copying content depending on the permissions settings, unless they provide the owner password to remove those restrictions.

- Both user and owner passwords are set — The file can only be opened by providing either password. With the user password, access to printing, editing, and copying content might be restricted depending on the permission settings. With the owner password, the user has no restrictions and can print, edit, and copy content.

Encrypting isn’t enabled for PDF/A documents.

To save a password-protected PDF to a `Stream`, use the [`SaveToStream` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~SaveToStream.html) overload.

### C#

```csharp

using GdPicture14;
using System;
using System.IO;

using GdPicturePDF gdPicturePDF = new GdPicturePDF();
using MemoryStream streamPDF = new MemoryStream();

GdPictureStatus status = gdPicturePDF.LoadFromFile(@"C:\temp\source.pdf");
if (status!= GdPictureStatus.OK)
{
    Console.WriteLine($"LoadFromFile failed: {status}");
    return;
}

status = gdPicturePDF.SaveToStream(
    streamPDF,
    PdfEncryption.PdfEncryption128BitAES,
    "",
    "owner",
    CanPrint: true,
    CanCopy: true,
    CanModify: false,
    CanAddNotes: false,
    CanFillFields: true,
    CanCopyAccess: false,
    CanAssemble: false,
    CanPrintFull: false);

if (status!= GdPictureStatus.OK)
{
    Console.WriteLine($"SaveToStream (encrypted) failed: {status}");
}

```

### VB.NET

```vb

Imports GdPicture14
Imports System.IO

Using gdPicturePDF As New GdPicturePDF(),
      streamPDF As New MemoryStream()

    Dim status As GdPictureStatus = gdPicturePDF.LoadFromFile("C:\temp\source.pdf")
    If status <> GdPictureStatus.OK Then
        Console.WriteLine($"LoadFromFile failed: {status}")
        Return
    End If

    status = gdPicturePDF.SaveToStream(
        streamPDF,
        PdfEncryption.PdfEncryption128BitAES,
        "",
        "owner",
        CanPrint:=True,
        CanCopy:=True,
        CanModify:=False,
        CanAddNotes:=False,
        CanFillFields:=True,
        CanCopyAccess:=False,
        CanAssemble:=False,
        CanPrintFull:=False)

    If status <> GdPictureStatus.OK Then
        Console.WriteLine($"SaveToStream (encrypted) failed: {status}")
    End If
End Using

```
---

## Related pages

- [Save a file from the annotation manager in C#](/guides/dotnet/save-a-file/annotation-to-jpg.md)
- [Save a file from the annotation manager in C#](/guides/dotnet/save-a-file/annotation-to-pdf.md)
- [Save a file from the annotation manager in C#](/guides/dotnet/save-a-file/annotation-to-tiff.md)
- [Save images in C#](/guides/dotnet/save-a-file/imaging-bitmap.md)
- [Save a file from the annotation manager in C#](/guides/dotnet/save-a-file/annotation-to-xmp.md)
- [Save images in C#](/guides/dotnet/save-a-file/imaging-byte-array.md)
- [Save images in C#](/guides/dotnet/save-a-file/imaging-ftp.md)
- [Save images in C#](/guides/dotnet/save-a-file/imaging-vector.md)
- [Save images in C#](/guides/dotnet/save-a-file/imaging-remote-url.md)
- [Save images in C#](/guides/dotnet/save-a-file/imaging.md)
- [Save images and PDF files in C#](/guides/dotnet/save-a-file.md)
- [Save PDF files in C#](/guides/dotnet/save-a-file/pdf-incremental-to-stream.md)
- [Save PDF files in C#](/guides/dotnet/save-a-file/pdf-incremental.md)
- [Save PDF files in C#](/guides/dotnet/save-a-file/pdf-local-storage.md)
- [Save PDF files in C#](/guides/dotnet/save-a-file/pdf.md)

