Brother Label Printer with b-pac SDK

Started by rothestar, February 17, 2014, 06:41:22 AM

Previous topic - Next topic

rothestar

Hi
Im trying to to figure out how to print directly via at p-touch template, but can't figure out how to pass to code to the printer..

here are the SDK http://www.brother.com/product/dev/label/bpac/download/index.htm#full

the are some samples codes. I got the java script working but cant figure out how to get objects i WB working..


some ideas?

Best regards
Henrik

rothestar

the java script code that is working looks like this:

<!--
'*************************************************************************
'
'      b-PAC 3.0 Component Sample (JS_NamePlate.html)
'
'      (C)Copyright Brother Industries, Ltd. 2009
'
'*************************************************************************/
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>My Label printer</title>
    <script language="javascript" type="text/javascript">
    <!--
    var DATA_FOLDER = "C:\\Program files\\Brother bPAC3 SDK\\Templates\\";
    //------------------------------------------------------------------------------
    //   Function name   :   DoPrint
    //   Description     :   Print, Preview Module
    //------------------------------------------------------------------------------
    function DoPrint(strExport)
    {
        var theForm = document.getElementById("myForm");
        var nItem = theForm.cmbTemplate.selectedIndex;
        var strPath = DATA_FOLDER + theForm.cmbTemplate.options[nItem].value;
     
      var objDoc = new ActiveXObject("bpac.Document");
      if(objDoc.Open(strPath) != false)
      {
         objDoc.GetObject("objName").Text = theForm.txtName.value;
         objDoc.GetObject("objBatch").Text = theForm.txtBatch.value;
         objDoc.GetObject("objSmag").Text = theForm.txtSmag.value;
         theForm.txtWidth.value = objDoc.Width;
         
         if(strExport == "")
         {
            //objDoc.SetMediaByName(objDoc.Printer.GetMediaName(), true);
            objDoc.StartPrint("", 0);
            objDoc.PrintOut(1, 0);
            objDoc.Close();
            objDoc.EndPrint();
         }
         else
         {
            strExport = DATA_FOLDER + strExport;
            objDoc.Export(4, strExport, 180);
            objDoc.Close();
            window.location.href = strExport;
         }
      }
    }   
    -->
    </script>
</head>
<body style="color:#008001;background-color:#FFFFFF">
<form id = "myForm" action = "">
   <h2 style="text-align:center">Djurs Damp Label e-juice</h2>
   

    <p>
   Template :
    <select name="cmbTemplate" id="cmbTemplate" style="width: 320px; height: 22px">
    <option value="NamePlate1.lbx">NamePlate Design 1</option>
    <option value="NamePlate2.lbx">NamePlate Design 2</option>
    <option value="e-juice.lbx" selected="selected">e-juice</option>   
    </select>
    </p>

   <p>
   Name :
  <select name="txtName" id="txtName" type="text" style="width: 320px; height: 22px">
  <option value="John">John</option>
  <option value="Jim">Jim</option>
  <option value="Tom">Tom</option>
  <option value="Amanda">Amanda</option>
</select>
</p>

   <p>
   mg/ml :
  <select name="txtBatch" id="txtBatch" type="text" style="width: 320px; height: 22px">
  <option value="J">0</option>
  <option value="A">1</option> 
  <option value="B">2</option>
  <option value="C">3</option>
  <option value="D">4</option>
  <option value="E">5</option> 
  <option value="F">6</option>
  <option value="G">7</option>
  <option value="H">8</option>   
  <option value="I">9</option> 
  <option value="AJ">10</option>
  <option value="AA">11</option>
  <option value="AB">12</option>
  <option value="AC">13</option> 
  <option value="AD">14</option>
  <option value="AE">15</option>
  <option value="AF" selected="selected">16</option>   
  <option value="AG">17</option>
  <option value="AH">18</option>
  <option value="AI">19</option>
  <option value="BJ">20</option> 
  <option value="BA">21</option>
  <option value="BB">22</option>
  <option value="BC">23</option>   
  <option value="BD">24</option>   
  </select>
    </p>


<p>
   Smag :
  <select name="txtSmag" id="txtSmag" type="text" style="width: 320px; height: 22px">
  <option value="0.5">0.5</option>
  <option value="0.6">0.6</option> 
  <option value="0.7">0.7</option>
  <option value="0.8">0.8</option>
  <option value="0.9">0.9</option>
  <option value="1.0" selected="selected">1.0</option> 
  <option value="1.1">1.1</option>
  <option value="1.2">1.2</option>
  <option value="1.3">1.3</option>   
  <option value="1.4">1.4</option> 
  <option value="1.5">1.5</option>
  <option value="1.6">1.6</option>
  <option value="1.7">1.7</option>
  <option value="1.8">1.8</option> 
  <option value="1.9">1.9</option>
  <option value="2.0">2.0</option>
  </select>
</p>

   
   

    <input id="btnPrint" type="button" value="   Print   " onclick="DoPrint('')"/>
   <input id="btnPreview" type="button" value="   Preview   " onclick="DoPrint('Preview.bmp')"/>
   

   

   Tape Width :
   <input id="txtWidth" style="size:15;"/>
    </form>
</body>
</html>

Deana

Here is my totally undebugged attempt at converting the JavaScript sample to WIL code:

Code (winbatch) Select

