Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Dec 15, 2019 6:36 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Printers
PostPosted: Tue Feb 01, 2011 8:57 am 
Offline

Joined: Fri Apr 21, 2006 7:11 pm
Posts: 73
Location: Cincinnati, OH
I have written a barcode printing application for my employer. I need to have the application print barcodes to two different printers. Both printers are label printers, one having a larger label than the other. So, what I would like to do is have my application print automatically to both printers without having the user do any kind of set up. How can I get my application to print to both printers automatically? Obviously I can't do it at the same time so I'm hoping I can print to one and the switch to the other one. Is this possible?


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Tue Feb 01, 2011 12:13 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Have the user go through a PageSetupDialog once for both printers and save the resulting SetupString for each. Then when you print, restore the first SetupString, open the printer, print, close the printer, restore the second SetupString, open the printer, and print.


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Wed Feb 02, 2011 2:35 pm 
Offline

Joined: Fri Apr 21, 2006 7:11 pm
Posts: 73
Location: Cincinnati, OH
Good idea! I have set it up so if there is no config file for the label side the user chooses then a printer set up dialog shows up. Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Fri Feb 25, 2011 8:57 pm 
Offline

Joined: Thu Mar 08, 2007 8:24 pm
Posts: 176
Location: Port Vila, VANUATU
I've just run into the same problem except that I'm building a Mac Application.

I have a label printer and an A4 page printer.

It's easy enough to store the PrinterSetup strings as per Tim's post and my program logic can switch to the appropriate PrinterSetup for the printer I want to use. Unfortunately the PrinterSetup string only produces a graphics object and tells my application the characteristics of the printing space.

My problem is that both OpenPrinterDialog() and OpenPrinter will print to the "currently selected printer". (OK I note that the user can choose a different printer in the Printer Dialog but I'd really like to automate the process and use OpenPrinter).

So my questions are:

(a) how can my program find out which is the "currently selected printer" and
(b) if the wrong printer is currently selected, how can I switch to the correct one?

I note that the "currently selected printer" is either the specified default printer in the Mac OS or the last printer used if that option is set in the OS, but I don't know how my App can find out about this either.

Thanks.

jamesee :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Fri Feb 25, 2011 10:49 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You must not be saving/restoring the printer setupstring correctly.

Read the printersetupstring from your file
setup= the string you just read
dim ps as PrinterSetup
ps = new PrinterSetup
ps.SetupString = setup
dim g as graphics = OpenPrinter(ps)

If you pass a brand new printersetup object, without setting its SetupString, to OpenPrinter, then you do get the default printer. If you restore a SetupString first, you should get the printer that the user selected for that string.


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Sat Feb 26, 2011 4:07 am 
Offline

Joined: Thu Mar 08, 2007 8:24 pm
Posts: 176
Location: Port Vila, VANUATU
Thanks for looking into this for me Tim.

Unfortunately, my code is essentially the same as yours but it does not switch the output from my A4 printer to the label printer as I had hoped it would.

Here is my code:

dim sql as string
dim rsPrinterSetup as RecordSet
dim page as Graphics
dim ps as PrinterSetup
dim settings as string

sql = "SELECT LabelPrinter FROM PrinterSetup"
rsPrinterSetup = db.SQLSelect(sql)
settings = rsPrinterSetup.Field("LabelPrinter").StringValue

'set up the printer with settings retrieved from the database

ps = new PrinterSetup
ps.SetupString = settings

ps.MaxVerticalResolution = 600
ps.MaxHorizontalResolution = 600

page = OpenPrinter(ps) 'open the printer and get the page graphics object for our layout


My printer settings are stored in a database in a one-line table called "PrinterSetup" and the table has two columns called "LabelPrinter" and "A4Printer". Separate code presents the PageSetupDialog of the PrinterSetup class to the user and stores the respective strings in the database. I have carefully verified that the correct strings are stored in their respective fields in the database.

If for testing purposes I change

page = OpenPrinter(ps)

into

page = OpenPrinterDialog(ps)

then the dialog presents the A4 printer as the default printer and this is where the print ends up going if I just use OpenPrinter.

If at the printer dialog I leave the setting for the A4 printer and choose the Preview button rather than the Print button, my label is correctly displayed, demonstrating that the Graphics object created by

page = OpenPrinter(ps)

has the dimensions and characteristics of the LabelPrinter specification as I would expect, BUT the print is still sent to the A4 printer.

At the moment the only way I can get the printing sent to the correct printer is by presenting the user with a print dialog and in effect, change the printer by manual intervention rather than under the control of my program (very frustrating). If you (or any other) can spot an error in my program logic, I'd be most grateful to know of it.

Thanks

jamesee :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Mon Feb 28, 2011 2:40 am 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
I've seen situations where you cant even select a printer that isnt the default (in windows)
My reply then was this:

Quote:
The Page Setup dialog in XP had a Printers button to allow you to choose which printer you wanted.
It doesn't show up in Win7
...

Microsoft took it out because they think you shouldn't be allowed to change printers there.

http://social.msdn.microsoft.com/Forums ... f1360f7347


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Fri Mar 04, 2011 2:15 am 
Offline

Joined: Thu Mar 08, 2007 8:24 pm
Posts: 176
Location: Port Vila, VANUATU
Thanks jeffullin. I just have my fingers crossed that Apple doesn't have the same attitude!

Cheers

jamesee :D


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group