Printer settings / defaults to handle paper trays?

edited February 2017 in FastReport VCL 5
Using latest fast reports 5 VCL Professional Edition and Berlin update 2

I am getting beat up on a deal where customers complain that paper tray settings are not saving.

They print a report to say a BROTHERS printer ... they select paper tray 2.

Close the program and come back.

Go to print ... and fire it off... goes to in this case maybe, paper tray 1 ... (or whatever default is maybe for that printer) ?

I do nothing paper/bin related.

I run the report, show print dialog can be true or false and call the report print call.

I searched around but have not come up with anything that really talks about this.

Apparently they are saying my program is not using the settings exactly that they have set as defaults for their printer.

One customer showed me where Tray 2 is their default.

If they bring up the printer dialog in my app before it prints, Tray is on AUTO ...

I currently have it so in a configuration screen that can pick a printer default for a certain report. Invoices goes to this printer, workorders to different one and so on.

Do I need to make it so it shows available printer trays for each printer?

Is that doable? How would I get those tray/bins ... and then save it off and then restore back to the FRX report engine to specify that bin/tray?

Comments

  • gpigpi
    edited 5:23AM
    Set tray in the page's setup window in the FR Designer
  • edited 5:23AM
    gpi wrote: »
    Set tray in the page's setup window in the FR Designer

    I have this running on thousands of machines over maybe 600 locations across the country.

    All different.

    So setting a tray in the designer, wouldn't that be an issue due to one place maybe have 3 trays, or 2... or just 1 paper pickup?

    I need it so either it saves this info the user selects when that print dialog comes up (which i dont think is the case, cause its the printer driver doing the work as its their UI elements)
    or a way for when users configure their printers in our program for different tasks, such as printing a workorder it goes to the "Workorder Printer" they have installed and then show
    any and all paper trays that printer may have. So they can then pick one of the trays if they have any, and go from there.

    Some locations have a printer with 3 trays... white, yellow, green paper..... quotes, workorder, invoice... so it would be nice to fire the print out to the proper tray.

    They will have printer installed 3 times... 3 names. But each one pointing to a tray as its default.

    Some people this is fine... others not. Looses the tray that is set to default in the driver. And when you look at the tray in the printer dialog, it would have "AUTO" maybe selected.


  • gpigpi
    edited 5:23AM
    You may set TfrxReportPage.Bin and TfrxReportPage.BinOtherPages before preparing of report on in the TfrxReport.OnPrintPage event
  • edited 5:23AM
    gpi wrote: »
    You may set TfrxReportPage.Bin and TfrxReportPage.BinOtherPages before preparing of report on in the TfrxReport.OnPrintPage event

    ok so there is 2 properties to set .... but how do I programmatically get the available bins?

    As mentioned, I have zero clue what a person has printer wise. Could be an old inkjet printer for all I know.

    I have a form that allows people to setup their defaults depending on what they are printing. I just save off the printer name string.

    Then I pass that string to FRX to tell it what printer to use.

    Is there anything that pulls the bin/trays available for a printer and be able to save that off and then pass it to frx before printing?

    Does FRX have anything like that built in? Do I need find a Windows call instead to find bin/trays? If gotta use a windows call, do those
    values 100% translate over to passing FRX? .... as mentioned, never touched bin/trays before.


  • edited 5:23AM
    Found this example @ http://www.swissdelphicenter.com/en/showcode.php?id=796

    Returned nothing.

    Found another example @ https://www.experts-exchange.com/questions/...nter-trays.html

    Which it returned

    u=7
    a=1
    T=258
    a=4

    Which to me... means nothing as I have no idea what the left side is...I assume the right side is an ID number of sorts.
    If so would this be the # to pass to the FRX report? But currently without any idea what the tray name is , or what printer that goes to,
    it doesn't do me any good.

    Printer I want to test against, only has 2 trays.


  • edited 5:23AM
    Found this @ http://delphi-kb.blogspot.com/2011/03/how-...-for-paper.html

    Has a call called GetBinnames

    It shows me the names of the bin ... modified it a bit to get name and number value


    Brother HL-6180DW series

    Auto Select - 7
    Tray1 - 1
    Tray2 - 2
    MP Tray - 258
    Manual - 4


    Tray2 - 2 .... that has my green paper in it... Tray1 has white paper.

    my code
      frxreport1.PrintOptions.Printer := 'Brother HL-6180DW series';
      frxreport1.PrepareReport(true);
      TfrxReportPage(frxreport1.Pages[0]).Bin := 2;
      TfrxReportPage(frxreport1.Pages[0]).BinOtherPages := 2;
      frxreport1.PrintOptions.ShowDialog := false;
      frxreport1.Print;
    

    Not sure if doing this right .... but it always comes out of Tray1


  • edited February 2017
    procedure TForm37.frxReport1PrintPage(Page: TfrxReportPage; CopyNo: Integer);
    begin
     Page.Bin := 2;
     Page.BinOtherPages := 2;
    end;
    

    If I do this ... this works.. came out of tray 2 finally.

    One problem here with the device i am testing against

    If i use the showdialog TRUE , the paper tray shows whatever. In this case for me it always shows

    First Page "Auto Select"
    Other Pages "Same as First Page"

    Is there any way that First page property in the printer driver says "Tray 2" by setting something before hand?

    That way if the bring up the printer dialog box, the print driver already has this printer set?

  • gpigpi
    edited 5:23AM
    See ticket #422856
    wrote:
    Use
    uses frxPrinter;
    
    frxPrinters.Printer.Bins
    
    to access all bins' list
    frxPrinters.Printer.BinNameToNumber(frxPrinters.Printer.Bins[0])
    
    will get first bin number
  • edited 5:23AM
    gpi wrote: »
    See ticket #422856
    gpi wrote: »
    Use
    uses frxPrinter;
    
    frxPrinters.Printer.Bins
    
    to access all bins' list
    frxPrinters.Printer.BinNameToNumber(frxPrinters.Printer.Bins[0])
    
    will get first bin number

    My hero ... I'll check this out ... I tried searching and searching and couldn't find anything that mentioned this.... am I that blind? >
  • edited 5:23AM
    This seems to work well, vs using the code I had found. Getting the bin names, Id's and such.

    The only thing I have to question if possible, is setting the printer bin BEFORE fastreports shows the printer dialog box.

    So I can pre-set it to Tray 2 ( value of 2 in this case ) and if they look at the printer properties in this case for the printer, it would have
    Tray 2 preset for them instead of "Auto Select" ...

    Because if the user is setup to show the printer dialog , they may want to print to a different bin for whatever reason... or maybe not.

    But if its set to "auto select" its gonna go to wrong tray most likely.

    Is there a way you know of to pre-set the bin value to the printer driver before that dialog comes up ?
  • gpigpi
    edited 5:23AM
    wrote:
    So I can pre-set it to Tray 2 ( value of 2 in this case ) and if they look at the printer properties in this case for the printer, it would have
    Tray 2 preset for them instead of "Auto Select" ...
    In this case you should change printer driver settings by Delphi's code
  • edited 5:23AM
    I did ... and printer dialog shows other wise...

    BUT

    If I use delphi's TPrinterSetupDialog to show it ... it works.

    So its like FastReports is whipping out my settings?

    Included is another video that shows how it works in the TPrinterSetupDialog as desired. This is what is the last part holding me up.


    https://www.youtube.com/watch?v=uGAhal8Ecik...eature=youtu.be



    What is interesting.. talked to on of my customers complaining.. he said up until recently, if they changed the paper source to tray 2 ... it would stick.
    Until they close my program and brought it back up. Now it always resets.

    I did upgrade FastReports some what recently too... any chances there is a deal that is always blasting out the settings back to some kind of blank/default settings?


  • edited 5:23AM
    Maybe work around for this is to NOT use the FR dialog ? ... possibly just a design problem of FR dialog box of how this is just all handled when it comes to trays.

    I want to be able to pre-set to a tray.

    I want it to show the printer dialog that the pre-set tray is selected. ( Like in TPrinterSetupDialog in my video )

    I want the tray the customer ends up picking or if the customer leaves as the pre-set one to be the one it prints to.
  • edited 5:23AM
    Nope... using the Delphi printer dialog didn't work either ... The tray settings get set..

    But when frx report print call is done, it ignores it. Assuming it wipes the driver settings back to a default.

    I can programatically set this all, but the whole issue comes down to

    If the user wants to see the dialog box before printing, I can't set the driver to the proper tray.
    And if the user picks a tray at this point, if I have it programmed in... their selection no longer matters.. cause i just put it back in my code
    to probably something else than what they picked.

    Am I crazy????

    Here is a video showing using the dialog box ... tray2 used ... picked by me, the user ..... but the printout comes out of tray 1 ...

    video @ https://youtu.be/r_2TQvSb7Ts

    Unless I am 100% missing something here that I am requesting the absolute impossible, someone please explain to me why this idea is impossible ?
  • edited 5:23AM
    Progress .... using the Delphi printer dialog box ...

    I can set the printer driver to a desired printer tray.... (if user decides)

    Show the printer dialog box.

    Get the printer bin selected ... as user might have changed it...

    Store it and use it in the FR onPrintPage event to use it.

    procedure ChangePrinterBin(ToBin: Integer);
    var
      ADevice, ADriver, APort: array [0 .. 255] of Char;
      DeviceHandle: THandle;
      DevMode: PDeviceMode; // A Pointer to a TDeviceMode structure
    begin
      Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
      if DeviceHandle = 0 then
      begin
        Printer.PrinterIndex := Printer.PrinterIndex;
        Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
      end;
      if DeviceHandle = 0 then
        Raise Exception.Create('Could Not Initialize TDeviceMode structure')
      else
        DevMode := GlobalLock(DeviceHandle);
      with DevMode^ do
      begin
        dmFields := DevMode^.dmFields or DM_DEFAULTSOURCE;
        dmDefaultSource := ToBin;
      end;
      if not DeviceHandle = 0 then
        GlobalUnlock(DeviceHandle);
    end;
    
    function GetPrinterBin:integer;
    var
      ADevice, ADriver, APort: array [0 .. 255] of Char;
      DeviceHandle: THandle;
      DevMode: PDeviceMode; // A Pointer to a TDeviceMode structure
    begin
      Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
      if DeviceHandle = 0 then
      begin
        Printer.PrinterIndex := Printer.PrinterIndex;
        Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
      end;
      if DeviceHandle = 0 then
        Raise Exception.Create('Could Not Initialize TDeviceMode structure')
      else
        DevMode := GlobalLock(DeviceHandle);
      result := devMode^.dmDefaultSource;
      if not DeviceHandle = 0 then
        GlobalUnlock(DeviceHandle);
    end;
    
    
    

    
    procedure TForm37.PrintClick(Sender: TObject);
    var
      Bin: Integer;
    begin
      Bin := frxPrinters.Printer.BinNameToNumber(Edit1.Text); // simple box to type in NAME of a tray
      ChangePrinterBin(Bin); // change to that BIN in the printer driver
      if PrinterSetupDialog1.Execute then
      begin
        fPrintTray := GetPrinterBin; // set a private var to the selected tray/bin 
        frxReport1.PrintOptions.Printer := Printer.printers[Printer.PrinterIndex];
        frxReport1.PrintOptions.Copies := Printer.Copies;
        frxReport1.PrintOptions.ShowDialog := false;
        frxReport1.PrepareReport;
        frxReport1.Print;
      end;
    end;
    
    procedure TForm37.frxReport1PrintPage(Page: TfrxReportPage; CopyNo: Integer);
    begin
      Page.Bin := fPrintTray; // now force the bin to be what the USER selected earlier... 
      Page.BinOtherPages := fPrintTray;
    end;
    
    

    Now I can set a tray.
    User can leave it be... or select a different tray.
    And the print out comes out of the correct tray.

    I am sure there will be some negative effect of doing this that I can't think of ... but the FR dialog lacks this support sadly so I have to use the more generic
    print dialog box in Delphi to get the job done right.

  • edited 5:23AM
    jdredd wrote: »
    Found this example @ http://www.swissdelphicenter.com/en/showcode.php?id=796

    Returned nothing.

    Found another example @ https://www.experts-exchange.com/questions/...nter-trays.html

    Which it returned

    u=7
    a=1
    T=258
    a=4

    Which to me... means nothing as I have no idea what the left side is...I assume the right side is an ID number of sorts.
    If so would this be the # to pass to the FRX report? But currently without any idea what the tray name is , or what printer that goes to,
    it doesn't do me any good.

    All in One Printer I want to test against, only has 2 trays.
    aybe work around for this is to NOT use the FR dialog ?

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.