#DefineFunction DoPrint(strExport, strTemplate, txtName, txtBatch, txtSmag)
   objDoc = ObjectCreate("bpac.Document")
   If objDoc.Open(strTemplate) != @false
      objDoc.GetObject("objName").Text = txtName
      objDoc.GetObject("objBatch").Text = txtBatch
      objDoc.GetObject("objSmag").Text = txtSmag         
      If strExport == ""
         ;objDoc.SetMediaByName(objDoc.Printer.GetMediaName(), @true)
         objDoc.StartPrint("", 0)
         objDoc.PrintOut(1, 0)
         objDoc.Close()
         objDoc.EndPrint()
      Else ;Print preview
         strExport = 'C:\Program files\Brother bPAC3 SDK\Templates\' : strExport;
         objDoc.Export(4, strExport, 180)
         objDoc.Close()
         ShellExecute(strExport, '', '', @NORMAL, '')
      EndIf
   EndIf
#EndFunction


strExport = '' ; or 'Preview.bmp'

;<option value="NamePlate1.lbx">NamePlate Design 1</option>
;<option value="NamePlate2.lbx">NamePlate Design 2</option>
;<option value="e-juice.lbx" selected="selected">e-juice</option>   
strTemplate = 'C:\Program files\Brother bPAC3 SDK\Templates\e-juice.lbx'  ; theForm.cmbTemplate.options[nItem].value;

;<option value="John">John</option>
;<option value="Jim">Jim</option>
;<option value="Tom">Tom</option>
;<option value="Amanda">Amanda</option>
txtName = Amanda ; theForm.txtName.value;

;<option value="J">0</option>
;<option value="A">1</option> 
;<option value="B">2</option>
;<option value="C">3</option>
;<option value="D">4</option>
;<option value="E">5</option> 
;<option value="F">6</option>
;<option value="G">7</option>
;<option value="H">8</option>   
;<option value="I">9</option> 
;<option value="AJ">10</option>
;<option value="AA">11</option>
;<option value="AB">12</option>
;<option value="AC">13</option> 
;<option value="AD">14</option>
;<option value="AE">15</option>
;<option value="AF" selected="selected">16</option>   
;<option value="AG">17</option>
;<option value="AH">18</option>
;<option value="AI">19</option>
;<option value="BJ">20</option> 
;<option value="BA">21</option>
;<option value="BB">22</option>
;<option value="BC">23</option>   
;<option value="BD">24</option>   
txtBatch = 'AF' ; 16 theForm.txtBatch.value;

;<option value="0.5">0.5</option>
;<option value="0.6">0.6</option> 
;<option value="0.7">0.7</option>
;<option value="0.8">0.8</option>
;<option value="0.9">0.9</option>
;<option value="1.0" selected="selected">1.0</option> 
;<option value="1.1">1.1</option>
;<option value="1.2">1.2</option>
;<option value="1.3">1.3</option>   
;<option value="1.4">1.4</option> 
;<option value="1.5">1.5</option>
;<option value="1.6">1.6</option>
;<option value="1.7">1.7</option>
;<option value="1.8">1.8</option> 
;<option value="1.9">1.9</option>
;<option value="2.0">2.0</option>
txtSmag = ;theForm.txtSmag.value;


DoPrint(strExport, strTemplate, txtName, txtBatch, txtSmag)

exit
Deana F.
Technical Support
Wilson WindowWare Inc.

rothestar

Thanks Deana ;)

There was a small bug, but got it to print within 30 seconds..

Super thanks.... you cracked the code for me...

now I can move on to do the hard stuff:

My best regards
Henrik


Deana

Quote from: rothestar on February 19, 2014, 11:07:55 AM
Thanks Deana ;)

There was a small bug, but got it to print within 30 seconds..

Super thanks.... you cracked the code for me...

now I can move on to do the hard stuff:

My best regards
Henrik

Care to share details about the bug, for the next user?
Deana F.
Technical Support
Wilson WindowWare Inc.

rothestar

sure I will post the script when it is done...

Henrik

rothestar

Code (winbatch) Select
;advanced label print.wbt
;============================================================
;============================================================
;============================================================

path=dirscript()

#DefineFunction DoPrint(strExport, strTemplate, text1, text2)
   objDoc = ObjectCreate("bpac.Document")
   If objDoc.Open(strTemplate) != @false
      objDoc.GetObject("objText1").Text = text1   ;objtext1 must exist in the label.lbx template
      objDoc.GetObject("objText2").Text = text2   ;objtext2 must exist in the label.lbx template
      If strExport == ""
         ;objDoc.SetMediaByName(objDoc.Printer.GetMediaName(), @true)
         objDoc.StartPrint("", 0)
         objDoc.PrintOut(1, 0)
         objDoc.Close()
         objDoc.EndPrint()
      Else ;Print preview
         strExport = dirscript() : strExport; ;path to the preview file
         objDoc.Export(4, strExport, 180)
         objDoc.Close()
         ShellExecute(strExport, '', '', @NORMAL, '');show preview
      EndIf
   EndIf
#EndFunction

strExport = "Preview2.bmp" ; to preview
;strExport = "" ;to print
strTemplate = strcat(path,'label.lbx')  ;path to template label
text1 = "John" ; the text to print
text2 = "Doe" ; the text to print

DoPrint(strExport, strTemplate, text1, text2)

exit


the attached bmp shows the preview file

Deana

Deana F.
Technical Support
Wilson WindowWare Inc.