Convert word document all pages in one image to display in picturebox

hi
i have a code here that gets the value from a stream/dialogbox pass it to an instance of aspose.words.document

and save the document as memstream , picturebox1 is inside panel2.
but when check picturebox1 its only displaying the firstpage of the document. what im expecting is the whole document would be saved as single image no matter how many pages the document has, this the only way that i could think of viewing word doc in my app since aspose doesnt have a document viewer included, unlike aspose.cells that they have aspose.cells.griddesktop as excel viewer…
thanks…

Dim memstream As MemoryStream = New MemoryStream 
Dim worddoc As Aspose.Words.Document = New Aspose.Words.Document(showdialog1.FileName)

worddoc.Save(memstream, Aspose.Words.SaveFormat.Jpeg)
Panel2.Visible = True
PictureBox1.Image = Image.FromStream(memstream)

memstream.close

Hi Ivan,

Thanks for your inquiry. Please follow up this workaround:

'Dim worddoc As Aspose.Words.Document = New Aspose.Words.Document(showdialog1.FileName)
Dim doc As Aspose.Words.Document = New Aspose.Words.Document("D:/TEMP/FSWS.docx")
'To Combine all images into single object
Dim images As New List(Of System.Drawing.Bitmap)()
Dim finalImage As System.Drawing.Bitmap = Nothing
Dim width As Integer = 0
Dim height As Integer = 0
Dim pageCounter As Integer = 0, [stop] As Integer = doc.PageCount

While pageCounter < [stop]
    Dim options As New Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg)
    options.PageIndex = pageCounter

    'create a Bitmap from the file and add it to the list
    Dim memstream As New MemoryStream
    doc.Save(memstream, options)
    Dim bitmap As New System.Drawing.Bitmap(memstream)
    width += bitmap.Width
    height = If(bitmap.Height > height, bitmap.Height, height)
    images.Add(bitmap)

    pageCounter += 1
End While
finalImage = New System.Drawing.Bitmap(width, height)

'get a graphics object from the image so we can draw on it
Using g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(finalImage)

    'set background color
    'g.Clear(System.Drawing.Color.Black)

    'go through each image and draw it on the final image
    Dim offset As Integer = 0
    For Each image As System.Drawing.Bitmap In images
        g.DrawImage(image, New System.Drawing.Rectangle(offset, 0, image.Width, image.Height))
        offset += image.Width

    Next
End Using
'Save it Pysical memory(optional)
finalImage.Save("C:\\stitchedImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Dim pan As New Panel
pan.Location = New Point(5, 5)
pan.Size = New Size(300, 300)
pan.AutoScroll = True
Dim pic As New PictureBox

'Change the path/name of image file
pic.Image = finalImage 'Image.FromStream(memstream)
pic.SizeMode = PictureBoxSizeMode.AutoSize
pan.Controls.Add(pic)
Me.Controls.Add(pan)

In case of any ambiguity, please let me know.

hi
i already tried the code that you’ve written for me, but i just notice that the images adds to the side not below the previews images, can you point me to the specific area of the code that i need to change so the new image adds below the current image/s…
thanks alot.

Hi Ivan,

Thanks for your inquiry. Please change your lines as follow:
(also set each image background color white or whatever)

'finalImage = New System.Drawing.Bitmap(width,height)
finalImage = New
System.Drawing.Bitmap(height, width)
'g.DrawImage(image, New System.Drawing.Rectangle(offset, 0, image.Width, image.Height))
g.DrawImage(image, New System.Drawing.Rectangle(0, offset, image.Width, image.Height))

In case of any ambiguity,please let me know.