Paradox Community

Items in pnews.paradox-discussions

Subject:Re: Printing in Pdox Version 9
Date:Fri, 13 Oct 2017 16:13:14 +0100
From:John Wright <john@jfwright.co.uk>
Newsgroups:pnews.paradox-discussions
Wow Mark,
Thanks for setting out your suggestions which I will ponder over in a 
while. What a thing to have to do though to have to set the printer.
I'm very grateful for the information and see what I can set up.

On 12/10/2017 16:47, Mark Bannister wrote:
> John:
> 1:  Always use the printersetOptions method to set your defaults after 
> setting the correct printer.
> 
> Second item:
> If you are printing the report directly (not previewing first) you need 
> to switch the printer to the pdf printer first before running the 
> report, then set the options.
> 
> Here's some terrible code that may help you:
> 
> EXAMPLE OF CALLING THE TERRIBLE CODE:
> 
> ;display the quality log report
> method ReportQualityLog(loOnScreen logical; false default
> )   logical
> var
>      answer         logical
>      mysettings     dynarlo
> 
>     myopts PrinterOptionInfo
>     RI  ReportPrintInfo
>     myr2        report
>   ;  saveprn                 string
>   params                     dynarattype
> endvar
> 
> 
> try
>      libCommon.Settings(mySettings,true)
> 
>      ErrorTraponwarnings(yes)
> ; CODE
>   params["saveprn"] = ""
>   params["loonscreen"] = loOnScreen
> params["Subject"] = "[QualityLog:"+ string(date()  )+"]"
>   params["File_FilePath"] = libcommon.getConstant ( "PDFLocker" )
>   params["File_NewFileName"] = libcommon.getConstant ( "PDFLocker" )
> 
>     myopts.Orientation = PrintPortrait
> 
>                        + 
> iif(libstrings.cmlastcharST(libcommon.getConstant ( "PDFLocker" 
> ))="\\","","\\")
>                                                         
+ "QualityLog_ 
> "+string(date())
> 
> ;/// display a menu with available printers, letting user pick where to 
> print
>            if NOT libCommon.printerPick (  myopts ,params ) then
>               fail ( UserError + 1 , "" )
> 
>            endIf
> 
> ;// do the printing
>        ri.name = ":mngrforms:I0qualitylog.rsl"
>        ri.panelOptions = PrintClipToWidth
>        ri.Orient = PrintPortrait
> 
>        if params["loOnScreen"] then
>           myr2.open(ri)
>           sleep()
>            myr2.DesignModified=false
>        else
>               myr2.print(ri)
>               sleep()
>        endif
> 
> 
> 
> 
> ;ENDCODE^^^^^^
>      answer = true
> onfail
>      libCommon.Errorlogshow(libCommon.Errorlogger())
>      answer=false
>     params["File_Action"] = File_CancelActionCT
>              libMisc.File_WaitonNewFile( params)
> endtry
> libCommon.Settings(mySettings,false)
> 
> libcommon.printerPick_Restore ( Params )
> 
> return(answer)
> endMethod
> 
> { 10-2008
>   Front end to PrinterSetup
>   lets you select a printer
>   and then calls PrinterSetup
> 
>   example :
>   try
>   saveprn =""
>     myopts.Orientation = PrintPortrait
>        myopts.Duplex = prnHorizontal
> 
>      if NOT libCommon.printerPick(loOnscreen,myopts,saveprn) then
>         fail(UserError+1,"")
>      endif
> 
>     ..do printing
> 
>    onfail
>       ..
>    endtry
>     ;restore default
> if saveprn<>"" then
>     if not printerSetCurrent(SavePrn) then
>        msgStop("Print Config","Did not restore printer.")
>     endif
> endif
>     }
> 
> 
> proc __checkPDF(  )logical
> 
> var
>      answer         logical
>      mysettings     dynarlo
> endvar
> try
>         if getConstant ( "PDFPRN" ) = "" or getConstant ( "PDFLocker" ) 
> = "" then
>             if msgQuestion ( "Constant(s) Undefined" , "You must set the 
> preferences for PDF printing."
>                     + iif ( getConstant ( "PDFPRN" ) = "" , "\nSet PDF

> Printer, Printing local consant" , "" )
>                     + iif ( getCOnstant ( "PDFLocker" ) = "" , "\nSet

> PDF folder, PDF User's Constant" , "" )
>                     + "\n\nOpen Preferences form?" ) = "Yes" then
>                  LibForms.openForm ( "" , "s0constantsNew" , "mngrforms"

> , true , blank ( ) )
>             endIf
>             answer = False
>         else
>             answer = true
>        endIf
> 
> 
> ;code
> 
> 
> 
> 
> 
> onfail
>          
> Errorlogshow(ErrorloggerAddMsg(FormNameGL+"printerpick.__checkPDF"))
>    ;  libCommon.Errorclosetc(ordertc,answer)
>      answer=false
> endtry
> 
> return(answer)
> endproc
> 
> method PrinterPick ( ;var     loOnScreen          Logical ;False -
>                       myopts PrinterOptionInfo
>                   ;   , var    stsaveprn           String
>                      , var params dynarattype
>                      ;, var stans                 string
;what we 
> selected if blank will display menu
>                      ) Logical      ;// returns false if did not
print!
>        var
>             answer                       Logical
>             mysettings dynarlo
>             mypop
>                , mypop2                  PopUpMenu
>            myprn
>                                          String
>             CurrPRNInfo printerinfo
>             stprn       string
>             loonscreen LOgical
>             stsaveprn,stParams, stans string
>        endVar
>        try
>           openlibs() ;insp_20141203
>        ;     SetMouseShape ( Mousewait , true )
>             ;  DelayScreenUpdates(yes)
>             ErrorTraponwarnings ( yes )
>            ; printerGetInfo ( CurrPRNInfo )
>              stParams="loOnScreen:LFalse" ;// was there an error?
>              +","+MenuPickCT  ;// email, Print to PDF, etc
>               +",File_FilePath:A"  ;\\ path to new file default = H:
>              ; +",File_FileExtension:A" ;\\ file extension to look for 
> w/o .
>               +",File_FileMatchName:A" ;\\ if we know some part of the 
> new file name supply it
>               +",File_NewFileName:A" ;\\ what to call our new file, 
> blank will use random
>               +",Stripplus:Ltrue,ignoreExtraParams:LTrue"
> 
>      if NOT libmisc.cmArrayCheckAT(params, stparams) then
>              fail(userError+4,"paramters invalid")
>      endif
>             stSavePrn = ""
>             myprn = ""
>             stans = params[MenuPickCT]
> 
>             if stans = "" then
>                if NOT PrinterPick_Menus( mypop ) then
>                    fail(userError+4,"")
>                 endif
> 
>                mypop.addtext ( "Cancel" )
>                stans = mypop.show ( )
>                params[MenuPickCT] = stans
>                SetMouseShape ( Mousewait , true )
>             endif
>             loOnScreen = ( stans = "Print Preview" )
>             switch
>                  case stans = "Print Preview" :
>                       loOnScreen = True
> 
>               {   case stans = "Printer: " + CurrPRNInfo.devicename:
>                       loOnScreen = False
>                   }
>                  case stans = "Print to PDF" or stans ="Email" :
>                      if NOT __checkPDF() then
>                         fail(userError+1,"")
>                      endif
>                      params["Email_SendEmail"] = (Stans="Email")
>                       loOnScreen = False
>                       myprn =  getConstant ( "PDFPRN" )
>                       ;// set up pdf printer and the printerpickRestore

> will take care of the rest
>                        params["File_Action"] = File_SetupActionCT
> 
>                        if NOT libmisc.File_WaitonNewFile( params )
then
>                            fail ( USErError + 4 , "" )
>                       endIf
>                  case stans = "Cancel" or stans = "" :
>                       fail ( UserError + 2 , "" )   ;insp_20141203

> changed to user cancel
> 
>                  case stans.match("Printer: ..", stprn ) :
> 
>                       myprn = stprn
>                       loOnScreen = False
>                  otherwise :
>                             ;// not aprinter choise
> 
>             endSwitch
>             if myprn <> "" or loOnScreen then
>                if NOT loOnScreen then
>                  if NOT PrinterSetup ( myprn , myopts , stsaveprn ) then
>                       fail ( UserError + 1 , "" )
>                  endIf
>                 endif
>                  answer = True
>             else
>                 answer = False
>             endIf
>             params["Saveprn"] = stsaveprn
>             params["loOnScreen"] = loOnScreen
> 
>             Menu_Parkmenu() ;// move the menu bar out of the way of the 
> report
> 
>        onFail
>             Errorlogshow ( Errorloggeraddmsg (FormNameGL+"PRinterPick" ) )
>             ;  libCommon.Errorclosetc(,answer)
>              Timercontrol( TimerWaitonFileCT, true )
>             answer = false
>        endTry
>           ;libCommon.Settings(mySettings,false)
>           ;SetMouseShape(MouseArrow,false)
>           ;DelayScreenUpdates(No)
>        return ( answer )
> EndMethod
> 
> method PrinterPick_Menus(var mypop popupmenu)   logical
> 
> var
>      answer         logical
>      mysettings     dynarlo
>        prnar                             Array [ ] String
>     mypop2 popupmenu
>     li1 longint
>     CurrPRNInfo printerinfo
> endvar
> try
>    openlibs()
>    ;    libCommon.Settings(mySettings,true)
>      ;SetMouseShape(Mousewait,true)
>     ;ErrorTraponwarnings(yes)
> 
>     ;code
> 
> 
> 
>   printerGetInfo ( CurrPRNInfo )
> 
>             mypop.addtext ( "Print Preview" )
>             mypop.addtext ( "Printer: " + CurrPRNInfo.devicename )
> 
>             enumprinters ( prnar )
>             for li1 from 1 to prnar.size()
>                mypop2.addtext("Printer: "+ prnar[ li1 ] )
>             endfor
> 
>             mypop.addpopup ( "Print to.." , mypop2 )
>             mypop.addtext ("Print to PDF")
>             mypop.addtext ("Email")
> 
> 
> 
> 
> 
>      answer = true
> onfail
>          Errorlogshow(ErrorloggerAddMsg(FormNameGL+"PrinterPick_Menus"))
>    ;  libCommon.Errorclosetc(ordertc,answer)
>      answer=false
> endtry
> ;Settings(mySettings,false)
> ;SetMouseShape(MouseArrow,false)
> ;DelayScreenUpdates(No)
> return(answer)
> endMethod
> 
> 
> 
> {
>   after printing we will restore the printer
>   we will also launch wait on file and email if applicable
> 
> }
> method  printerPick_Restore (var params dynarattype) logical
> var
>      answer         logical
>      mysettings     dynarlo
>     stParams  string
> endvar
> 
> 
> try
>    openlibs()
>         Settings(mySettings,true)
>     ;SetMouseShape(Mousewait,true)
>    ;DelayScreenUpdates(yes)
>      ErrorTraponwarnings(yes)
> ; CODE
> 
>     stParams="saveprn:A" ;// name of printer to restore
>              +",loError:LFalse" ;// was there an error?
>              +","+MenuPickCT  ;// email, Print to PDF, etc
> 
>               +",Stripplus:Ltrue,ignoreExtraParams:LTrue"
> 
>      if NOT libmisc.cmArrayCheckAT(params, stparams) then
>              fail(userError+4,"paramters invalid")
>      endif
> 
>        if params["saveprn"] <> "" then
>                  if not printerSetCurrent (  params["saveprn"] ) then
>                       libforms.bb_Statusmsg("Did not restore printer",

> statusmsgwarningCT )
>                  endIf
>        endIf
> 
> 
> ;ENDCODE^^^^^^
>     answer = True
> onfail
>      Errorlogshow(ErrorloggerAddMsg(FormNameGL+"printerPick_Restore"))
>      ;    libCommon.Errorclosetc(,answer)
>     Timercontrol( TimerWaitonFileCT, true )
>      answer=false
> endtry
> Settings(mySettings,false)
> ;SetMouseShape(MouseArrow,false)
> ;DelayScreenUpdates(No)
> return(answer)
> endMethod
> 
> 
> { 10-2008  Better call is to use PrinterPick which calls this method
>     it allows you to pick a printer
> 
> }
> method printerSetup ( myprinter         String
>                       , var      myopts PrinterOptionInfo
>                       , var        saveprn           
String
>                       ) Logical
> {
> 
> myprinter = name of printer to change to if ""  then
>     use windows default printer
> 
> myopt = printer options --set only ones you need to change
> saveprn = returns the name of the old printer so you can restore it
> 
> example of use
> 
> if NOT printerSetup(LibCommon.GetConstant("SINGLELABELPRN",Labopts, 
> saveprn) then
>     errro proces
> else
> ;do some printing
> endif
> ;restore default
> if not printerSetCurrent(SavePrn) then
>     msgStop("Print Config","Did not restore printer.")
> endif
> 
> }
>        var
>             ranswer                      String
>             answer                       Logical
>             Curropts PrinterOptionInfo
>             Labopts PrinterOptionInfo
>             holdopts PrinterInfo
>             lar                          Array [ ] String
>             arPrinters ,
>                arPrnNames ,
>                par                       Array [ ] String
>             stDrvName ,
>                stPrnName ,
>                stPrnInfo                 String
>             i                            SmallInt
>             CurrPRNInfo printerinfo
>             hold                         String
>             Changedit                    Logical
>             ;\\     Saveprn    string
>             labtc                        TCursor
>             labellen                     SmallInt
>             lrep                         Report
>        endVar
>        changedit = false
>        try
>           openlibs()
>             enumPrinters ( arPrinters ) ;\\ Get a list of installed 
> printers.
>             ;\\  arprinters.view()
>             printerGetOptions ( CurrOpts )
>             ;\\curropts.view()
>             printerGetInfo ( CurrPRNInfo )
>             saveprn = CurrPrnInfo.DeviceName + "," + 
> CurrPrnInfo.DriverName + "," + CurrPrnInfo.PortName
>             if myprinter.search ( "," ) > 0 then
>                  myprinter.breakapart ( par , "," )
>                  myprinter = par [ 1 ]
>             endIf
>             answer = false
>             for i from 1 to arPrinters.size ( )
>                  stPrnInfo = arPrinters [ i ]
>                  ;\\ Info is separated by commas.
>                  stPrnInfo.breakApart ( arPrnNames , "," )
>                  ;\\ After breakApart, array item 1 is the printer name,
>                  ;\\ array item 2 is the driver name.
>                  hold = arprnNames [ 1 ] .lower ( )
>                  ;\\  if (arprnNames[3]= MYPRINTER)  then
>                  libforms.BB_StatusMsg(hold , statusMsgOKCT)
>                  if MYPRINTER = "" then
>                       changedit = true
>                       ;\\look for default printer since none specified
>                       printerSetCurrent ( StPrnInfo )
>                       printerGetInfo ( holdopts )
>                       if holdopts.DefaultPrinter then
>                            answer = True
>                            answer = printerSetOptions ( MYOPTS
)
>                            quitLoop
>                       endIf
>                  else
>                       if ( arprnNames [ 1 ] .lower ( ) = MYPRINTER.lower

> ( ) ) then
>                            answer = true
>                            if printerSetCurrent ( stPrnInfo )
then
>                                 ;msgInfo("Current printer:",
arPrnNames[1])
>                                 changedit = true
>                                 ;\\ answer = printerSetOptions(MYOPTS)
>                                 if not printerSetOptions
( MYOPTS ) then
>                                      errorshow ( )
>                                      answer = false
>                                 endIf
>                            else
>                                 answer = false
>                            endIf
>                            quitLoop
>                       endIf
>                  endIf
>             endFor
> 
>             if not answer then
>                  msgstop ( "Error" , "Could not find printer named: \""

> + MYPRINTER + "\"\nPlease check constants for correct printer name." )
>                  errorlog ( usererror , "Could not find printer named: "

> + MYPRINTER )
>                   libforms.BB_StatusMsg(MYPRINTER+"  not found." , 
> statusMsgWarningCT)
>             else
>                  libforms.BB_StatusMsg("Printer Set" , statusMsgOKCT)
>             endIf
>        onFail
>             ErrorLogShow ( ErrorLogger ( ) )
>             answer = false
>             if changedIt then
>                  if not printerSetCurrent ( SavePrn ) then
>                       msgStop ( "Print Config" , "Did not restore 
> printer." )
>                  endIf
>             endIf
>        endTry
>        return ( answer )
> EndMethod
> 
> 
> On 10/12/2017 10:10 AM, John Wright wrote:
>> Because of Paradox 8 no longer running in Win10 I have had to move to 
>> using PDox9 all of the time. I have obviously had it and used it 
>> previously but always prefered some of the ways in which PDox8 
>> 'operated'. One of the things that has come to light is that when I go 
>> to print, PDox9 seems to want to Default to "Create horizontal 
>> overflow pages as needed". When I was using Pdox8 it invariably 
>> Defaulted to "Clip to page width". It also seems that when initially 
>> changing to the latter in the print output dialog box it still 
>> defaults back to the Horizontal etc. However, changing it again to 
>> Clip to page etc. then outputs as that. Any ideas why this should be?
>>
>> I have also noticed that itially outputing to an installed PDF Printer 
>> often now creates a poor output as though the resolution of the 
>> printer needs increasing but a second output seems to correct it 
>> without changing anything from the default setting! Any further 
>> comments appreciated.
>>
>> In all the instances so far the actual Report Output seems quite normal!
>>
>> John Wright
> 


Copyright © 2004 thedbcommunity.com