Page 1 of 1

Simple print question

PostPosted: Sun Jan 31, 2016 5:20 am
by dtussman
In old 2007 version of FWH you could say

print oprn name pname to (cprinter)

where cprinter was the name of an installed printer. Now with FWH 1507 it ignores the "to" clause and just goes to the default printer. I don't want the user to have to select the printer since I am using a PDF writer that I provide and its part of a complicated routine where I generate bills to pdf files and then email them to the respective recipients all without requiring any user input. How can I get it to work the old way?

Re: Simple print question

PostPosted: Sun Jan 31, 2016 5:33 am
by dtussman
Figured it out, setprintdefault(cprinter) is the answer.

Re: Simple print question

PostPosted: Sun Jan 31, 2016 6:22 am
by dtussman
I take it all back. setprintdefault() seems to have no effect at all.

Re: Simple print question

PostPosted: Sun Jan 31, 2016 10:27 am
by Antonio Linares
We are checking it.

Could other FWH users report if this is failing for them too ? thanks

Re: Simple print question

PostPosted: Sun Jan 31, 2016 10:40 am
by cnavarro
dtussman wrote:In old 2007 version of FWH you could say

print oprn name pname to (cprinter)

where cprinter was the name of an installed printer. Now with FWH 1507 it ignores the "to" clause and just goes to the default printer. I don't want the user to have to select the printer since I am using a PDF writer that I provide and its part of a complicated routine where I generate bills to pdf files and then email them to the respective recipients all without requiring any user input. How can I get it to work the old way?


You are tried without brackets?

print oprn name pname to cprinter

Re: Simple print question

PostPosted: Sun Jan 31, 2016 6:39 pm
by dtussman
yes cnavarro, I tried everything!

Re: Simple print question

PostPosted: Mon Feb 01, 2016 2:44 am
by dtussman
I got it to work with the following code:

setprintdefault(cprinter)
oprn:=printbegin(pname,.f.,.f.,cprinter,.t.)
oprn:end()
print oprn name pname to cprinter

Only then does the program successfully change the default printer. If I leave off any of those lines it doesn't work.

Strange, but I suppose the fact that it works is all that matters.

Re: Simple print question

PostPosted: Mon Feb 01, 2016 3:12 am
by dtussman
I now realize the source of my error. I was using prngetname() to check if I had successfully changed the default printer, but changing the default printer doesn't change prngetname(). Whew.

Re: Simple print question

PostPosted: Mon Feb 01, 2016 9:53 am
by Antonio Linares
Please try it this way:

setprintdefault(cprinter)
PrinterInit()
print oprn name pname to cprinter

SetPrintDefault() just changes the Windows registry values but does not refresh the FWH printer internals

Maybe we should call PrinterInit() from SetPrintDefault() automatically

Re: Simple print question

PostPosted: Mon Feb 01, 2016 8:56 pm
by James Bott
David,

Antonio's code works fine for me (using FWH 15.6 and under Windows 8.1).

Below is a little sample to test it.

Personally, I never change the default printer since the user may not want this behavior. I think it would be rude for any app to change the default printer. Users will be confused as to why the default was changed later when they are running a different app. Even it you restore it at the end of your app, the user could still switch to another app while yours was still open, then try to print.

Anyway, the way you were doing it originally should still work. If my little test doesn't work for you, then we need to find the problem. Let us know what you find.

James


Code: Select all  Expand view
#include "fivewin.ch"

Function Main()
  Local cPrinter:=  "PDFCreator" // Change to  your PDF driver
 
  msgInfo( prnGetName(), "Default Printer" )
 
  PRINTER oPrn NAME "My Report" TO cPrinter
 
  msgInfo( oPrn:cModel , "oPrn:cModel")
 
return nil