xsharp.eu • RP2: Default printer - Solved in xSharp
Page 1 of 1

RP2: Default printer - Solved in xSharp

Posted: Mon Apr 24, 2023 3:56 pm
by Gfb22
Hi all.
I can't set and keep the default printer for my app.
When I set the printer with oPrinter:Setup() the set printer is seen correctly with oPrinter:Device but not with oReport:PrinterDevice:printername and the same by choosing the print icon from the preview window (it is always set Microsoft print to PDF).
The app's default printer doesn't necessarily have to be the same as in Windows.
So I save the chosen default printer on file (with oPrinter:Device) but then I can't set it to be used every time within the app.
How should I do?
Thank you for your suggestion.

RP2: Default printer

Posted: Mon Apr 24, 2023 5:36 pm
by ic2
Hello,

I use

[left]oReport:PrinterDevice:SetPrinterByName(cPrinter)[/left]

where cPrinter is passed by the program (I keep the preferred printername in the program's settings).

If this is not done, I'd indeed expect Windows default printer, which for me is Microsoft Print to PDF too (and I see that appear in other programs which do not have their own printer settings). I use this printer to prevent accidentally filling the printer queue and then printing pages with some test stuff when I am about to really print something (else), often weeks later.

Dick

RP2: Default printer

Posted: Tue Apr 25, 2023 7:56 am
by Gfb22
Thank you Dick for your suggestion:
I choose the printer with oPrinter:Setup(), save PrinterName with oPrinter:Device and, when I have to print, I use oReport:PrinterDevice:SetPrinterByName(cPrinter) and everything works fine!
When I want to change the default printer again, oPrinter:Setup() always selects Microsoft Print to PDF: how do I select my previous printer?
gfb

RP2: Default printer

Posted: Wed Apr 26, 2023 8:48 am
by ic2
Hello,

I am not sure I completely understand your question but maybe this code helps. IC2GetAppObject is an implementation of GetAppObject but you could use any source of storing and retrieving the variable.

Dick

Code: Select all

METHOD FilePrinterSetup() CLASS IC2StSh
//#s Global setup for printer 09-11-2009
LOCAL oPrinter AS PrintingDevice
LOCAL cPrinter  AS STRING
	oPrinter := PrintingDevice{IC2GetAppObject():cSessionPrinter}
	oPrinter:Setup()
	cPrinter:=oPrinter:Device
	IC2GetAppObject():cSessionPrinter:=cPrinter		// assign to global object
	WriteIC2Reg("cDefaultPrinter",cPrinter)				// Write last selected printer to retrieve next time 12-8-2010	
RETURN NIL

RP2: Default printer

Posted: Wed Apr 26, 2023 3:03 pm
by Gfb22
...It's what I need but I can't find the IC2StSh Class.
Thank you! :-)

RP2: Default printer

Posted: Wed Apr 26, 2023 4:12 pm
by Gfb22
Hi Dick,
what doesn't work is:
oPrinter := PrintingDevice{<cPrinterName>}
For example:
oPrinter := PrintingDevice{"Microsoft XPS Document Writer"} does not set up the printer and oPrinter: device still returns "Microsoft Print to PDF" (and the same in oPrinter:Setup() )

RP2: Default printer

Posted: Wed Apr 26, 2023 9:17 pm
by Chris
Hi Gian,

Is this with the VO or the X# version of RP2?

Can you please create and send a very small test app showing exactly what you are doing?

.

RP2: Default printer

Posted: Wed Apr 26, 2023 10:20 pm
by ic2
Hello Gian,

IC2StSh is my subclass of shellwindow, via some more subclasses. You could put it in any of your classes. The above method worked for me in VO, I do not use ReportPro in X# but we have 1 application converting (Frank is working on that) - not sure if that program uses this too.
Did you eventually try the full code, when you concluded it didn't work?

Dick

RP2: Default printer - Solved in xSharp

Posted: Thu Apr 27, 2023 9:55 am
by Gfb22
It's a curious fact:
in my latest version I changed some things: in xSharp it works, while in VO oPrinter:Setup() still doesn't take the previously selected printer....
However, I share a small test app because it may be of interest to others:
1) Test-AEF (the app)
2) Test-Dir&File.zip (Folder c:test with .dbf and .rpt files)
Thanks so much to Dick and Chris for the tips and patience.