Avatar of hidrau
hidrau
Flag 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
Delphi

Avatar of undefined
Last Comment
hidrau

8/22/2022 - Mon
Sinisa Vuk

You want to set paper size actually?
Look for an old answer by epasquier. Example needs little modification I thought.
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
Sinisa Vuk

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hidrau

ASKER
Thanks
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23