Your code looks correct, and works fine on my system (Win 11, PDF printer). What might be helpful, is to add unit
OSPrinters to the uses clause (in addition to unit
Printers) in order to get correct access to OS-specific printing routines.
Please note that specifying the LEFTMARGIN as 100 pixels is not a very good idea because the printer resolution usually is much different from the screen resolution, and thus the 100 px may be too small. Better to think in device-independent units, e.g. millimeters, and provide a conversion function to pixels:
const
INCH = 25.4; // 1 inch is 25.4 mm
function mmToPx(mm: Double; APixelsPerInch: Integer): Integer;
begin
Result := round(mm / INCH * APixelsPerInch);
end;
const
LEFT_MARGIN_MM = 10; // Left margin should be 10 mm
var
LeftMargin: Integer; // Left margin in pixels, to be passed to the printer
begin
with Printer do
begin
...
LeftMargin := mmToPx(LEFT_MARGIN_MM, XDPI);
...
...