DocumentSave(Stream, SaveFormat) Method

Saves the document to a stream using the specified format.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public SaveOutputParameters Save(
	Stream stream,
	SaveFormat saveFormat


Type: System.IOStream
Stream where to save the document.
Type: Aspose.WordsSaveFormat
The format in which to save the document.

Return Value

Type: SaveOutputParameters
Additional information that you can optionally use.


Shows how to save a document to a stream.
Document doc = new Document(MyDir + "Document.docx");

using (MemoryStream dstStream = new MemoryStream())
    doc.Save(dstStream, SaveFormat.Docx);

    // Rewind the stream position back to zero so it is ready for next reader
    dstStream.Position = 0;
Saves a document page as a BMP image into a stream.
Document doc = new Document(MyDir + "Rendering.docx");

MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.Bmp);

// Rewind the stream and create a .NET image from it
stream.Position = 0;

// Read the stream back into an image
using (Image image = Image.FromStream(stream))
    // ...Do something
Shows how to save a document to the JPEG format using the Save method and the ImageSaveOptions class.
// Open the document
Document doc = new Document(MyDir + "Rendering.docx");
// Save as a JPEG image file with default options
doc.Save(ArtifactsDir + "Rendering.SaveAsImage.DefaultJpgOptions.jpg");

// Save document to stream as a JPEG with default options
MemoryStream docStream = new MemoryStream();
doc.Save(docStream, SaveFormat.Jpeg);
// Rewind the stream position back to the beginning, ready for use
docStream.Seek(0, SeekOrigin.Begin);

// Save document to a JPEG image with specified options
// Render the third page only and set the JPEG quality to 80%
// In this case we need to pass the desired SaveFormat to the ImageSaveOptions constructor 
// to signal what type of image to save as
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Jpeg);
imageOptions.PageIndex = 2;
imageOptions.PageCount = 1;
imageOptions.JpegQuality = 80;
doc.Save(ArtifactsDir + "Rendering.SaveAsImage.CustomJpgOptions.jpg", imageOptions);

See Also