Sending Reports to a NON-Default Printer

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Red2
Posts: 25
Joined: Sat May 18, 2019 2:11 pm
DBs Used: DBF, FoxPro, Visual FoxPro
Location: United States (East Coast)
Has thanked: 4 times
Been thanked: 1 time

Sending Reports to a NON-Default Printer

Post by Red2 » Fri Jun 07, 2019 3:46 pm

Hi All,

I am fairly new to HMG but am really enjoying my experience. (My previous work in Visual FoxPro has been quite helpful).

My HMG project has gone well. It is almost done except for a report printing issue and I am now stuck!!!

A report must print on a local printer. NOTE: This “report” is actually two separate reports. That is, the second must print immediately after the first.

Some background:
1) Both are printed using the function ExecuteReport().
2) This function’s parameter, PRINTERSELECT, is set to .F.
3) The code is adapted from “...\HMG.3.4.4\Samples\Controls\ReportAdvanced\Report_Advanced_1\Demo.prg”.
4) The user must select the printer before printing because the “report” is generated for each of multiple locations.

The reports print to the default Windows printer just fine, no problem here.

My Question:
How can I programatically force all reports to print to the same (user-selected) printer?
(I have not had success experimenting with “SET PRINTER TO [<cPrinter>]”).

I am sure that I am just missing something. Any guidance or suggestions you have would be greatly appreciated.

Thank you very much,

Red2

User avatar
andyglezl
Posts: 1151
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 35 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri Jun 07, 2019 5:24 pm

Así a lo rápido, puedes guardar en una variable...
*------------------------------------------------------------------------
So fast, you can save in a variable ...

FUNCTION MAIN
MyDefPrinter := GetPrinter()
...
...
...
...
SET PRINTER TO MyDefPrinter
Andrés González López
Desde Guadalajara, Jalisco. México.

franco
Posts: 336
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 11 times

Post by franco » Fri Jun 07, 2019 5:51 pm

Red2
Here is a sample of what I use. Hope it Helps and you can figure it out
I have a control table with fields for setup of program
field reciet
field prn1 := 'direct'
field prn2 := a printers shared name or local name
I send a parameter to print procedure
IF YOUR BOTH PRINTOUTS ARE THE SAME
printbig('DIRECT')
printbig(direct')
if different
printbig('direct')
printsomewhere'direct') or for print pick printsomhere()
*------------------------------------------------------------------------------*
Procedure Printbig
*------------------------------------------------------------------------------*
Local lSuccess:=.T., pr := alltrim(controls->prn1)
Parameter DI

if controls->receit = 'R'
pr := alltrim(controls->prn2)
endif

if upper(di) = 'DIRECT' // to print to default printbig('direct') else printbig()
if pr = 'DEFAULT'
select printer DEFAULT to lsuccess // preview
else
SELECT PRINTER PR TO LSUCCESS // preview //DEFAULT ;
endif
else
SELECT PRINTER DIALOG TO lSuccess PREVIEW //;
endif
If lSuccess <> .T.
MsgInfo('Print Not Available')
return
EndIf

// Measure Units Are Millimeters
START PRINTDOC
Franco
Franco Bushie
Canada

Red2
Posts: 25
Joined: Sat May 18, 2019 2:11 pm
DBs Used: DBF, FoxPro, Visual FoxPro
Location: United States (East Coast)
Has thanked: 4 times
Been thanked: 1 time

Post by Red2 » Fri Jun 07, 2019 6:17 pm

Hola Andyglezl,

Muchas Gracias por la rápida respuesta.

Agregué este código a la línea anterior a la función ExecuteReport ():
       cPrinter: = GetPrinter ()
       set printer to cPrinter

Esa sintaxis es bastante similar a la que usaría en VFP:
       “set printer to NAME ‘HP Officejet Pro 8610’”

Entonces sólo para la prueba:
En la Configuración de Windows, configuro la impresora predeterminada a otra cosa, "Foxit Reader PDF Printer".

