1. Tracy Lamb
  2. PowerBuilder
  3. Friday, 13 September 2024 15:57 PM UTC

Hi all,

In my application, I have a user event for printing to a label printer, triggered from a right mouse menu option.

I'm wondering how to get and save the current default printer, call PrintSetup() to allow the user to select the label printer, then reset the default printer after the print job is finished, so the next time they print a document, the original printer will be the default.

PrintSetup() changes the default printer for my application. The label printer should never be the application default printer.  Maybe using PrintSetup() isn't the right solution, but I don't know how else to let the user select a printer without changing the default printer.  Using PB 2022 R3, build 3356.

TIA,
~~~Tracy

Accepted Answer
Tracy Lamb Accepted Answer Pending Moderation
  1. Friday, 13 September 2024 22:47 PM UTC
  2. PowerBuilder
  3. # Permalink

 

Many thanks to Chris Pollach for pointing me in the right direction.  Turns out, the PrintOpen("name", true) function does not change the default printer.  Hooray, made my job much easier!

Here's my code, in case your curious:

// Override
long ll_rc
ulong ul_job

this.Retrieve(il_FormID)
if this.RowCount() < 1 then
	MessageBox("Legacy Label", "No data retrieved")
	return 0
end if

// Open a print job.
ul_job = PrintOpen( "Cal Label", TRUE )
if ul_job = -1 then
	MessageBox("Legacy Label", "Print Cancelled")
end if

// Send the Start Label sequence.
Print( ul_job, "##startlabel##~r~n" )

   ... print a lot of fields ...

// Send the End Label sequence.
Print( ul_job, "##endlabel##~r~n" )

// Send the job to the printer or spooler.
ll_rc = PrintClose( ul_job )

return 1

This is so much simpler than how I was trying to do it.  I was just trying to get old code to work.  Again, I'm very grateful, Chris!

~~~Tracy

 

Comment
  1. Chris Pollach @Appeon
  2. Friday, 13 September 2024 23:16 PM UTC
Hi Tracy;

Super glad that you got that sorted out! Thanks for the feedback.

However, you now have some more printer knowledge for future endeavours. ;-)

Regards .. Chris
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 13 September 2024 16:19 PM UTC
  2. PowerBuilder
  3. # 1

Hi Tracy;

  That is what the related PrintGetPrinters, PrintGetPrinter, PrintSetPrinter and PrintSetupPrinter commands would be used for.  HTH

Regards .. Chris

Comment
  1. Tracy Lamb
  2. Friday, 13 September 2024 20:27 PM UTC
I'm calling PrintOpen() followed, by 6 or 7 Print() statements, then PrintClose(). Do I need to call PrintSetPrinter() before each Print(), or just once after PrintOpen()?
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 13 September 2024 20:33 PM UTC
  2. PowerBuilder
  3. # 2

Hi Tracy;

  That would be (IMHO)

  1. PrintGetPrinter  // Get current printer
  2. // Print loop
  3. PrintSetPrinter // Restore previous printer from #1

Regards .. Chris

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.