Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export MFC CView into vectorial format

With my MFC application, I am able to print my CDocument on screen using the CView class. Basically, I use the CDC class to write text and draw polygons on screen to provide a view representation of my document.

Now let's say I would like to use that output view in Microsoft Word.

From a user point a view and without anymore developer work, I can :

  • copy-paste my drawing to word : this produces a raster BMP file which I am able to paste in Word
  • print my drawing and use a PDF exporter : this produces a vectorial PDF file which is light and zoom-able, but not easy to reuse in Word.

These two effortless solutions are great because I can keep the exact layout of my view, but have cons (raster or format)

Another way to solve my problem would be to write SVG or VML but I would not get the same layout and this would require a lot of work.

Is there a library to do the same kind of PDF export / print mechanism into a standard format ?

What would you suggest ? Thanks a lot.

like image 725
Michel Hua Avatar asked Jul 15 '26 19:07

Michel Hua


1 Answers

To draw your view into a Enhanced Meta File, first read the documentation @ MSDN: http://msdn.microsoft.com/en-us/library/427wezx1%28v=VS.80%29.aspx

Here is an example, how this works:

CMetaFileDC MFDC;

CRect rect(0,0,width,height);

MFDC.CreateEnhanced(NULL,NULL,rect,NULL);
MFDC.SetBkMode(TRANSPARENT);
MFDC.SetMapMode(MM_HIMETRIC);

CDC tempDC;
tempDC.CreateCompatibleDC(&MFDC);
MFDC.SetAttribDC(tempDC.m_hDC);

// now you draw into the DC like it was your original view

HENHMETAFILE hEnhMetaFile = MFDC.CloseEnhanced();
HENHMETAFILE hEMF = NULL;
hEMF = CopyEnhMetaFile(hEnhMetaFile,"C:\\Temp\\Test.emf");
DeleteEnhMetaFile(hEMF);
DeleteEnhMetaFile(hEnhMetaFile);
like image 62
dwo Avatar answered Jul 18 '26 16:07

dwo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!