Esto es lo que sucedió cuando ejecuté el programa y seleccioné mi impresora HP:
1) Ningún informe fue a la impresora HP.
2) Para cada informe, apareció el diálogo de creación de archivos PDF de Foxit Reader.
2) Un archivo de cero bytes llamado. “CPrinter.prn” apareció en el directorio predeterminado.

¿Hay algo que pueda hacer diferente? Apreciaría mucho cualquier sugerencia.

Gracias de nuevo,

Red2
********************************
Hi Andyglezl,

Thank you so much for the quick reply.

I added this code to the line before function ExecuteReport():
cPrinter := GetPrinter()
set printer to cPrinter

That syntax is quite similar to what I would use in VFP:
“set printer to NAME ‘HP Officejet Pro 8610’”

Then just for testing:
In Windows’ Settings I set the default printer to something else, “Foxit Reader PDF Printer”.

Here is what then happened when I then ran the program and selected my HP Printer:
1) No report went to the HP printer.
2) For each report the Foxit Reader PDF file creation dialog appeared.
2) A zero byte file named. “cPrinter.prn” appeared in the default directory.

Is there something I might do differently? I would very much appreciate any suggestions.

Thanks again,

Red2

User avatar
andyglezl
Posts: 1151
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 35 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri Jun 07, 2019 7:07 pm

Tendrás un ejemplo mínimo con el cual pudieramos probar ??
*----------------------------------------------------------------------------
You will have a minimum example with which we could try?
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
andyglezl
Posts: 1151
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 35 times
Been thanked: 68 times
Contact:

Post by andyglezl » Fri Jun 07, 2019 9:55 pm

(I have not had success experimenting with “SET PRINTER TO [<cPrinter>]”).
SET PRINTER TO [<cPrinter>]
Se utiliza solo en HARBOUR, no en HMG.

En HMG sería así:

REPORT EXECUTION

Function:
ExecuteReport ( <cReportName> , <lPrintPreview> , <lSelectPrinter> , [ <cOutputFile> ] )


Command:
EXECUTE REPORT <ReportName> [ PREVIEW ] [ PRINTERSELECT ] [ FILE <cFile> ]


Revisa el ejemplo \HMG\3.4.4\SAMPLES\Controls\ReportAdvanced\REPORT_ADVANCED_5 o 6
Andrés González López
Desde Guadalajara, Jalisco. México.

Red2
Posts: 25
Joined: Sat May 18, 2019 2:11 pm
DBs Used: DBF, FoxPro, Visual FoxPro
Location: United States (East Coast)
Has thanked: 4 times
Been thanked: 1 time

Post by Red2 » Sat Jun 08, 2019 12:15 am

Hola Andyglezl,

Gracias de nuevo por su amable asistencia. Aquí es donde estoy en este momento.

En realidad, ya estoy usando la sintaxis, "ExecuteReport (<cReportName>, <lPrintPreview>, <lSelectPrinter>, [<cOutputFile>])".

Cambié a la sintaxis de HMG, "impresora de selección ...", que me sugirió Franco.
cPrinter := GetPrinter()
...
...
// begin loop
select printer cPrinter to lSuccess
if ( lSuccess )
ExecuteReport( "Pages_1_to_2", .F. , .F. )
ExecuteReport( "Page_3", .F. , .F. )
endif
// end loop

Ambos informes, "Pages_1_to_2" y "Page_3", son necesarios para el informe completo. Además, este par de informes se ejecuta repetidamente en un bucle, una vez para cada una de las muchas ubicaciones. Por eso no puedo simplemente establecer el parámetro lSelectPrinter en .T.

Nuevamente, desafortunadamente, no se envió nada a la impresora seleccionada en GetPrinter (). Todos los resultados fueron a la impresora predeterminada de Windows.

PREGUNTA:
¿Es este un requisito de informe inusual para HMG? Dado que soy nuevo en HMG, ¿hay una mejor manera de abordar este problema de la impresora?

Gracias y realmente aprecio sus ideas y orientación.

Red2
***************************************
Hi Andyglezl,

Thank you again for your kind assistance. Here is where I am at the moment.

Actually I am already using the syntax, “ExecuteReport ( <cReportName> , <lPrintPreview> , <lSelectPrinter> , [ <cOutputFile> ] )”.

