Print multiple copies of barcode label (graphic)

I wonder if someone can point me in the right direction regarding printing a canvas multiple times.
My project is to be able to print barcode labels and text with a Zebra label printer from a custom database.

I have put a canvas on my layout, and populate it with the g.drawstring command, utilizing the free 3 of 9 font.

This works fine if I only want to print a single barcode label, but I am at a loss as to how to print multiple copies of the same label.
Even using the print dialogue number of copies only prints a single label.

The following code is from my print button Action Event, please be kind on my coding, not a lot of printing examples around :slight_smile:

Dim settings As String
Dim p as new Picture(200,75,32)
Dim g as Graphics
Dim ps As PrinterSetup
ps = New PrinterSetup
dim i as Integer

//Check if the Page Setup has been previously selected this launch and stored in App.psSettings
if app.psSettings ="" then
If ps.PageSetupDialog Then
settings = ps.SetupString
End If
app.psSettings = settings //Store Printer Settings in App Property
end if

//If page setup has been set this launch, set the ps.SetupString with the information
ps.SetupString = app.psSettings

// open the printer dialog, get the graphics class and prints using the settings from ps
g = OpenPrinterDialog(ps)

// if it’s not nil
If g <> Nil Then

//check if number of prints is greater than 1 and loop accordingly
if val(popupNumberOfLabels.text) > 1 then
  for i = 1 to val(popupNumberOfLabels.text)
    buildbarcode(g)
  next
else
  buildbarcode(g)
end if

else
MsgBox “Printing Cancelled”
End If

Hoping someone understands my needs.

Robert

My fault for not reading all the documentation !
Just had to add a g.nextPage after the initial call to the buildbarcode method and now all working.

Hi Robert
I have a problem using g.nextPage it print more then 2 labels

example :
I send to print 2 label and it print 4

do you have the same problem or no

Alexis,

I am new to XOJO, so not sure if I can give you correct advice but I will try.
My print routine (before I tell it to print multiple copies) will always print one copy, is this correct for you ?
Using a mac, you can print to pdf and preview the results without wasting any labels.

If the original print routine only prints 1 copy, but when asked to print multiple copies it prints double the amount I would guess that you are looping through the print routine multiple times, have you ran it with the debugger on and stepped through it?

This is my print routine:

If g <> Nil Then
//check if number of prints is greater than 1 and loop accordingly
if val(popupNumberOfLabels.text) > 1 then
for i = 1 to val(popupNumberOfLabels.text) //checks that there is more than 1 label to be printed
buildbarcode(g) //builds barcode routine and print
if i <val(popupNumberOfLabels.text) then
g.NextPage
end if
next
else
buildbarcode(g)
end if
else
MsgBox “Printing Cancelled”
End If

Another thing to check, nothing to do with XOJO, is that the printer page size is correct. Out of the box my printer always fed a blank label after every printed one, needed to calibrate the printer to the label size to get over this problem.

Ok
Thanks

Hi Robert
I have to change the printer page size is correct or the Report on Xojo change size from 8.5 x 11.00 to label size like 1.0x3.0

Alexis,

One thing I done is save the printer settings as a preference. Now when I tell it to print, it checks for the printer settings and adjusts them automatically. Also selects correct printer to print to even though it is not set as Default.

Robert. Can you share how to connect to the Zebra printer?

I am trying to print either a PNG or a PDF file with no luck (and no error codes either!!).

I have the Zebra connected to my Mac via USB, and when I use another app it works just fine, I just cannot get any output from my own app.

Thanks in advance.

My code is:

Dim picFile As FolderItem
picFile = GetOpenFolderItem("")

If picFile <> Nil Then

Dim pic As Picture
pic = Picture.Open(picFile)
ImageWell1.Image = pic

// 4x6 inches @ 72dpi = 288x432 pixels
Dim g As Graphics
g = OpenPrinterDialog
If g <> Nil Then
  g.DrawPicture(pic,0,0,288,432,0,0,pic.width,pic.height)
  //g.DrawPicture(pic,0,0)
End If

Else

MsgBox("No image found")

End If