b-PAC Application Examples [ Print from Web Application]

This article explains the system configuration and coding examples to print Brother labels from the web. If you’ve ever tried to work with the Brother software SDK you definitely would have reached a point where you feel true frustration with the lack of documentation and samples from 2003 written in VBS and Visual Studio 2003 (that don’t even compile anymore).


If you’ve had issues, here are a few things you might have encountered:

  • x64 processor support is not there. You have to compile targeting x86
  • COM classes are not always registered correctly
  • Label is printer specific so if you try to print the same label on a different Brother Printer, you have to change the LABEL’s PRINTER in code before actually printing it.
  • Most of the code is designed for Win Forms / Desktop application and the web application examples are few and don’t work

What is bPAC?

unnamed.pngb-PAC is a component that sends data to Brother P-touch series hardware.
Customers can create programs that directly control P-touch to print labels. Creating a simple program for a system in use allows adding a label print function to the existing system.
b-PAC is recommended for the following customers:

  • Customers who want to print labels by putting data from a database in a standard label layout.
  • Customers who want to automate and simplify label printing tasks to streamline their work.
  • Customers who want to integrate P-touch as a label printer into their business system.

How to print Brother Labels from web

bpa_img01.pngThe following components are required:
(1) b-PAC (COM component) Download from the JAPAN Site of Brother as the US one tries to get you registered. Download
(2) Windows PC to run b-PAC (x32 or x64)
(3) Label printer which support b-PAC (I’m using Brother QL 700 for this example)
(4) Printer driver for the label printer

For (2) Windows PC, you have 2 options that either to install b-PAC in the Web Server side or in the web browser of Client PC side.

Option 1
Printing labels from the Label Printer connected to the Web Server.
Install the Brother Printer Driver and b-PAC on the Windows Server. In the back-end code, when the user presses a button, the server code will send the command to the COM component and print the label.

Dim objDoc As bpac.DocumentClass = New bpac.DocumentClass
Try
    objDoc.Open(strLbxPath)
    objDoc.GetObject("txtName").Text = "web print"
    objDoc.StartPrint("", bpac.PrintOptionConstants.bpoDefault)
    objDoc.PrintOut(1, 0)
    objDoc.EndPrint()
Catch ex As Exception
    Me.lblErr.Text = “error" & vbTab & ex.Message
End Try
objDoc.Close()

Option 2. Print from a Web Application Client Side

We want to be printing labels from the Label Printer connected to the Client PC. For this we need to ensure that the b-PAC SDK is installed on the client PC (Windows machine) and the scripting language selected must be VBScript or JScript (which only run in Internet Explorer)

If you’re trying to execute in Chrome you get the following error: “Uncaught ReferenceError: ActiveXObject is not defined”

capture
HTML which show in Web Browser (Internet Explorer) on Client PC side.
Then you can print by using b-PAC solution.
Source code:Example 1

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 3.2//EN”>
<HTML>
<HEAD>
<meta http-equiv=”x-ua-compatible” content=”IE=10″>
<TITLE>b-PAC Sample (Nameplates)</TITLE>

‘ Data Folder
Const sDataFolder = “C:\Temp\name.lbx”
‘*******************************************************************
‘ Print, Preview Module
‘*******************************************************************
Sub DoPrint()
Set ObjDoc = CreateObject(“bpac.Document”)
If(ObjDoc.Open(sDataFolder) False) Then
ObjDoc.GetObject(“txtName”).Text = “Blueberry”
‘ ObjDoc.SetMediaByName ObjDoc.Printer.GetMediaName(), True
ObjDoc.StartPrint “”, 0
ObjDoc.PrintOut 1, 0
ObjDoc.EndPrint
ObjDoc.Close
End If
Set ObjDoc = Nothing
End Sub

</HEAD>

<BODY TEXT=”white” BGCOLOR=#8080c0>
<H2 ALIGN=”center”>Simple Name Badge Example</H2>
<HR>
<FORM NAME=”ValidForm”>
<INPUT TYPE=”button” language=”vbscript” VALUE=” Print ” onClick=’DoPrint’>&nbsp;
<BR>

</FORM>
</BODY>
</HTML>

Note: added language = vbscript on the input button to tell IE to execute the script via VBScript. This works in IE8, IE9, IE10.

IE11 does not offer support for VBScript.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.