I changed to the HMG syntax, “select printer...”, that was suggested to me by Franco.
cPrinter := GetPrinter()
...
...
// begin loop
select printer cPrinter to lSuccess
if ( lSuccess )
ExecuteReport( "Pages_1_to_2", .F. , .F. )
ExecuteReport( "Page_3", .F. , .F. )
endif
// end loop

Both reports, "Pages_1_to_2" and "Page_3", are needed for the full report. Furthermore, this pair of reports is repeatedly run in a loop, once for each of many locations. That is why I cannot simply set parameter lSelectPrinter to .T.

Again, unfortunately, nothing was sent to the printer selected in GetPrinter(). All output went to the default Windows printer.

QUESTION:
Is this an unusual reporting requirement for HMG? Given that I am new to HMG is there a better way to approach this printer problem?

Thank you and I really appreciate your ideas and guidance.

Red2

User avatar
andyglezl
Posts: 1151
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 35 times
Been thanked: 68 times
Contact:

Post by andyglezl » Sat Jun 08, 2019 2:56 am

Creo que con ExecuteReport() no se va a poder...
Revisa el ejemplo que está en \HMG\3.4.4\SAMPLES\Controls\Print\Print_to_PDF
en la opción que dice PrintTest2()
*-----------------------------------------------------------------------------------------------------------
I think that with ExecuteReport () it will not be possible ...
Check the example that is in \HMG\3.4.4\SAMPLES\Controls\Print\Print_to_PDF
in the option that says PrintTest2 ()


Code: Select all

*------------------------------------------------------------------------------*
Procedure PrintTest2()
*------------------------------------------------------------------------------*
Local i 
Local cPrinter

	cPrinter := GetPrinter()

	If Empty (cPrinter)
		Return
	EndIf

	SELECT PRINTER cPrinter ;
		ORIENTATION	PRINTER_ORIENT_PORTRAIT ;
		PAPERSIZE	PRINTER_PAPER_LETTER ;
		QUALITY		PRINTER_RES_MEDIUM

	//PrintDoc()
	// Toma como ejemplo el procedure PrintDoc() para hacer los tuyos
	Pages_1_to_2()
	Page_3()
	
	MsgInfo('Print Finished')
Return
Andrés González López
Desde Guadalajara, Jalisco. México.

franco
Posts: 336
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 11 times

Post by franco » Sat Jun 08, 2019 7:21 am

where is the non default printer.
in my internal network system I have 2 network printers.
one is default on each terminal. The other is another installed printer on each computer with a shared name.
in my program controls->prn1 := default.... controls->prn2 := other shared printer name
when I want to print to default I set printer to controls->prn1, or default. For other printer I set printer to controls->prn2
Also you could create public variables at start of program prn1:= "default" .... prn2:="canon2" which is the shared network printer.
Franco
Franco Bushie
Canada

edk
Posts: 469
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 136 times
Been thanked: 381 times

Post by edk » Sat Jun 08, 2019 10:29 am

Red2 wrote:
Sat Jun 08, 2019 12:15 am
(...)
Again, unfortunately, nothing was sent to the printer selected in GetPrinter(). All output went to the default Windows printer.

Red2
:idea: You can try to set the temporarily selected printer as the default printer, print reports and restore the default printer. :idea:

Code: Select all

Function main_button_1_action

Local cCurrentDefaultPrinter := GetDefaultPrinter()
Local cTempDefaultPrinter := GetPrinter()

	IF !EMPTY(cTempDefaultPrinter)
		IF !win_printerSetDefault (cTempDefaultPrinter)  //Set the selected printer as the default printer.
			MsgInfo ("The selected printer " + cTempDefaultPrinter + " can't be set as the default.")
		ENDIF
	ENDIF
	
	Use Test

	LOAD REPORT Test

	EXECUTE REPORT Test PREVIEW //1st report
	
	Use Test2

	LOAD REPORT Test2

	EXECUTE REPORT Test2 PREVIEW  //2nd report
	
	win_printerSetDefault (cCurrentDefaultPrinter)		//restore the default printer.

	Use

Return Nil


Post Reply