0

I'm a novice programmer and I'm trying to print a single cell of data at a time from a Google sheet, but the Labelwriter 450 Twin Turbo doesn't initialize or print - nothing happens. Do I need to initialize the printer? Here's the javascript that I've added to code.gs.

Any hints pr help would be much appreciated?

//Load JavaScript from External Server

function LoadJSFromServer() {

  var response = UrlFetchApp.fetch("http://labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.latest.js");
  Logger.log(response.getContentText());
  }

//function loadJSFromServer() {
//  var url = "http://labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.latest.js";
//  var javascript = UrlFetchApp.fetch(url).getContentText();
//  eval(javascript);
//  Logger.log(javascript.getContentText());
//}

//Custom menu on open

function onOpen() {
  var spreadsheet = SpreadsheetApp.getActive();
  var menuItems = [
    {name: 'Print Label...', functionName: 'PrintLabel'},
  ];
  spreadsheet.addMenu('Print Label', menuItems);
  }

function PrintLabel() {

// prints the label

                try
                {
// open label
   var labelXml = '<?xml version="1.0" encoding="utf-8"?>\
        <DieCutLabel Version="8.0" Units="twips">\
    <PaperOrientation>Landscape</PaperOrientation>\
    <Id>Address</Id>\
    <IsOutlined>false</IsOutlined>\
    <PaperName>30252</PaperName>\
    <DrawCommands>\
        <RoundRectangle X="0" Y="0" Width="1581" Height="5040" Rx="270" Ry="270" />\
    </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 />\
            <Rotation>Rotation0</Rotation>\
            <IsMirrored>False</IsMirrored>\
            <IsVariable>True</IsVariable>\
            <GroupID>-1</GroupID>\
            <IsOutlined>False</IsOutlined>\
            <HorizontalAlignment>Center</HorizontalAlignment>\
            <VerticalAlignment>Middle</VerticalAlignment>\
            <TextFitMode>ShrinkToFit</TextFitMode>\
            <UseFullFontHeight>True</UseFullFontHeight>\
            <Verticalized>False</Verticalized>\
            <RollSelection>Left>/RollSelection>\
            <StyledText>\
                <Element>\
                    <String xml:space="preserve">Name Order Timestamp</String>\
                    <Attributes>\
                        <Font Family="Arial" Size="20" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
                        <ForeColor Alpha="255" Red="0" Green="0" Blue="0" HueScale="100" />\
                    </Attributes>\
                </Element>\
            </StyledText>\
        </TextObject>\
        <Bounds X="331" Y="150" Width="4560" Height="1343" />\
    </ObjectInfo>\
</DieCutLabel>';

    return labelXml;

    var label = dymo.label.framework.openLabelXml(labelXml);

    // set label text

    label.setObjectText("Text", textTextArea.value);

    // select printer to print on
    // 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";

  // print the label
     label.print(printerName);
}
     catch(e)
     {
     alert(e.message || e);
     }
}
}
mickeychcg
  • 43
  • 7
  • What research have you done? For example, what about http://developers.dymo.com/2010/06/02/dymo-label-framework-javascript-library-samples-print-a-label/ doesn't apply? This helps people not duplicate your work. –  Oct 11 '18 at 21:16
  • Yes, I can appreciate that. I've spent add'l time searching Google's site and had some help from a consultant. However, the real issue with this is G Apps scripting and it's lack of support for global variables, i.e., (from Google documentation)... ...because Apps Script code runs on Google's servers (not client-side, except for HTML-service pages), browser-based features like DOM manipulation or the Window API are not available. So finding the printer that's not a network print server adds an additional challenge to issue. – mickeychcg Oct 12 '18 at 22:14
  • Are you running your javascript from a browser page using https? If so, you are probably getting caught up with a browser security check that won't load dymo library from http into a page secured with https. – Don Oct 29 '18 at 16:43

0 Answers0