I'm not sure if you've already got around to it...
But here is an attempt to set the custom papersize to A5.
(i can't test this for myself at this moment but i'm sure you can)
(You need to decide if it's 21x14,85 or 14,85x21)
I'm sure i did some things wrong (i.e. not setting a GlobalLock and Unlock on devmode etc.) but this should work for now. We can worry about cleaning it up when it works. (preferably as a separate function to set custom-paper size.)
uses Printers, OSPrinters, Windows, WinUtilPrn;
// ...
const
DMPAPER_USER = 0; // Why is this not defined in defines.inc ??????
procedure TForm1.Button1Click(Sender: TObject);
var
PDev: TPrinterDevice;
dmW: PDeviceModeW;
dmA: PDeviceModeA;
begin
PDev := TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex]);
if UseUnicode then
begin
dmW := PDev.DevModeW;
dmW^.dmFields := DM_PAPERLENGTH or DM_PAPERWIDTH or DM_PAPERSIZE or DM_SCALE;
dmW^.dmPaperLength := round(21 * 100); // 1/10 of mm
dmW^.dmPaperWidth := round(14.85 * 100); // 1/10 of mm
dmW^.dmPaperSize := DMPAPER_USER; // Custom Size, DMPAPER_A5
dmW^.dmScale := 100;
ResetDCW(Printer.Canvas.Handle, dmW);
end
else
begin
dmA := PDev.DevModeA;
dmA^.dmFields := DM_PAPERLENGTH or DM_PAPERWIDTH or DM_PAPERSIZE or DM_SCALE;
dmA^.dmPaperLength := round(21 * 100); // 1/10 of mm
dmA^.dmPaperWidth := round(14.85 * 100); // 1/10 of mm
dmA^.dmPaperSize := DMPAPER_USER; // Custom Size, DMPAPER_A5
dmA^.dmScale := 100;
ResetDCA(Printer.Canvas.Handle, dmA);
end;
Printer.BeginDoc;
// ... do you thing
Printer.EndDoc;
end;