Dim objWord As New Word.Application
Dim objDoc As Word.Document
Const CF_ENHMETAFILE As Integer = 14
objDoc = objWord.Documents.Open("C:\TEST\Test1.doc")
objWord.ActiveDocument.Select()
objWord.Selection.CopyAsPicture()
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 EncoderParameters = New EncoderParameters
ep.Param(0) = New
System.drawing.imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100)
Dim codecs() As ImageCodecInfo =
ImageCodecInfo.GetImageEncoders()
Dim iciInfo As ImageCodecInfo
Dim item As ImageCodecInfo
For Each item In codecs
If (item.MimeType = "image/jpeg") Then iciInfo = item
Next
objImageWriter.Save("c:\test\test1.jpg", iciInfo, ep)
objImageWriter.Dispose()
End If
Public Class ClipboardAPI
<DllImport("user32.dll", EntryPoint:="OpenClipboard", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function OpenClipboard(ByVal hWnd As IntPtr) As Boolean
End Function
<DllImport("user32.dll", EntryPoint:="EmptyClipboard", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EmptyClipboard() As Boolean
End Function
<DllImport("user32.dll", EntryPoint:="SetClipboardData", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> Public Shared Function
SetClipboardData(ByVal uFormat As Integer, ByVal ByValhWnd As IntPtr) As
IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="CloseClipboard", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function CloseClipboard() As Boolean
End Function
<DllImport("user32.dll", EntryPoint:="GetClipboardData", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function GetClipboardData(ByVal uFormat As Integer) As
IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="IsClipboardFormatAvailable", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function IsClipboardFormatAvailable(ByVal uFormat As
Integer) As Short
End Function
End Class
My guess would be you aren't going to be able to use the clipboard
non-interactively.. HTH
"mabosch" <mab...@discussions.microsoft.com> wrote in message
news:76E8D03E-F203-4BED...@microsoft.com...
The clipboard, to my knowledge, is an in-process function that is made
available via explorer.exe and the Shell32 extensions (i.e. the Windows
shell, the Start button, desktop, taskbar, etc) - and those require a
windows context, which you won't be able to get, from a webapp.
Good luck
"mabosch" <mab...@discussions.microsoft.com> wrote in message
news:301B839E-8CBC-42FD...@microsoft.com...
> Thanks for your answer, I Have in the web.config impersonate =true with
> user
> and Password.
>
> can I force UIPermissionClipboard.AllClipboard , I really don't know how
> to
> use it in VB
>
> Thank you again
>
> Marcelo
I Discover that the data is in the clipboard, because the following works in
asp.net
......
objWord.Selection.CopyAsPicture()
objWord.Documents.Add()
objWord.Documents.Item(2).Activate()
objWord.ActiveDocument.Select()
objWord.Selection.Paste()
objWord.ActiveDocument.SaveAs("c:\test\MyNewDocument.doc")
Copy & Paste works inside the Word, the problem is that I can't read it from
my page, I'm thinking to use another application to paste and save (but I
can't find it because the paint is not a COM and when I paste (manually) in
Photodraw only paste text, It loose the format).
What doyou suggest ?
Regards
Marcelo