This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/dotnet/load-a-file/pdf/from-local-storage.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. C# .NET load PDF file from local storage | Nutrient .NET SDK

To load a document from local storage, use the LoadFromFile method from the GdPicturePDF class.

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.

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

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.
  3. If encrypted, call the SetPassword method with a user or owner password.
  4. Verify the return status and check IsEncrypted again.
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}");
}
}

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