# Load a PDF file from local storage in C#

To load a document from local storage, use the [`LoadFromFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~LoadFromFile.html) from the [`GdPicturePDF` class](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF.html).

`LoadFromFile` supports PDF and TXT input:

- PDF files are loaded directly.

- TXT files are converted to a PDF document.

The optional `LoadInMemory` Boolean parameter controls whether the file content is loaded into memory:

- `false` (default) — Lower memory usage, but the source file stays locked while the document is open.

- `true` — Better manipulation performance and enables you to overwrite/delete the source file while working.

`LoadFromFile` returns a `GdPictureStatus`, and you should always verify that it equals `GdPictureStatus.OK`.

### C#

```csharp

using GdPicture14;

using GdPicturePDF pdf = new GdPicturePDF();

// Load without loading document content into memory.
GdPictureStatus status = pdf.LoadFromFile(@"C:\temp\source.pdf", false);
if (status!= GdPictureStatus.OK)
{
    Console.WriteLine($"Load failed: {status}");
    return;
}

pdf.CloseDocument();

// Load with document content in memory.
status = pdf.LoadFromFile(@"C:\temp\source.pdf", true);
if (status!= GdPictureStatus.OK)
{
    Console.WriteLine($"Load failed: {status}");
    return;
}

```

### VB.NET

```vb

Imports GdPicture14

Using pdf As New GdPicturePDF()
    ' Load without loading document content into memory.
    Dim status As GdPictureStatus = pdf.LoadFromFile("C:\temp\source.pdf", False)
    If status <> GdPictureStatus.OK Then
        Console.WriteLine($"Load failed: {status}")
        Return
    End If

    pdf.CloseDocument()

    ' Load with document content in memory.
    status = pdf.LoadFromFile("C:\temp\source.pdf", True)
    If status <> GdPictureStatus.OK Then
        Console.WriteLine($"Load failed: {status}")
        Return
    End If
End Using

```

### Loading a password-protected PDF

A PDF can define:

- A **user password** (open password), required to open the document.

- An **owner password** (permissions/master password), used to grant full permissions.

Depending on which password is set and which one is provided, behavior differs:

- **No passwords set** — Anyone can open and edit the PDF.

- **Only user password set** — The PDF opens only after entering the user password, and then the document can be edited.

- **Only owner password set** — The PDF can be opened without a password, but owner-level operations require the owner password.

- **Both passwords set** — Entering the user password enables viewing with restrictions; entering the owner password enables full permissions.

To work with encrypted PDFs:

1. Load the file.

2. Call the [`IsEncrypted` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~IsEncrypted.html).

3. If encrypted, call the [`SetPassword` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~SetPassword.html) with a user or owner password.

4. Verify the return status and check `IsEncrypted` again.

### C#

```csharp

using GdPicture14;

using GdPicturePDF pdf = new GdPicturePDF();
GdPictureStatus status = pdf.LoadFromFile(@"C:\temp\source.pdf", false);
if (status!= GdPictureStatus.OK)
{
    Console.WriteLine($"Load failed: {status}");
    return;
}

if (pdf.IsEncrypted())
{
    if (pdf.GetStat()!= GdPictureStatus.OK)
    {
        Console.WriteLine($"IsEncrypted failed: {pdf.GetStat()}");
        return;
    }

    status = pdf.SetPassword("user");
    if (status!= GdPictureStatus.OK)
    {
        Console.WriteLine($"SetPassword failed: {status}");
        return;
    }

    bool stillEncrypted = pdf.IsEncrypted();
    if (pdf.GetStat() == GdPictureStatus.OK)
    {
        Console.WriteLine($"Still encrypted: {stillEncrypted}");
    }
}

```

### VB.NET

```vb

Imports GdPicture14

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

    If pdf.IsEncrypted() Then
        If pdf.GetStat() <> GdPictureStatus.OK Then
            Console.WriteLine($"IsEncrypted failed: {pdf.GetStat()}")
            Return
        End If

        status = pdf.SetPassword("user")
        If status <> GdPictureStatus.OK Then
            Console.WriteLine($"SetPassword failed: {status}")
            Return
        End If

        Dim stillEncrypted As Boolean = pdf.IsEncrypted()
        If pdf.GetStat() = GdPictureStatus.OK Then
            Console.WriteLine($"Still encrypted: {stillEncrypted}")
        End If
    End If
End Using

```

After loading an encrypted PDF, `IsEncrypted()` returns `true` (if the call succeeds). After setting a correct password with `SetPassword`, `IsEncrypted()` returns `false`.
---

## Related pages

- [Load a PDF from a remote URL in C#](/guides/dotnet/load-a-file/pdf/from-remote-url.md)
- [Load a PDF from a stream in C# .NET](/guides/dotnet/load-a-file/pdf/from-stream.md)

