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
LVL 1
hidrauAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
You want to set paper size actually?
Look for an old answer by epasquier. Example needs little modification I thought.
hidrauAuthor Commented:
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.
Sinisa VukSoftware architectCommented:
Ok. But have you look at this example from old mail replay...
might look like:
var
     Device, Driver, Port: array[0..80] of Char;
     DevMode: THandle;
     pDevmode: PDeviceMode;
   begin
     // Get printer device name etc.
     Printer.GetPrinter(Device, Driver, Port, DevMode);
     // force reload of DEVMODE
     Printer.SetPrinter(Device, Driver, Port, 0) ;
     // get DEVMODE handle
     Printer.GetPrinter(Device, Driver, Port, DevMode);
     If Devmode <> 0 Then Begin
       // lock it to get pointer to DEVMODE record
       pDevMode := GlobalLock( Devmode );
       If pDevmode <> Nil Then
       try
         With pDevmode^ Do Begin
           // modify form
           StrLCopy( dmFormname, 'NeoVida', CCHFORMNAME-1 );
           // tell printer driver that dmFormname field contains
           // data it needs to inspect.
           dmFields := dmFields or DM_FORMNAME;
         End;
      finally
        // unlock devmode handle.
        GlobalUnlock( Devmode );
      end;
     End; 
   end;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hidrauAuthor Commented:
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.