2016-06-06 73 views
1

在发生时,让我说这些都是我一直试图找出打印Dymo 450 LabelWriter标签上的条形码问题的所有网站和地方。Dymo框架条码打印

http://developers.dymo.com/2010/06/02/dymo-label-framework-javascript-library-samples-print-a-label/ DYMO label JavaScript printing framework http://developers.dymo.com/2010/03/24/understanding-label-file-formats-in-dymo-label-v-8-label-objects/ Printing in Java to Label Printer

对DYMO网站是一个大烂摊子给我。我无法直接回答我所寻找的任何事情。我试图从他们的标签网站拼凑代码,它的工作原理。我想将条形码添加到标签。

这是我曾尝试:

PrintLabel.js

(function() 
    { 
     // called when the document completly loaded 
     function onload() 
     { 
      var textTextArea = document.getElementById('textTextArea'); 
      var barCode = document.getElementById('barCode'); 
      var printButton = document.getElementById('printButton'); 

      // prints the label 
      printButton.onclick = function() 
      { 
       try 
       { 
        // open label 
        var labelXml = '<?xml version="1.0" encoding="utf-8"?>\ 
     <DieCutLabel Version="8.0" Units="twips">\ 
      <PaperOrientation>Landscape</PaperOrientation>\ 
      <Id>Address</Id>\ 
      <PaperName>30252 Address</PaperName>\ 
      <DrawCommands/>\ 
      <ObjectInfo>\ 
       <TextObject>\ 
        <Name>Text</Name>\ 
        <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\ 
        <BackColor Alpha="0" Red="255" Green="255" Blue="255" />\ 
        <LinkedObjectName></LinkedObjectName>\ 
        <Rotation>Rotation0</Rotation>\ 
        <IsMirrored>False</IsMirrored>\ 
        <IsVariable>True</IsVariable>\ 
        <HorizontalAlignment>Left</HorizontalAlignment>\ 
        <VerticalAlignment>Middle</VerticalAlignment>\ 
        <TextFitMode>ShrinkToFit</TextFitMode>\ 
        <UseFullFontHeight>True</UseFullFontHeight>\ 
        <Verticalized>False</Verticalized>\ 
        <StyledText/>\ 
       </TextObject>\ 
       <Bounds X="332" Y="150" Width="4455" Height="160" />\ 
      </ObjectInfo>\ 
     <ObjectInfo>\ 
      <BarcodeObject>\ 
       <Name>Barcode</Name>\ 
       <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\ 
       <BackColor Alpha="0" Red="255" Green="255" Blue="255" />\ 
       <LinkedObjectName></LinkedObjectName>\ 
       <Rotation>Rotation0</Rotation>\ 
       <IsMirrored>False</IsMirrored>\ 
       <IsVariable>True</IsVariable>\ 
       <Text></Text>\ 
       <Type>Code39</Type>\ 
       <Size>Medium</Size>\ 
       <TextPosition>Bottom</TextPosition>\ 
       <TextFont Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\ 
       <CheckSumFont Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\ 
       <TextEmbedding>None</TextEmbedding>\ 
       <ECLevel>0</ECLevel>\ 
       <HorizontalAlignment>Center</HorizontalAlignment>\ 
       <QuietZonesPadding Left="0" Top="0" Right="0" Bottom="0" />\ 
      </BarcodeObject>\ 
      <Bounds X="224" Y="150" Width="150" Height="120" />\ 
     </ObjectInfo>\ 
     </DieCutLabel>'; 
        var label = dymo.label.framework.openLabelXml(labelXml); 

        // set label text 
        label.setObjectText("Text", textTextArea.value); 
        label.setObjectText("BARCODE", '721'); 

        // select printer to print on 
        // for simplicity sake just use the first LabelWriter printer 
        var printers = dymo.label.framework.getPrinters(); 
        if (printers.length == 0) 
         throw "No DYMO printers are installed. Install DYMO printers."; 

        var printerName = ""; 
        for (var i = 0; i < printers.length; ++i) 
        { 
         var printer = printers[i]; 
         if (printer.printerType == "LabelWriterPrinter") 
         { 
          printerName = printer.name; 
          break; 
         } 
        } 

        if (printerName == "") 
         throw "No LabelWriter printers found. Install LabelWriter printer"; 

        // finally print the label 
        label.print(printerName); 
       } 
       catch(e) 
       { 
        alert(e.message || e); 
       } 
      } 
     }; 

     // register onload event 
     if (window.addEventListener) 
      window.addEventListener("load", onload, false); 
     else if (window.attachEvent) 
      window.attachEvent("onload", onload); 
     else 
      window.onload = onload; 

    }()); 

这里是HTML:

