How to change the paper layout (name) in print preferences?
Hello guys
I have a function where I can set a print to as a default print.
Now I need to get the way to change the paper layout of it, I have a paper developed and I want to change it when I will print
a doc. Do you know any function or way to get that?
It is interesting that I can list all paper from my default printer with this function but I haven't found any way to set the paper with its name.
procedure TForm1.ListPaper;var HPrinter: THandle; Forms: array of TFormInfo1; Count, Needed, Returned: DWORD; i: Integer;begin Memo1.Clear; if OpenPrinter(nil, HPrinter, nil) then begin try if not EnumForms(HPrinter, 1, nil, 0, Needed, Returned) then begin // we should fail here since we didn't pass a buffer if GetLastError <> ERROR_INSUFFICIENT_BUFFER then RaiseLastOSError; Count := (Needed div SizeOf(TFormInfo1)) + 1; SetLength(Forms, Count); if EnumForms(HPrinter, 1, @Forms[0], SizeOf(TFormInfo1) * Count, Needed, Returned) then begin if Returned < Count then SetLength(Forms, Returned); for i := 0 to Returned - 1 do begin Memo1.Lines.Add(Format('Paper name: %s, Paper size: %dmm x %dmm', [Forms[i].pName, Forms[i].Size.cx div 1000, Forms[i].Size.cy div 1000])) end; end else RaiseLastOSError; end; finally ClosePrinter(HPrinter); end; end else RaiseLastOSError;end;
Look for an old answer by epasquier. Example needs little modification I thought.