跳至主內容

搜尋

搜尋

How can I use Java code to set up a one-line multi-column label for the Bartender template?

評論

1 條評論

  • Avatar
    Xabier Clemente
    版主

    Hello Lala Kan,

    Welcome to the BarTender Community Forums!

    To print both the left and right labels when using a multi-column template in Bartender, you need to modify your code to specify the column position for each label before printing. Currently, your code is only setting the variable values in the template but not specifying the position.

    Here's an example of how you can modify your code to print both the left and right labels:

    // Open Template
    btFormat = Dispatch.call(btFormats, "Open", filePatch, false, "").toDispatch();
    Dispatch printSetup = Dispatch.get(btFormat, "PrintSetup").toDispatch();
    Dispatch.put(printSetup, "Printer", "TSC TE244");
    int size = printDatas.size();

    // Set column position
    Dispatch formatPrintJob = Dispatch.get(btFormat, "FormatPrintJob").toDispatch();
    Dispatch.put(formatPrintJob, "ColumnCount", 2);
    Dispatch.put(formatPrintJob, "ColumnSpacing", 0);  // Adjust the spacing as needed

    for (int i = 0; i < size; i++) {
        Map<String, String> printMap = printDatas.get(i);
        if (printMap != null) {
            for (Map.Entry<String, String> entry : printMap.entrySet()) {
                try {
                    // Replace variables in templates
                    Dispatch.call(btFormat, "SetNamedSubStringValue", entry.getKey(), entry.getValue());
                } catch (Exception e) {
                    // Handle any exceptions
                }
            }
        }

        // Specify column position and print
        Dispatch.put(formatPrintJob, "StartingPosition", i % 2 == 0 ? 0 : 1);
        Dispatch.call(formatPrintJob, "PrintOut");
    }

    // Close Template
    Dispatch.call(btFormat, "Close", 2);


    In the modified code, the FormatPrintJob object is used to set the column count to 2 and adjust the column spacing if necessary. Before each label is printed, the StartingPosition property is set to 0 for the left label and 1 for the right label based on the current iteration. This ensures that the content is printed in the correct columns.

    After printing all the labels, the template is closed using Dispatch.call(btFormat, "Close", 2).

    Finally, please make sure to adjust the column spacing and handle any exceptions according to your specific requirements.

    If you have further issues, we would recommend reaching our Professional Services team, who in exchange for a quote can help you with all your BarTender scripting needs.

    I hope this helps!

    0

登入寫評論。