Link to home
Create AccountLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

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;

Open in new window



thanks
Alex
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

You want to set paper size actually?
Look for an old answer by epasquier. Example needs little modification I thought.
Avatar of hidrau

ASKER

Hello Sinisa,

I have a specific size created named " NeoVida "
I would like to set it by its name. I haven't found any example how to do that yet.
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of hidrau

ASKER

Thanks