How to print? lazarus / 13-General ---------------------------------------------------------------------- seb · 2004-09-04 08:39 Hi all, I'm trying to rewrite a project I made with Kylix and so far Lazarus is working great; But it seems that I can't print the same way... I need to print a form containing an invoice; With Kylix Open Edition I had to make a screen capture. Not perfect, but it worked. With Lazarus it seems that I can't even user Printer.Printers to fill a combobox with the printers list... Any idea of how I can do the job? Is there something like TCustomForm.GetFormImage? (I could'nt do that with Kylix Open...). Seb. ---------------------------------------------------------------------- Anonymous · 2004-09-05 13:52 Well, I don't know if I was clear enough :-) What I exactly need for now is: - Get the list of all available printers, - Fill a combo box with this list. Then I think I'll find a way to print the invoice on the printer selected with the cb. Seb. ---------------------------------------------------------------------- scismondo · 2004-09-06 07:46 Let's continue... (this time I'm registered, but the two previous messages are from me). I've looked at my previous project, here is what I was doing in Kylix: Code: [Select] i := 0; while i < Printer.Printers.Count do         begin         ListeImpr.Items.Add(Printer.Printers.Strings[i]);         i := i + 1;         end; With Lazarus / fpc I don't even have Printer.Printers.Count... Maybe there's another way? (better way?). I'll take any idea! On the other hand, I've tried to use the Cups for Lazarus package, but I don't understand how to "install" it in Lazarus (I'm using the 0.9.2 RPM). TIA, Seb. ---------------------------------------------------------------------- scismondo · 2004-09-07 10:17 Well, I've managed to install cups4lazarus (I used the CVS source of Lazarus instead of the RPM this time). I can use the sample app. Now, I can try the old method I used in Kylix, making a sreen capture with only the dialog box I want, but isn't there a better way to do the job? Seb. ---------------------------------------------------------------------- scismondo · 2004-09-09 08:53 Nobody knows how I can generate a picture of a form? ---------------------------------------------------------------------- scismondo · 2004-09-12 09:51 Well, I had an answer from the author of cups4lazarus; It might be useful to someone else, so here's the procedure, it creates a snapshot a a dialog box and saves it as a BMP file: Update your Lazarus with last CVS source and use this code : Code: [Select] procedure TForm1.Button1Click(Sender: TObject); var SnapShotBitmap: TBitmap; begin SnapShotBitmap:=TBitmap.Create; SnapShotBitmap.LoadFromDevice(Canvas.Handle); SnapShotBitmap.SaveToFile('./snapshot.bmp'); SnapShotBitmap.Free; end; // and for print the result add this if Printer.ExecuteSetup<>srCancel then Printer.CUPSPrintFile('./snapshot.bmp'); Seb. ---------------------------------------------------------------------- windy · 2007-08-22 21:34 Hi sorry to bring up an old thread this works, but if another window is over the top, that is captured as well. Anyone know how to get around that? (other than Form1.show to bring it to the front window) ? thanks procedure TForm1.Button1Click(Sender: TObject); var SnapShotBitmap: TBitmap; begin SnapShotBitmap:=TBitmap.Create; SnapShotBitmap.LoadFromDevice(Canvas.Handle); SnapShotBitmap.SaveToFile('./snapshot.bmp'); SnapShotBitmap.Free; end;