Author: Jonas Bilinkevicius
How to set the PixelsPerInch property of a TPrinter
Answer:
When changing printers, be aware that fontsizes may not always scale properly. To
ensure proper scaling, set the PixelsPerInch property of the font after changing
the printer index property. Be sure not to make the change until you have started
the print job.
Here are two examples:
1 uses2 Printers;
3 4 var5 MyFile: TextFile;
6 begin7 Printer.PrinterIndex := 2;
8 AssignPrn(MyFile);
9 Rewrite(MyFile);
10 Printer.Canvas.Font.Name := 'Courier New';
11 Printer.Canvas.Font.Style := [fsBold];
12 Printer.Canvas.Font.PixelsPerInch := GetDeviceCaps(Printer.Canvas.Handle,
13 LOGPIXELSY);
14 Writeln(MyFile, 'Print this text');
15 System.CloseFile(MyFile);
16 end;
17 18 uses19 Printers;
20 21 begin22 Printer.PrinterIndex := 2;
23 Printer.BeginDoc;
24 Printer.Canvas.Font.Name := 'Courier New';
25 Printer.Canvas.Font.Style := [fsBold];
26 Printer.Canvas.Font.PixelsPerInch := GetDeviceCaps(Printer.Canvas.Handle,
27 LOGPIXELSY);
28 Printer.Canvas.Textout(10, 10, 'Print this text');
29 Printer.EndDoc;
30 end;