We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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

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..

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)


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)


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


'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


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



In case of any ambiguity, please let me know.


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)<o:p></o:p>

'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))<o:p></o:p>

In case of any ambiguity,please let me know.