FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Simple print question
Posts: 102
Joined: Sat Jun 06, 2015 06:57 PM
Simple print question
Posted: Sun Jan 31, 2016 05:20 AM

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?

Posts: 102
Joined: Sat Jun 06, 2015 06:57 PM
Re: Simple print question
Posted: Sun Jan 31, 2016 05:33 AM

Figured it out, setprintdefault(cprinter) is the answer.

Posts: 102
Joined: Sat Jun 06, 2015 06:57 PM
Re: Simple print question
Posted: Sun Jan 31, 2016 06:22 AM

I take it all back. setprintdefault() seems to have no effect at all.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Simple print question
Posted: Sun Jan 31, 2016 10:27 AM

We are checking it.

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Simple print question
Posted: Sun Jan 31, 2016 10:40 AM
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
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 102
Joined: Sat Jun 06, 2015 06:57 PM
Re: Simple print question
Posted: Sun Jan 31, 2016 06:39 PM

yes cnavarro, I tried everything!

Posts: 102
Joined: Sat Jun 06, 2015 06:57 PM
Re: Simple print question
Posted: Mon Feb 01, 2016 02:44 AM

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.

Posts: 102
Joined: Sat Jun 06, 2015 06:57 PM
Re: Simple print question
Posted: Mon Feb 01, 2016 03:12 AM

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.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Simple print question
Posted: Mon Feb 01, 2016 09:53 AM

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Simple print question
Posted: Mon Feb 01, 2016 08:56 PM
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 (fw): Select all Collapse
#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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion