Printing Charts crash my computer lazarus / 39-Graphics ---------------------------------------------------------------------- drkppvch · 2013-12-07 01:16 Hello, I have the following code to print my charts, but I had a QuickBooks V303 PDF Converter as my default printer and when I try to pint the chart with it, it crashed  my computer. I also try using my normal printer HP and nothing happen. The only way i can print the data is using PrimoPDF, here is my done: Code: [Select]procedure TForm1.Button16Click(Sender: TObject); var    MyPrinter : TPrinter;     Begin   if PrinterSetupDialog1.execute then begin   MyPrinter := Printer;   MyPrinter.BeginDoc;     myPrinter.Canvas.CopyRect(Classes.Rect(0, 0, myPrinter.PaperSize.Width, myPrinter.PaperSize.Height),      Chart3.Canvas, Classes.Rect(0, 0, Chart3.Width, Chart3.Height));   MyPrinter.EndDoc; end;   end; Is my code wrong or incomplete?, I can only use the PrimoPDF to print my charts and I have not been able to find what will cause it to not work with my HP printer or crash with the QuickBooks. I do not expect it to work with QuickBooks PDF Converter, but I was not expecting to crash my computer. Any help is appreciated. ---------------------------------------------------------------------- Cyrax · 2013-12-07 08:13 Which version of Lazarus and FPC are you using? In what kind of OS are you running them? ---------------------------------------------------------------------- drkppvch · 2013-12-07 08:59 I have Lazarus Version 1.0.14 FCP Version 2.6.2 Running on Windows Vista, The project I am working on will be use in XP, Vista ---------------------------------------------------------------------- howardpc · 2013-12-07 11:14 Try this (though no doubt you'll want to set margins etc. as well): Code: [Select]procedure TForm1.Button16Click(Sender: TObject); var   r: TRect; begin   if PrinterSetupDialog1.Execute then begin     r := Rect(0, 0, Printer.PageWidth, Printer.PageHeight);     printer.BeginDoc;     try       Chart3.PaintOnCanvas(Printer.Canvas, r)     finally       Printer.EndDoc;     end;   end; end; ---------------------------------------------------------------------- Cyrax · 2013-12-07 11:49 Quote from: drkppvch on December 07, 2013, 09:59:53 amI have Lazarus Version 1.0.14 FCP Version 2.6.2 Running on Windows Vista, The project I am working on will be use in XP, Vista Both XP and Vista are 32-bits? ---------------------------------------------------------------------- drkppvch · 2013-12-07 12:45 Vista is 64-Bits - that is the computer that crash when selected the QuickBooks pdf converter as printer. XP is 32 - Have not tested it as it is the main office computer and dont want to crash it. ---------------------------------------------------------------------- wp · 2013-12-07 15:57 I am replying to your first posting which I did not see... Probably your issues are due to the drawing infrastructure of TAChart. TAChart uses its own drawing machinery and therefore can support a variety of drawing enviroments. I guess that it's just not possible to copy the canvas of the chart directly to that of the printer. Please have a look at the example "printdemo" which you can find in your Lazarus installation (lazarus\componens\tachart\demo\print). It is working, for sure: Code: [Select]uses   ..., TAPrint, ... procedure TForm1.PrintClick(Sender: TObject); const   MARGIN = 10; var   r: TRect;   d: Integer; begin   if not PrintDialog1.Execute then exit;   Printer.BeginDoc;   try     r := Rect(0, 0, Printer.PageWidth, Printer.PageHeight div 2);     d := r.Right - r.Left;     r.Left += d div MARGIN;     r.Right -= d div MARGIN;     d := r.Bottom - r.Top;     r.Top += d div MARGIN;     r.Bottom -= d div MARGIN;     Chart1.Draw(TPrinterDrawer.Create(Printer), r);   finally     Printer.EndDoc;   end; end;