Save as Image



i need an urgent help, before i will lose my mind! Smiley Happy

actually i want to do a simple thing, get a draft document and save it as tif file, in order to do that i must use the save as image method- which applied only for "view object", and "sheet metal"

i have a draft document, i tryed to reach both object-sheetmetal and view but i cant.

i get stuck in the windows collection- returns idispatch- and i need a window .

please view the code bellow...(it wont work cause i try to insert the idispatch into the windowptr)


DraftDocumentPtr drafDoc = doc;

WindowsPtr windows = drafDoc->Windows;

IDispatchPtr window = windows->Item((


WindowPtr windowp= window;

ViewPtr view = windowp->View;


please any ideas????


Posted by: Lior Bz
Post date: 2/21/2009 8:07:25 PM


RE: Save as Image


See CopyEmfToClipboard and .NET Discussion.  Basically you want to use the CopyEmfToClipboard function.  Search the forums for that keyword as well as the SDK for documentation.

Here is the example.

You will have to figure out how to get it to the image type that you want from there.


Posted by: Jason Newell
Post date: 2/21/2009 8:19:11 PM

RE: Save as Image


thanks fr your quick reply,

ive been trying this all morning but-

im writing in C++ so im kinda struggeling with a replacment for the "metafile" type

do you know what the equivalent in c++?

plus reading from clipboard is not so simple...


maybe you have a c++ sample?

Smiley Happy


Thank you very much!



Posted by: Lior Bz
Post date: 2/22/2009 1:01:55 AM

RE: Save as Image


There is plenty of room for improvement on this code but it gets the point across.  I attached the solution to the post so you would have everything.// ExtractDraftImages.cpp : Defines the entry point for the console application.//#include "stdafx.h"bool GetEncoderClsid(const GUID FormatID, CLSID* pClsid){ UINT num, size; Gdiplus::GetImageEncodersSize(&num, &size); Gdiplus::ImageCodecInfo* pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size)); Gdiplus::GetImageEncoders(num, size, pImageCodecInfo); bool found = false; for (UINT ix = 0; !found && ix ActiveDocument; pSections = pDraftDocument->Sections; pSection = pSections->WorkingSection; pSectionSheets = pSection->Sheets; for (LONG i = 1; i Count; i++) { pSheet = pSectionSheets->Item(i); /* Copy EMF to Clipboard */ hr = pSheet->CopyEMFToClipboard(); /* Ensure EMF format is available */ if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) { if (OpenClipboard((HWND)LongToHandle(pApplication->hWnd))) { /* Clipboard controls the handle! */ HENHMETAFILE hEmf = (HENHMETAFILE)GetClipboardData(CF_ENHMETAFILE); if (hEmf) { /* Gdiplus::Metafile */ Metafile metaFile(hEmf); CLSID encoder; if (!GetEncoderClsid(Gdiplus::ImageFormatTIFF, &encoder)) return E_FAIL; TCHAR szPath[MAX_PATH]; PathCombine(szPath, _T("C:\\"), pSheet->Name); PathAddExtension(szPath, _T(".tiff")); Gdiplus:Smiley Frustratedtatus status = metaFile.Save(szPath, &encoder); if (status == Gdiplus:Smiley Surprisedk) return E_FAIL; } CloseClipboard(); } } } /* Shut down Gdiplus */ Gdiplus::GdiplusShutdown(gdiplusToken); } pSheet = NULL; pSectionSheets = NULL; pSection = NULL; pSections = NULL; pDraftDocument = NULL; pApplication = NULL; CoUninitialize(); return 0;}


Posted by: Jason Newell
Post date: 2/22/2009 7:25:34 PM

RE: Save as Image



First- Thank you so much! you are such a big help....


i have one last question, i search the web and find it could mean so many things ...

in the

metaFile.Save(szPath, &encoder);

i get a genericerror.

too general, i saw on forums this could mean a graphic issue, or lots of other things...


do you know maybe why do i get that error?




Posted by: Lior Bz
Post date: 2/23/2009 3:27:54 AM

RE: Save as Image

I've read that permission issues is the most common cause. My example is writing to C:\. Does you app have rights to write a file there? Are you using Vista with UAC enabled?


I just noticed that: if (status == Gdiplus:Smiley Surprisedk) return E_FAIL;

is wrong. Don't return at that point because you need the Gdiplus::GdiplusShutdown(gdiplusToken);

to execute.


Posted by: Jason Newell
Post date: 2/23/2009 6:14:25 AM

RE: Save as Image

Hey, thanks again for the reply


i actually got all permissions and not using vista at all... im gonna keep trying to figure this out

could it be someting about a color pelete? cause i read that it might be the reason..


thanks you so much!


Posted by: Lior Bz
Post date: 2/23/2009 7:47:18 PM

Re: RE: Save as Image


Hi Jasson,

this link does not work.
Can you send me a new link.

Thank you.

Re: RE: Save as Image

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Dang, I can't find it either...


I'll rewrite the example and post a reply here with a link to the source. Which language are you needing?

Jason Newell
Applications Architect

Re: RE: Save as Image



it may be VB.NET or c #


many Thanks