<!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> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    <title>Print a Label</title> 
    <script src = "http://labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.latest.js" type="text/javascript" charset="UTF-8"> </script> 
    <script src = "PrintLabel.js" type="text/javascript" charset="UTF-8"> </script> 
    </head> 

    <body> 
    <h2>Lab Label</h2> 

     <div id="textDiv"> 
      <label for="textTextArea">Label :</label><br/> 
      <textarea name="textTextArea" id="textTextArea" rows='5' cols='20'> 
    <?php echo $name ."\n"; ?> 
    <?php echo date("Y-m-d") . "&#160;&#160;&#160;&#160;&#160;&#160;" .$oid."\n"; ?> 


      </textarea> 

      <input type="text" id="barCode" value="786"> 
     </div> 

      <div id="printDiv"> 
       <button id="printButton">Print</button> 
      </div> 

    </body> 

    </html> 

我从 添加什么http://developers.dymo.com/2010/03/24/understanding-label-file-formats-in-dymo-label-v-8-label-objects/

部位是条码对象。我以为我可以放下它,只是在工作。但我注意到TextObject代码似乎也没有做太多。

任何建议将不胜感激。

+0

你是伟大的人!我找到解决我的问题。谢谢! –

回答

1

这里是最后的代码,现在适用于Print.js文件。

(function() 
    { 
     // called when the document completly loaded 
     function onload() 
     { 
      var textTextArea = document.getElementById('textTextArea'); 
      var barCode = document.getElementById('barCode');  
      var printButton = document.getElementById('printButton'); 

      // prints the label 
      printButton.onclick = function() 
      { 
       try 
       { 
        // open label 
        var labelXml = '<?xml version="1.0" encoding="utf-8"?>\ 
     <DieCutLabel Version="8.0" Units="twips">\ 
      <PaperOrientation>Landscape</PaperOrientation>\ 
      <Id>Address</Id>\ 
      <PaperName>30252 Address</PaperName>\ 
      <DrawCommands/>\ 
      <ObjectInfo>\ 
       <TextObject>\ 
        <Name>Text</Name>\ 
        <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\ 
        <BackColor Alpha="0" Red="255" Green="255" Blue="255" />\ 
        <LinkedObjectName></LinkedObjectName>\ 
        <Rotation>Rotation0</Rotation>\ 
        <IsMirrored>False</IsMirrored>\ 
        <IsVariable>True</IsVariable>\ 
        <HorizontalAlignment>Left</HorizontalAlignment>\ 
        <VerticalAlignment>Middle</VerticalAlignment>\ 
        <TextFitMode>ShrinkToFit</TextFitMode>\ 
        <UseFullFontHeight>True</UseFullFontHeight>\ 
        <Verticalized>False</Verticalized>\ 
        <StyledText/>\ 
       </TextObject>\ 
       <Bounds X="332" Y="150" Width="4455" Height="1260" />\ 
      </ObjectInfo>\ 
      <ObjectInfo>\ 
      <BarcodeObject>\ 
       <Name>Barcode</Name>\ 
       <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\ 
       <BackColor Alpha="0" Red="255" Green="255" Blue="255" />\ 
       <LinkedObjectName>BarcodeText</LinkedObjectName>\ 
       <Rotation>Rotation0</Rotation>\ 
       <IsMirrored>False</IsMirrored>\ 
       <IsVariable>True</IsVariable>\ 
       <Text>barCode</Text>\ 
       <Type>Code128Auto</Type>\ 
       <Size>Medium</Size>\ 
       <TextPosition>Bottom</TextPosition>\ 
       <TextFont Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\ 
       <CheckSumFont Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\ 
       <TextEmbedding>None</TextEmbedding>\ 
       <ECLevel>0</ECLevel>\ 
       <HorizontalAlignment>Center</HorizontalAlignment>\ 
       <QuietZonesPadding Left="0" Top="0" Right="0" Bottom="0" />\ 
      </BarcodeObject>\ 
      <Bounds X="324" Y="950" Width="3150" Height="520" />\ 
     </ObjectInfo>\ 
     </DieCutLabel>'; 
        var label = dymo.label.framework.openLabelXml(labelXml); 

        // set label text 
        label.setObjectText("Text", textTextArea.value); 
        label.setObjectText('Barcode', barCode.value);     
        // select printer to print on 
        // for simplicity sake just use the first LabelWriter printer 
        var printers = dymo.label.framework.getPrinters(); 
        if (printers.length == 0) 
         throw "No DYMO printers are installed. Install DYMO printers."; 

        var printerName = ""; 
        for (var i = 0; i < printers.length; ++i) 
        { 
         var printer = printers[i]; 
         if (printer.printerType == "LabelWriterPrinter") 
         { 
          printerName = printer.name; 
          break; 
         } 
        } 

        if (printerName == "") 
         throw "No LabelWriter printers found. Install LabelWriter printer"; 

        // finally print the label 
        label.print(printerName); 
       } 
       catch(e) 
       { 
        alert(e.message || e); 
       } 
      } 
     }; 

     // register onload event 
     if (window.addEventListener) 
      window.addEventListener("load", onload, false); 
     else if (window.attachEvent) 
      window.attachEvent("onload", onload); 
     else 
      window.onload = onload; 

    }());