Load an Office Document for Conversion from a Stream in C#

To load and convert a PDF document from a stream object to a different file type, use the LoadFromStream method from the GdPictureDocumentConverter class. This method requires the following parameters:

  • Stream — The stream object of a PDF document.

  • DocumentFormat — The file format represented as a member of the DocumentFormat enumeration.

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

// Create a stream object from a PDF document file.
using Stream streamFile = new FileStream(@"C:\temp\source.pdf", FileMode.Open);
// Create a new `gdpictureDocumentConverter` object.
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Specify the file format.
GdPicture14.DocumentFormat format = GdPicture14.DocumentFormat.DocumentFormatPDF;
// Load the stream object to the `gdpictureDocumentConverter` object.
gdpictureDocumentConverter.LoadFromStream(streamFile, format);
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
' Create a stream object from a PDF document file.
Using streamFile As Stream = New FileStream("C:\temp\source.pdf", FileMode.Open)
' Create a new `gdpictureDocumentConverter` object.
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Specify the file format.
    Dim format As GdPicture14.DocumentFormat = GdPicture14.DocumentFormat.DocumentFormatPDF
    ' Load the stream object to the `gdpictureDocumentConverter` object.
    gdpictureDocumentConverter.LoadFromStream(streamFile, format)
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
End Using

To load and convert a Word document from a stream object to a different file type, use the LoadFromStream method from the GdPictureDocumentConverter class. This method requires the following parameters:

  • Stream — The stream object of a Word document.

  • DocumentFormat — The file format represented as a member of the DocumentFormat enumeration.

To load and convert a Word document from a stream object, use the following code:

// Create a stream object from a Word document file.
using Stream streamFile = new FileStream(@"C:\temp\source.docx", FileMode.Open);
// Create a new `gdpictureDocumentConverter` object.
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Specify the file format.
GdPicture14.DocumentFormat format = GdPicture14.DocumentFormat.DocumentFormatDOCX;
// Load the stream object to the `gdpictureDocumentConverter` object.
gdpictureDocumentConverter.LoadFromStream(streamFile, format);
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
' Create a stream object from a Word document file.
Using streamFile As Stream = New FileStream("C:\temp\source.docx", FileMode.Open)
' Create a new `gdpictureDocumentConverter` object.
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Specify the file format.
    Dim format As GdPicture14.DocumentFormat = GdPicture14.DocumentFormat.DocumentFormatDOCX
    ' Load the stream object to the `gdpictureDocumentConverter` object.
    gdpictureDocumentConverter.LoadFromStream(streamFile, format)
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
End Using

To load and convert an image from a stream object to a different file type, use the LoadFromStream method from the GdPictureDocumentConverter class. This method requires the following parameters:

  • Stream — The stream object of an image.

  • DocumentFormat — The file format represented as a member of the DocumentFormat enumeration.

To load and convert an image from a stream object, use the following code:

// Create a stream object from an image file.
using Stream streamFile = new FileStream(@"C:\temp\source.jpeg", FileMode.Open);
// Create a new `gdpictureDocumentConverter` object.
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Specify the file format.
GdPicture14.DocumentFormat format = GdPicture14.DocumentFormat.DocumentFormatJP2;
// Load the stream object to the `gdpictureDocumentConverter` object.
gdpictureDocumentConverter.LoadFromStream(streamFile, format);
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
' Create a stream object from an image file.
Using streamFile As Stream = New FileStream("C:\temp\source.jpeg", FileMode.Open)
' Create a new `gdpictureDocumentConverter` object.
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Specify the file format.
    Dim format As GdPicture14.DocumentFormat = GdPicture14.DocumentFormat.DocumentFormatJP2
    ' Load the stream object to the `gdpictureDocumentConverter` object.
    gdpictureDocumentConverter.LoadFromStream(streamFile, format)
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
End Using

To load and convert a bitmap image from a stream object to a different file type, use the LoadFromStream method from the GdPictureDocumentConverter class. This method requires the following parameters:

  • Stream — The stream object of a bitmap image.

  • DocumentFormat — The file format represented as a member of the DocumentFormat enumeration.

To load and convert a bitmap image from a stream object, use the following code:

