Print # of Copies

Looking into an issue with printing on Windows. It looks like the Number of Copies to print is outside the control of a Xojo app but yet when I do this in Windows 7 I get a single copy regardless of what I’ve put in the print dialog. On Mac OS X the # of copies works as expected.

Am I missing something obvious in Windows? Anyone else seeing this?

Windows doesn’t manage the copies for you like OS X does

Um, it shows up in the print dialog.

WindowsDeviceModeMBS class allows modification of Printersetup.SetupString.

includes copies property.

It does and by the docs that is available to you, in Graphics.Copies… From the docs on Windows you have to loop through your document and do the printing of the copies yourself.

[quote]The OpenPrinterDialog function returns a Graphics object. The various drawing routines can then be used to draw into the Graphics object and will be sent to the printer for printing. You can get the values in the Copies, From and To fields of the Print dialog box using the Copies, FirstPage and LastPage properties of the Graphics object returned by the OpenPrinterDialog function.


I get the same results that Bob does with Windows 7 (Ultimate 64 bit). Furthermore, if you select only the 1st page (or 2nd or 3rd, etc.) in the Page Range, it prints the entire multi-page document anyways even though you specified only a single page to be printed.

See my post above… Unlike OS X, on Windows you are responsible for the logic for printing page range and copies… You get that information passed to in the graphics object.

Thanks, Karen … I did see your note, but thought (at first glance) it covered the topic of “copies” but not the “Page Range” … which is why I added that input. Upon taking the time to actually read the docs, I see where your point covers both … much obliged for your input!

However, seeing Christian’s note above happens to answer my need directly since I own just about everything MBS (but continuously learn here in the forums how to use each and every one of the bazillion commands available as Christian points out issues they resolve). Matter of fact, looking at the investment I’ve made in MBS versus Xojo, maybe I ought to put a splash screen on my creations saying “Made with MOJO” ^^

Thanks, Karen!

After doing some more investigating, the same code will work on Mac OS X except you don’t have to worry about the Number of copies. The Mac OS does that for you.

Code from my project:

[code] ’ This is the proper way to do printing
firstPage = g.FirstPage-1
lastPage = g.LastPage-1

’ Check the ranges.
if firstPage < 0 then firstPage = 0
if lastPage > Ubound(pages) then lastPage = Ubound(pages)

’ Get the number of copies
dim iCopyMax as integer = g.Copies
dim iCopyCount as integer = 0

’ On Mac OS X the OS handles the number of copies.
#if TargetMacOS then iCopyCount = iCopyMax - 1

while iCopyCount < iCopyMax
’ Print all the visible pages.
for i = firstPage to lastPage

  ' Is this not the first page?
  if i <> firstPage then
    ' Create a new page.
  end if
  ' Draw the page.
  pages(i).drawPageViewMode(g, self, printer.PageLeft, printer.PageTop, nil, true, printScale)
iCopyCount = iCopyCount + 1

#if TargetWin32 then
  if iCopyCount < iCopyMax then


Showing in the dialog and the OS handling it for you are two unrelated things
On OS X you simply print one copy & get however many you specified (collated etc)
Not so on Windows - your APP prints 1 copy 10 copies etc

Microsloth strikes again! No wonder someone reported this works on my Mac app but not on my Windows build.


Back to this seemingly old topic.

I use the following code (API 2.0) to print pages on macOS.

If I enter a value greater than 1 in the print dialog for the number of copies, then macOS prints for the PDF output (I have yet tested the code on a printer physically), only one copy of the value range of the pages. Why? Do you get the same results under Windows and Linux?

[code]’ Get the number of copies
Var copyMax As Integer = g.Copies
Var copyCount As Integer

’ On macOS the OS handles the number of copies.
#If TargetMacOS Then copyCount = copyMax - 1

’ Get last page.
Var lastPage As Integer = Min(Pages.LastRowIndex + 1, g.LastPage)

While copyCount < copyMax

’ Loop over all pages.
For i As Integer = g.FirstPage To lastPage

' Check for more then one page.
If i > g.FirstPage Then
  ' Add new page.
End If

' Call the Page's Paint-Event.
Pages(i - 1).Draw(g, x, y, scale)


copyCount = copyCount + 1

Is there maybe something wrong with the loop construct?

in the mac, regardless of how many copies you ask for, your software will only ever be asked to print one copy
the print driver handles printing multiple copies (since they are copies and it doesnt need to ask your app to redraw everything to make multiple copies)
this is NOT done this way on Windows and your app is asked to redraw things

This means that my code is correct in terms of the number of copies in itself?

I don’t think this line is quite right

[quote=481714:@Martin Trippensee]’ On macOS the OS handles the number of copies.
#If TargetMacOS Then copyCount = copyMax - 1[/quote]

Shouldn’t it be then copyCount = 1 ?

However, Copies will always be 1 on macOS anyway.
Edit: Source Graphics — Xojo documentation

[quote=481721:@Martin Trippensee]#If TargetMacOS Then copyCount = copyMax - 1
should be

#If TargetMacOS 
  copyCount =  1

including the newlines for readability :slight_smile:

No, this gives me a blank page back. But as you said, I can remove this condition and everything will run under macOS again.

ah reading the rest of the code helps :slight_smile:

#If TargetMacOS 
  copyCount =  0
  copymax = 1