GdPicture.NET.14
GdPicture14 Namespace / GdPictureDocumentConverter Class / SaveAsDOCX Method / SaveAsDOCX(Stream) Method
A stream object where the current document is saved to as a DOCX file. This stream object must be initialized before it can be sent into this method and it should stay open for subsequent use.

If the output stream is not opened for both reading and writing, the method will fail returning the GdPictureStatus.InvalidParameter status.

Example





In This Topic
SaveAsDOCX(Stream) Method
In This Topic
This method converts the currently loaded document to DOCX and saves it to an instantiated stream object.
Syntax
'Declaration
 
Public Overloads Function SaveAsDOCX( _
   ByVal Stream As Stream _
) As GdPictureStatus
public GdPictureStatus SaveAsDOCX( 
   Stream Stream
)
public function SaveAsDOCX( 
    Stream: Stream
): GdPictureStatus; 
public function SaveAsDOCX( 
   Stream : Stream
) : GdPictureStatus;
public: GdPictureStatus SaveAsDOCX( 
   Stream* Stream
) 
public:
GdPictureStatus SaveAsDOCX( 
   Stream^ Stream
) 

Parameters

Stream
A stream object where the current document is saved to as a DOCX file. This stream object must be initialized before it can be sent into this method and it should stay open for subsequent use.

If the output stream is not opened for both reading and writing, the method will fail returning the GdPictureStatus.InvalidParameter status.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.
Remarks
Keep noted that the output stream should be open for both reading and writing and should be closed/disposed by the user as well.
Example
Converting and saving a PDF document to a DOCX file using a stream.
Using gdpictureDocumentConverter As New GdPictureDocumentConverter()
    Dim status As GdPictureStatus = gdpictureDocumentConverter.LoadFromFile("input.pdf", GdPicture14.DocumentFormat.DocumentFormatPDF)
    If status = GdPictureStatus.OK Then
        Dim oFileStream As New System.IO.FileStream("output.docx", System.IO.FileMode.Create)
        gdpictureDocumentConverter.DocxImageQuality = 80
        status = gdpictureDocumentConverter.SaveAsDOCX(oFileStream)
        If status = GdPictureStatus.OK Then
            MessageBox.Show("The file has been saved successfully.", "GdPicture")
        Else
            MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "GdPicture")
        End If
        oFileStream.Dispose()
    Else
        MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "GdPicture")
    End If
End Using
using GdPicture14;
            
 using GdPictureDocumentConverter converter = new();
            
 var status = converter.LoadFromFile("input.pdf");
 if (status != GdPictureStatus.OK)
 {
     throw new Exception(status.ToString());
 }
            
 using var fs = new FileStream("output.docx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            
 status = converter.SaveAsDOCX(fs);
 if (status != GdPictureStatus.OK)
 {
     throw new Exception(status.ToString());
 }
            
 Console.WriteLine("The input document has been converted to a docx file");
See Also