RP2: Default printer - Solved in xSharp

Forum dedicato ai programmatori di X# in lingua italiana – Italian language forum

Moderator: wriedmann

Post Reply
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

RP2: Default printer - Solved in xSharp

Post 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.
gfb
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

RP2: Default printer

Post 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
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

RP2: Default printer

Post 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
gfb
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

RP2: Default printer

Post 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
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

RP2: Default printer

Post by Gfb22 »

...It's what I need but I can't find the IC2StSh Class.
Thank you! :-)
gfb
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

RP2: Default printer

Post 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() )
gfb
User avatar
Chris
Posts: 4898
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

RP2: Default printer

Post 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?

.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

RP2: Default printer

Post 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
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

RP2: Default printer - Solved in xSharp

Post 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.
Attachments
Test-AEF.zip
(586.51 KiB) Downloaded 196 times
Test-Dir&File.zip
(2.15 KiB) Downloaded 172 times
gfb
Post Reply