// Create a stream object from a bitmap image file.
using Stream streamFile = new FileStream(@"C:\temp\source.bmp", FileMode.Open);
// Create a new `gdpictureDocumentConverter` object.
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Specify the file format.
GdPicture14.DocumentFormat format = GdPicture14.DocumentFormat.DocumentFormatBMP;
// Load the stream object to the `gdpictureDocumentConverter` object.
gdpictureDocumentConverter.LoadFromStream(streamFile, format);
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
' Create a stream object from a bitmap image file.
Using streamFile As Stream = New FileStream("C:\temp\source.bmp", FileMode.Open)
' Create a new `gdpictureDocumentConverter` object.
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Specify the file format.
    Dim format As GdPicture14.DocumentFormat = GdPicture14.DocumentFormat.DocumentFormatBMP
    ' Load the stream object to the `gdpictureDocumentConverter` object.
    gdpictureDocumentConverter.LoadFromStream(streamFile, format)
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
End Using

To load and convert an SVG image from a stream object to a different file type, use the LoadFromStream method from the GdPictureDocumentConverter class. This method requires the following parameters:

  • Stream — The stream object of an SVG image.

  • DocumentFormat — The file format represented as a member of the DocumentFormat enumeration.

To load and convert an SVG image from a stream object, use the following code:

// Create a stream object from an SVG image file.
using Stream streamFile = new FileStream(@"C:\temp\source.svg", FileMode.Open);
// Create a new `gdpictureDocumentConverter` object.
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Specify the file format.
GdPicture14.DocumentFormat format = GdPicture14.DocumentFormat.DocumentFormatSVG;
// Load the stream object to the `gdpictureDocumentConverter` object.
gdpictureDocumentConverter.LoadFromStream(streamFile, format);
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
' Create a stream object from an SVG image file.
Using streamFile As Stream = New FileStream("C:\temp\source.svg", FileMode.Open)
' Create a new `gdpictureDocumentConverter` object.
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Specify the file format.
    Dim format As GdPicture14.DocumentFormat = GdPicture14.DocumentFormat.DocumentFormatSVG
    ' Load the stream object to the `gdpictureDocumentConverter` object.
    gdpictureDocumentConverter.LoadFromStream(streamFile, format)
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
End Using

To load and convert a TIFF image from a stream object to a different file type, use the LoadFromStream method from the GdPictureDocumentConverter class. This method requires the following parameters:

  • Stream — The stream object of a TIFF image.

  • DocumentFormat — The file format represented as a member of the DocumentFormat enumeration.

To load and convert a TIFF image from a stream object, use the following code:

// Create a stream object from a TIFF image file.
using Stream streamFile = new FileStream(@"C:\temp\source.tiff", FileMode.Open);
// Create a new `gdpictureDocumentConverter` object.
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Specify the file format.
GdPicture14.DocumentFormat format = GdPicture14.DocumentFormat.DocumentFormatTIFF;
// Load the stream object to the `gdpictureDocumentConverter` object.
gdpictureDocumentConverter.LoadFromStream(streamFile, format);
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
' Create a stream object from a TIFF image file.
Using streamFile As Stream = New FileStream("C:\temp\source.tiff", FileMode.Open)
' Create a new `gdpictureDocumentConverter` object.
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Specify the file format.
    Dim format As GdPicture14.DocumentFormat = GdPicture14.DocumentFormat.DocumentFormatTIFF
    ' Load the stream object to the `gdpictureDocumentConverter` object.
    gdpictureDocumentConverter.LoadFromStream(streamFile, format)
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
End Using

To load and convert any file from a stream object to a different file type, use the LoadFromStream method from the GdPictureDocumentConverter class. This method requires the following parameters:

  • Stream — The stream object of any file.

  • DocumentFormat — The file format represented as a member of the DocumentFormat enumeration.

The list of supported files is available on the Supported File Types page.

To load and convert an Excel file from a stream object, use the following code:

// Create a stream object from an Excel file.
using Stream streamFile = new FileStream(@"C:\temp\source.xlsx", FileMode.Open);
// Create a new `gdpictureDocumentConverter` object.
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Specify the file format.
GdPicture14.DocumentFormat format = GdPicture14.DocumentFormat.DocumentFormatXLSX;
// Load the stream object to the `gdpictureDocumentConverter` object.
gdpictureDocumentConverter.LoadFromStream(streamFile, format);
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
' Create a stream object from an Excel file.
Using streamFile As Stream = New FileStream("C:\temp\source.xlsx", FileMode.Open)
' Create a new `gdpictureDocumentConverter` object.
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Specify the file format.
    Dim format As GdPicture14.DocumentFormat = GdPicture14.DocumentFormat.DocumentFormatXLSX
    ' Load the stream object to the `gdpictureDocumentConverter` object.
    gdpictureDocumentConverter.LoadFromStream(streamFile, format)
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
End Using