How can I use Java code to set up a one-line multi-column label for the Bartender template?
I am using com to call ActiveX to enable Java to print labels using Bartender. If the label paper to be printed is single-column, then the printing effect is normal. However, if the template page is set to multi-column mode with one row and two or more columns in the Bartender software, the actual effect of the following code is that only the left label has content and the right label has no content. How can I modify the code to make both the left and right labels have data?
//open Templete
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();
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){
}
}
}
Dispatch.call(btFormat,"PrintOut",false,false);
-
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 neededfor (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
請登入寫評論。
評論
1 條評論