To load a PDF document from a previously instantiated stream, use the LoadFromStream method from the GdPicturePDF class.

LoadFromStream accepts:

  • A Stream parameter (required).
  • An optional OwnStream Boolean parameter (default: false).

When OwnStream is:

  • false — You’re responsible for disposing the stream.
  • trueGdPicturePDF will dispose the stream when it’s no longer needed (for example, after CloseDocument).

LoadFromStream only supports PDF input and returns a GdPictureStatus, which should always be checked.

You can also load a PDF from a COM IStream by using the LoadFromIStream method.

To load a PDF document from a stream, use the following code:

using GdPicture14;
using System;
using System.IO;
// OwnStream = false (default): caller disposes the stream.
using (Stream streamPdf = new FileStream(@"C:\temp\source.pdf", FileMode.Open, FileAccess.Read))
using (GdPicturePDF pdf = new GdPicturePDF())
{
GdPictureStatus status = pdf.LoadFromStream(streamPdf);
if (status != GdPictureStatus.OK)
{
Console.WriteLine($"LoadFromStream failed: {status}");
return;
}
pdf.CloseDocument();
}
// OwnStream = true: GdPicturePDF owns the stream lifecycle.
using (GdPicturePDF pdf = new GdPicturePDF())
{
Stream streamPdf = new FileStream(@"C:\temp\source.pdf", FileMode.Open, FileAccess.Read);
GdPictureStatus status = pdf.LoadFromStream(streamPdf, true);
if (status != GdPictureStatus.OK)
{
Console.WriteLine($"LoadFromStream failed: {status}");
return;
}
// Closing the document also releases owned stream resources.
pdf.CloseDocument();
}