Subject Re: printer paper source
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Thu, 23 Jul 2020 07:51:07 +0530
Newsgroups dbase.getting-started
Attachment(s) get_printer.prgload_ini.prg

On 23.07.2020 00:00, Mustansir Ghor wrote:
> Dear All
>
> In the helpfile, it is mentioned that paper source can be set on the fly. If the printer is setup on the computer which is development computer, then if printer name is specified in the report designer, the paper source can easily be selected.
>
> But if printer is on the remote computer, then we get numeric for paper source in the report designer. Under this scenario is there a way to translate these numbers into varous paper sources options available like autoselect, Tray 1, Tray 2, etc

Good Morning Mustansir,
Changing default paper sizes / printers for every installation can be a
PITA.

So I developed the attached code for altering the default report
settings at deployment.

I am using it.You can have a look.

Another thing before compiling a report for deployment open it in editor
and remove/comment out  the printer = " " line which specifies the printer.

The report will adopt the default printer of the deployment machine

Regards
Akshat



/*
  -----------------------------------------------------------------
    Description:

      Altering the printer for every report on different installations
      is tedious. chooseprinter() offers full choice but at times speed is of
      essence. Get_printer.prg program captures the normally required parameters and
      save them to an ini file passed to it as parameter.This will save
         color
         duplex
         orientation
         papersize
         papersource
         printername

    Programmers:

       Akshat Kapoor

    History:

                12 Feb 2019 Sharing the ready to deploy code for the first time.

    Instantiation/use:
      Just place get_printer.prg and load_ini in the required directory.
      
      get_printer("report1.ini") will save the required parameters in report1.ini
      (A one time event or as and when required from any form )
      
      When running the report
      set procedure to report1.rep
      r = new report1report()
      load_ini("report1.ini","r.printer")
      
      will restore the required defaults.
      thereafter
      r.render()
      
      No more changing of code.
      with change of printer.
              
               Some Code which I am actually using
               set procedure to p_sales.rep
               r = new p_salesreport()
               r.salesdatamodule1.sales.params["invoice"].value = str(minvoice,10,0)
               r.salesdatamodule1.sales.params["location"].value = mlocat
               r.salesdatamodule1.sales.requery()
               r.title = "Invoice no. "+str(minvoice,10,0)
               load_ini("cashmemo.ini","r.printer")
               r.render()
      
      Additional requirements :
         Both load_ini.prg and get_printer.prg are required.
         They compliment each other.
      
                for Any further suggestions please email me  akshatkapoor76 at gmail dot com
   ----------------------------------------------------------------
*/
parameters file_name
r = new report()
if r.printer.chooseprinter()
   of = new file()
   of.create(file_name)
   of.writeln("color[N]"+r.printer.color)
   of.writeln("duplex[N]"+r.printer.duplex)
   of.writeln("orientation[N]"+r.printer.orientation)
   of.writeln("papersize[N]"+r.printer.papersize)
   of.writeln("papersource[N]"+r.printer.papersource)
   of.writeln("printername[C]"+r.printer.printername)
   of.close()
endif

/*
  -----------------------------------------------------------------
    Description:

      Altering the printer for every report on different installations
      is tedious. chooseprinter() offers full choice but at times speed is of
      essence. Get_printer.prg program captures the normally required parameters and
      save them to an ini file passed to it as parameter.This will save
         color
         duplex
         orientation
         papersize
         papersource
         printername

    Programmers:

       Akshat Kapoor

    History:

                12 Feb 2019 Sharing the ready to deploy code for the first time.

    Instantiation/use:
      Just place get_printer.prg and load_ini in the required directory.
      
      get_printer("report1.ini") will save the required parameters in report1.ini
      (A one time event or as and when required from any form )
      
      When running the report
      set procedure to report1.rep
      r = new report1report()
      load_ini("report1.ini","r.printer")
      
      will restore the required defaults.
      thereafter
      r.render()
      
      No more changing of code.
      with change of printer.
              
               Some Code which I am actually using
               set procedure to p_sales.rep
               r = new p_salesreport()
               r.salesdatamodule1.sales.params["invoice"].value = str(minvoice,10,0)
               r.salesdatamodule1.sales.params["location"].value = mlocat
               r.salesdatamodule1.sales.requery()
               r.title = "Invoice no. "+str(minvoice,10,0)
               load_ini("cashmemo.ini","r.printer")
               r.render()
      
      Additional requirements :
         Both load_ini.prg and get_printer.prg are required.
         They compliment each other.
      
                for Any further suggestions please email me  akshatkapoor76 at gmail dot com
   ----------------------------------------------------------------
*/

parameters mfile,obj_name
infile = new file()
if file(mfile)
   infile.open(mfile)
   do while not infile.eof()
      mstr = infile.readln()
      prop_name = left(mstr,at("[",mstr)-1)
      prop_value= right(mstr,len(mstr)-at("]",mstr))
      prop_type=substr(mstr,at("[",mstr)+1,1)
      if prop_type = "N"
         prop_value = val(prop_value)
      endif
      if prop_type = "D"
         prop_value = ctod(prop_value)
      endif
      if prop_type = "L"
         prop_value = iif(upper(prop_value)="TRUE",true,false)
      endif
      mvar = obj_name+"."+prop_name
      &mvar = prop_value
   enddo
endif