I have tried below code but its converting only one page of i.e starting page of .doc file to .gif file.
Is there is any solution to convert the multipage file to .GIF file...
Expand|Select|Wrap|Line Numbers
- And any thing wrong with below code....
- Dim objWord As New Microsoft.Office.Interop.Word.Application
- Dim objDoc As Microsoft.Office.Interop.Word.Document
- Const CF_ENHMETAFILE As Integer = 14
- objDoc = objWord.Documents.Open("D:\Guide.doc")
- objWord.ActiveDocument.Select()
- objWord.Selection.CopyAsPicture()
- 'objDoc.SaveAs2("D:\Charge Back\test2.gif")
- Dim ip As IntPtr
- Dim metaFile As System.Drawing.Imaging.Metafile
- Dim bRet As Boolean
- bRet = ClipboardAPI.OpenClipboard(Me.Handle)
- If bRet = True Then
- 'Verify the clipboard contains data available
- 'as an enhanced metafile.
- bRet = ClipboardAPI.IsClipboardFormatAvailable(CF_ENHMETAFILE) <> 0
- End If
- If bRet = True Then
- 'Store the clipboard's contents in the IntPtr.
- ip = ClipboardAPI.GetClipboardData(CF_ENHMETAFILE)
- End If
- 'Verify the IntPrt contains data before proceeding. Passing
- 'an empty IntPtr to System.Drawing.Imaging.Metafile results
- 'in an exception.
- If Not IntPtr.Zero.Equals(ip) Then
- metaFile = New System.Drawing.Imaging.Metafile(ip, True)
- ClipboardAPI.CloseClipboard()
- Dim image As System.Drawing.Image = metaFile
- 'Me.PictureBox1.Image = metaFile
- Dim objImageWriter As Image = New Bitmap(image.Width, image.Height)
- Dim objGraphics As Graphics = Graphics.FromImage(objImageWriter)
- objGraphics.Clear(Color.White)
- 'objGraphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
- objGraphics.DrawImage(image, 0, 0, image.Width, image.Height)
- image.Dispose()
- objGraphics.Dispose()
- Dim ep As Imaging.EncoderParameters = New Imaging.EncoderParameters
- ep.Param(0) = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100)
- Dim codecs() As Imaging.ImageCodecInfo = Imaging.ImageCodecInfo.GetImageEncoders()
- Dim iciInfo As Imaging.ImageCodecInfo
- Dim item As Imaging.ImageCodecInfo
- Dim frame As Integer
- frame = 0
- Dim page As Bitmap
- page = Nothing
- For Each item In codecs
- If (item.MimeType = "image/gif") Then iciInfo = item
- Next
- objImageWriter.Save("D:\doc.gif", iciInfo, ep)
- 'For i As Integer = 1 To objImageWriter.GetFrameCount(FrameDimension.Page) - 1
- ' objImageWriter.SelectActiveFrame(FrameDimension.Page, i)
- ' 'mygif.Save("c:\test_" & i & ".gif")
- ' objImageWriter.SaveAdd(objImageWriter, ep)
- 'Next
- objImageWriter.Dispose()