Changing Paper Tray when Printing

Hi all !!

I would like to be able to Change the Printer Tray in my program, So it is possible to print the first page from the upper tray and the rest from the lower tray.

Is there a generel way to do this, whitout knowing what kind of printer it is.... I know the printer might not have more than one tray, but in those cases it schould be ignored

kwang080897Asked:
Who is Participating?
 
Fatman121898Connect With a Mentor Commented:
Hi, it's me again.

Here I'm posting a part of code I use, which has been inspired by Inthe. Actually, I have not tried to change the printer tray, but successfully changed the printer paper. I suppose you'llneed something similar, especially the statement:
"pDMode^.dmDefaultSource:=DMBIN_UPPER;".


procedure TReportForm.PrintReportBtnClick(Sender: TObject);
  var
    Device : array[Byte] of Char;
    Driver : array[Byte] of Char;
    Port   : array[Byte] of Char;
    hDMode : THandle;
    pDMode : PDEVMODE;
    I:Cardinal;
    PRN:textfile ;
  begin
    Printer.GetPrinter(Device, Driver, Port, hDMode);
    if hDMode <> 0 then
      begin
        pDMode := GlobalLock(hDMode);
        if pDMode <> nil then
          begin
           {Set to A3}
           pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
           pDMode^.dmPaperSize := DMPAPER_A3;
           pDMode^.dmDefaultSource := DMBIN_UPPER; {!!!}
           GlobalUnlock(hDMode);
          end;
       end;
    Printer.Orientation:=poPortrait;//poLandscape;
    Printer.Canvas.Font:=ReportMemo.Font;
    Printer.Canvas.Font.Size:=PrinterFontSize;
    AssignPRN(PRN);
    Rewrite(PRN);
    for I:=1 to  8 do Writeln(PRN);
    for I:=0 to ReportMemo.Lines.Count-1 do
      Writeln(PRN,CharRow(' ',8),ReportMemo.Lines[I]);
    CloseFile(PRN);
  end;

Enjoy!
Jo.
0
 
okemotoCommented:
This is dependant on the printer driver and hardware and is highly proprietary in nature. You would need to not only check the printer/driver attached, but you will also need the printer specific API since this is not a "standard" printing option even under Windows.
0
 
kwang080897Author Commented:
Okomoto :

Hi !

Thanks for participating, i will just reopen this question for a few days.

You might be right, and if thats the case i will of course grade you answer.

but i really need this function, and i just can't bellive It can't be done in a more generel way.

I can see that in Word 97 it is posible to use one tray for first page and another for the rest.

That way would work for me to... (to obtain a list of trays and choose)

Kim
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Fatman121898Commented:
Hello Kwang,

A few months ago I had a similar problem. Posting question I got answer from Inthe.
There is a unit called Windows.pas in Borland\Delphi\Source\RTL\WIN directory.It contains a lot of definitions for paper sizes, paper bins etc. I'm sure you will find there what you need. See under headings <paper selections> and <bin selections>.
Hope helps.

Jo.
0
 
intheCommented:
yes see jo's last comment that is the way to change paper and bin sizes :-)
0
 
kwang080897Author Commented:
Hi !!!

Jo:

Thanks ! - I will test this in a few days and return.... Havent got the time now


Inthe :

Hope You enjoy the recykling, if this works i will be more than happy to reward you too - after all it is your solution.


Kim

I'll Be back in a few days
0
 
kwang080897Author Commented:
Almost Perfect !!

Except I'll have to Close the Printer with a Printer.Enddoc if i want to change the tray (oterwise Printer is Busy )- this means that my one job will look like more jobs when printing (using enddoc every time)...

Any suggestions ??
0
 
intheCommented:
Sorry i dont know if its possible to change tray "on the fly" using delphi's tprinter object without enddoc :-(
0
 
kwang080897Author Commented:
Sorry !!!

I Forgot about this one.....

Fatman : Please post an answer

Inthe... I will submit a question for your old answer as well

Thanks


Kim
0
 
kwang080897Author Commented:
Well - guess you dont have to..... i could myself..
0
All Courses

From novice to tech pro — start learning today.