views:

359

answers:

3

As I'm working to add custom printing to my application, I've settled on using TMetafile to create the pages, then using it to preview &/or print, but I'm finding the documentation lacking.

Are there any good resources for learning the ins and outs of working with TMetafile and TMetafileCanvas?

+2  A: 

The ins and outs of working with TMetaFile/Canvas are more related to meta files than to the TMetaFile and TMetaFileCanvas implementations from my traumatic experience of working with it. Aka, you should rather look for information on how EMF (or WMF) works. The Delphi implementation simply calls windows to do everything as I understand it.

You may wish to be more specific what it is you need to know though beyond a walk through guide on how to do it.

PetriW
A: 

I haven't looked into it much myself, but I know that the QuickReports code uses metafiles under the hood to create the print preview and to send to the printer. If you've got the source for that, it may be helpful.

Scott W
+1  A: 

It's actually simpler than you think...

here's some of my code:

var
   m: TMetafile;
   mc: TMetafileCanvas;
begin
   m := TMetafile.Create;
   m.Width := 1000;
   m.Height := 1000;
   mc := TMetafileCanvas.Create(m, 0);
   //use mc just like any canvas...
   mc.Free;
   // you can use m for anything you want, preview, print, save ...etc.
end;

To copy the metafile to the clipboard:

Clipboard.Assign(m);

To Save to an emf file:

m.SaveToFile(filename);

I've used that to print a metafile in a fastreport.

Osama ALASSIRY