Package com.zebra.sdk.printer
Class PrinterUtil
Object
com.zebra.sdk.printer.PrinterUtil
Numerous utilities to simplify printer operations
package test.zebra.sdk.printer.examples;
import java.io.IOException;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.device.ZebraIllegalArgumentException;
import com.zebra.sdk.printer.NotALinkOsPrinterException;
import com.zebra.sdk.printer.PrinterUtil;
import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
public class PrinterUtilExample {
private static final String CONNECTION_STRING = "172.30.16.135";
public static void main(String[] args) throws ConnectionException, IOException, ZebraIllegalArgumentException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException {
// Create a few files on the printer
sendContentsExample();
// List the files just created
listFilesExample();
// Silently delete some of the files
deleteFilesExample();
// List the remaining files
listFilesExample();
// Verbosely delete the rest of the files
deleteFilesVerboseExample();
// List the remaining files
listFilesExample();
}
private static void sendContentsExample() throws ConnectionException, IOException {
PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST1.ZPL^FO100,100^A0N,30,30^FDZSDK_Test1.zpl^FS^XZ");
PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST2.ZPL^FO100,100^A0N,30,30^FDZSDK_Test2.zpl^FS^XZ");
PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST3.ZPL^FO100,100^A0N,30,30^FDZSDK_Test3.zpl^FS^XZ");
PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST4.ZPL^FO100,100^A0N,30,30^FDZSDK_Test4.zpl^FS^XZ");
PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST11.ZPL^FO100,100^A0N,30,30^FDZSDK_Test11.zpl^FS^XZ");
PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST12.ZPL^FO100,100^A0N,30,30^FDZSDK_Test12.zpl^FS^XZ");
PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST22.ZPL^FO100,100^A0N,30,30^FDZSDK_Test22.zpl^FS^XZ");
PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST33.ZPL^FO100,100^A0N,30,30^FDZSDK_Test33.zpl^FS^XZ");
PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST44.ZPL^FO100,100^A0N,30,30^FDZSDK_Test44.zpl^FS^XZ");
}
private static void listFilesExample() throws ConnectionException, ZebraIllegalArgumentException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException {
String[] filesOnE = PrinterUtil.listFiles(CONNECTION_STRING, "R:ZSDK_TEST*.*");
System.out.println("--- List of Files on R: ---");
for (String thisFile : filesOnE) {
System.out.println(" - " + thisFile);
}
System.out.println("--- End of List ---");
}
private static void deleteFilesExample() throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException {
System.out.println("Deleting R:ZSDK_TEST1*.ZPL...");
PrinterUtil.deleteFile(CONNECTION_STRING, "R:ZSDK_TEST1*.ZPL");
}
private static void deleteFilesVerboseExample() throws ConnectionException, ZebraPrinterLanguageUnknownException, ZebraIllegalArgumentException, NotALinkOsPrinterException {
System.out.println("Verbosely Deleting R:ZSDK_TEST*.ZPL...");
String[] filesDeleted = PrinterUtil.deleteFileReportDeleted(CONNECTION_STRING, "R:ZSDK_TEST*.ZPL");
for (String thisDeletedFile : filesDeleted) {
System.out.println(" - " + thisDeletedFile + " deleted");
}
}
}
.-
Field Summary
FieldsModifier and TypeFieldDescription -
Method Summary
Modifier and TypeMethodDescriptionstatic voidconvertGraphic(String filePathOnPrinter, ZebraImageI image, int width, int height, OutputStream convertedGraphicOutputStream) Encodes supplied image in either ZPL or CPCL after dithering and resizing.static voidconvertGraphic(String filePathOnPrinter, ZebraImageI image, OutputStream convertedGraphicOutputStream) Encodes supplied image in either ZPL or CPCL after dithering and resizing.static voidcreateBackup(String connectionString, String profilePath) Create a backup of your printer's settings, alerts, and files.static voidcreateProfile(String connectionString, String profilePath) Create a profile of your printer's settings, alerts, and files for cloning to other printers.static voiddeleteFile(String connectionString, String filePath) Deletes file(s) from the printer.static voiddeleteFile(String connectionString, String filePath, String authPassword) For printers in Protected Mode: Deletes file(s) from the printer.static String[]deleteFileReportDeleted(String connectionString, String filePath) Deletes file(s) from the printer and reports what files were actually removed.static String[]deleteFileReportDeleted(String connectionString, String filePath, String authPassword) For printers in Protected Mode: Deletes file(s) from the printer and reports what files were actually removed.static PrinterStatusgetCurrentStatus(Connection printerConnection, PrinterLanguage language) Returns a new instance ofPrinterStatusthat can be used to determine the status of a printer.static voidgetObjectFromPrinter(OutputStream destinationStream, String connectionString, String filePathOnPrinter) Retrieves a file from the printer's file system and writes the contents of that file to an output stream.static byte[]getObjectFromPrinter(String connectionString, String filePathOnPrinter) Retrieves a file from the printer's file system and returns the contents of that file as a byte[].static voidgetObjectFromPrinterViaFtp(OutputStream destination, String connectionString, String filePathOnPrinter, String ftpPassword) Retrieves a file from the printer's file system via FTP and writes the contents of that file to an output stream.static byte[]getObjectFromPrinterViaFtp(String connectionString, String filePathOnPrinter, String ftpPassword) Retrieves a file from the printer's file system via FTP and returns the contents of that file as a byte[].getOdometerStatus(String connectionString) Retrieves status of the printer odometer which includes the total print length, head clean counter, label dot length, head new, latch open counter, and both user resettable counters.
See ConnectionBuilder for the format ofconnectionString.static List<TcpPortStatus> getPortStatus(String connectionString) Retrieves a list of currently open tcp ports on the printer.
See ConnectionBuilder for the format ofconnectionString.getPrinterStatus(String connectionString) Retrieves status of the printer which includes any error messages currently set along with the number of labels remaining in queue, number of labels remaining in batch, and whether or not a label is currently being processed.getSettingsFromPrinter(String connectionString) Retrieve all settings and their attributes from the specified printer.
See ConnectionBuilder for the format ofconnectionString.static booleanisPrintingChannelInLineMode(Connection connection, PrinterLanguage printerLanguage) Checking line-print modestatic String[]Retrieves the names of the files which are stored on the device.
See ConnectionBuilder for the format ofconnectionString.static voidloadBackup(String connectionString, String backupPath) Takes settings, alerts, and files from a backup, and applies them to a printer.static voidloadBackup(String connectionString, String backupPath, boolean isVerbose) Takes settings, alerts, and files from a backup, and applies them to a printer.static voidloadProfile(String connectionString, String profilePath, FileDeletionOption filesToDelete) Takes settings, alerts, and files from a profile, and applies them to a printer.static voidloadProfile(String connectionString, String profilePath, FileDeletionOption filesToDelete, boolean isVerbose) Takes settings, alerts, and files from a profile, and applies them to a printer.static voidprintConfigLabel(String connectionString) Prints the configuration label on a printer using the specified connection string.static voidprintDirectoryLabel(String connectionString) Causes the specified printer to print a directory listing of all the files saved on the printer.
See ConnectionBuilder for the format ofconnectionString.static voidprintNetworkConfigLabel(String connectionString) Causes the specified printer to print a network configuration label.
See ConnectionBuilder for the format ofconnectionString.static StringquickStatus(String connectionString) Retrieves the quick status of the printer.
See ConnectionBuilder for the format ofconnectionString.static voidresetNetwork(String connectionString) Resets the network of the specified printer.static voidresetNetwork(String connectionString, String authPassword) For printers in Protected Mode: Resets the network configuration of a Zebra printer connected via the specified connection string.static voidresetPrinter(String connectionString) static voidresetPrinter(String connectionString, String authPassword) For printers in Protected Mode: Resets the specified printer.static voidrestoreAsmDefaults(String connectionString, String authPassword, String sgdBranch) For printers in Protected Mode: Restores the specified SGD branch(ip,wlan or power etc) configuration settings of a Zebra Link-OS printer in protected mode to their default values.static voidrestoreNetworkDefaults(String connectionString) Restores the network settings of a Zebra Link-OS printer to their default values.static voidrestorePrinterDefaults(String connectionString) Restores a Zebra printer to its default settings.static voidsendContents(String connectionString, InputStream data) Send contents ofdatadirectly to the device specified viaconnectionStringusing UTF-8 encoding.
See ConnectionBuilder for the format ofconnectionString.static voidsendContents(String connectionString, InputStream data, String encoding) Send contents ofdatadirectly to the device specified viaconnectionStringusingencoding.
See ConnectionBuilder for the format ofconnectionString.static voidsendContents(String connectionString, String data) Send contents ofdatadirectly to the device specified viaconnectionStringusing UTF-8 encoding.static voidsendContents(String connectionString, String data, String encoding) Send contents ofdatadirectly to the device specified viaconnectionStringusingencoding.
See ConnectionBuilder for the format ofconnectionString.static voidsendJSON(String connectionString, InputStream data, String encoding) Send contents ofdatadirectly to the device specified viaconnectionStringusingencoding.
See ConnectionBuilder for the format ofconnectionString.static voidstatic voidStores the file on the printer at the specified location and with specified name using any required file wrappers.
See ConnectionBuilder for the format ofconnectionString.static voidFor printers in Protected Mode: Stores the file on the printer at the specified location and name using any required file wrappers.
If the printer is in protected mode, authentication is required via the provided password for file types (NRD, NRE and PAC).static voidupdateFirmware(String connection, String firmwareFilePath, long timeout) Update the printer firmware.static booleanvalidExtensionForPrinterProtected(String filePath) static booleanvalidSGDBranchName(String sgdBranchName)
-
Field Details
-
validExtensionsForPrinterProtected
-
validSGDBranchNames
-
-
Method Details
-
sendContents
public static void sendContents(String connectionString, String data) throws ConnectionException, IOException Send contents ofdatadirectly to the device specified viaconnectionStringusing UTF-8 encoding.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.data- Data to send to the printer.- Throws:
IOException- if there is an error encodingdata.ConnectionException- if there is an error communicating with the printer.
-
sendContents
public static void sendContents(String connectionString, String data, String encoding) throws ConnectionException, IOException Send contents ofdatadirectly to the device specified viaconnectionStringusingencoding.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.data- Data to send to the printer.encoding- A character-encoding name (eg. UTF-8).- Throws:
ConnectionException- if there is an error communicating with the printer.IOException- if there is an error encodingdata.
-
sendContents
public static void sendContents(String connectionString, InputStream data) throws ConnectionException, IOException Send contents ofdatadirectly to the device specified viaconnectionStringusing UTF-8 encoding.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.data- Data to send to the printer.- Throws:
ConnectionException- if there is an error communicating with the printer.IOException- if there is an error reading fromdata.
-
sendContents
public static void sendContents(String connectionString, InputStream data, String encoding) throws ConnectionException, IOException Send contents ofdatadirectly to the device specified viaconnectionStringusingencoding.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.data- Data to send to the printer.encoding- A character-encoding name (eg. UTF-8).- Throws:
ConnectionException- if there is an error communicating with the printer.IOException- if there is an error reading fromdata.
-
sendJSON
public static void sendJSON(String connectionString, InputStream data, String encoding) throws ConnectionException, IOException Send contents ofdatadirectly to the device specified viaconnectionStringusingencoding.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.data- Data to send to the printer.encoding- A character-encoding name (eg. UTF-8).- Throws:
ConnectionException- if there is an error communicating with the printer.IOException- if there is an error reading fromdata.
-
getPortStatus
public static List<TcpPortStatus> getPortStatus(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Retrieves a list of currently open tcp ports on the printer.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.- Returns:
- The port status.
- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
getOdometerStatus
public static List<String> getOdometerStatus(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Retrieves status of the printer odometer which includes the total print length, head clean counter, label dot length, head new, latch open counter, and both user resettable counters.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.- Returns:
- The odometer status.
- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
getPrinterStatus
public static List<String> getPrinterStatus(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Retrieves status of the printer which includes any error messages currently set along with the number of labels remaining in queue, number of labels remaining in batch, and whether or not a label is currently being processed.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.- Returns:
- The printer status.
- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
quickStatus
public static String quickStatus(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Retrieves the quick status of the printer.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.- Returns:
- Highest level error or "Ready to Print"
- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
setClock
public static void setClock(String connectionString, String dateTime) throws ConnectionException, ZebraPrinterLanguageUnknownException, ZebraIllegalArgumentException, NotALinkOsPrinterException - Parameters:
connectionString- The connection string.dateTime- Format MM-dd-yyyy HH:mm:ss- Throws:
ConnectionException- if there is an error communicating with the printer.ZebraPrinterLanguageUnknownException- if the printer language can not be determined.ZebraIllegalArgumentException- if the format ofdateTimeis invalid.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
deleteFileReportDeleted
public static String[] deleteFileReportDeleted(String connectionString, String filePath) throws ConnectionException, ZebraPrinterLanguageUnknownException, ZebraIllegalArgumentException, NotALinkOsPrinterException Deletes file(s) from the printer and reports what files were actually removed. ThefilePathmay also contain wildcards.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string. (May be null)filePath- The location of the file on the printer. Wildcards are also accepted. (e.g. "E:FORMAT.ZPL", "E:*.*")- Returns:
- An array of the files which were deleted.
- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language cannot be determined.ZebraIllegalArgumentException- if there is an error parsing the directory data returned by the device.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
deleteFileReportDeleted
public static String[] deleteFileReportDeleted(String connectionString, String filePath, String authPassword) throws ConnectionException, ZebraPrinterLanguageUnknownException, ZebraIllegalArgumentException, NotALinkOsPrinterException For printers in Protected Mode: Deletes file(s) from the printer and reports what files were actually removed. ThefilePathmay also contain wildcards.
If the printer is in protected mode, authentication is required via the provided password. If the printer is not in protected mode, the file will be deleted without authentication. See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string. (May be null)filePath- The location of the file on the printer. Wildcards are also accepted. (e.g. "E:FORMAT.ZPL", "E:*.*")authPassword- Password to use for deleting the file in protected mode.- Returns:
- An array of the files which were deleted.
- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language cannot be determined.ZebraIllegalArgumentException- if there is an error parsing the directory data returned by the device.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
deleteFile
public static void deleteFile(String connectionString, String filePath) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException Deletes file(s) from the printer. ThefilePathmay also contain wildcards.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string. (May be null)filePath- the location of the file on the printer. Wildcards are also accepted. (e.g. "E:FORMAT.ZPL", "E:*.*")- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language cannot be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException
-
deleteFile
public static void deleteFile(String connectionString, String filePath, String authPassword) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException For printers in Protected Mode: Deletes file(s) from the printer. ThefilePathmay also contain wildcards.
If the printer is in protected mode, authentication is required via the provided password. If the printer is not in protected mode, the file will be deleted without authentication. See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string. (May be null)filePath- the location of the file on the printer. Wildcards are also accepted. (e.g. "E:FORMAT.ZPL", "E:*.*")authPassword- Password to use for deleting the file in protected mode.- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language cannot be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException
-
listFiles
public static String[] listFiles(String connectionString, String filter) throws ConnectionException, ZebraIllegalArgumentException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Retrieves the names of the files which are stored on the device.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string. (May be null)filter- Filter for returned files. (e.g. "E:*.ZPL", "*:*.*", "R:MYFILE.*")- Returns:
- List of file names on the printer.
- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language cannot be determined.ZebraIllegalArgumentException- if there is an error parsing the directory data returned by the device.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
getObjectFromPrinter
public static byte[] getObjectFromPrinter(String connectionString, String filePathOnPrinter) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException Retrieves a file from the printer's file system and returns the contents of that file as a byte[]. Will retrieve the following file extensions: .FNT, .ZPL, .GRF, .DAT, .BAS, .STO, .PNG, .LBL, .TTF, .PCX, .BMP, .IMG, .TTE, .WML, .CSV, .HTM, .BAE, .TXT.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.filePathOnPrinter- file to retrieve. (e.g. "R:MYFILE.PNG")- Returns:
- byte[] File contents.
- Throws:
ConnectionException- if there is an error connecting to the device, or the ftp password is not correct.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException- if the filename is invalid or does not exist.
-
getObjectFromPrinter
public static void getObjectFromPrinter(OutputStream destinationStream, String connectionString, String filePathOnPrinter) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException Retrieves a file from the printer's file system and writes the contents of that file to an output stream. Will retrieve the following file extensions: .FNT, .ZPL, .GRF, .DAT, .BAS, .STO, .PNG, .LBL, .TTF, .PCX, .BMP, .IMG, .TTE, .WML, .CSV, .HTM, .BAE, .TXT.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
destinationStream- Stream to receive file contents.connectionString- The connection string.filePathOnPrinter- file to retrieve. (e.g. "R:MYFILE.PNG")- Throws:
ConnectionException- if there is an error connecting to the device, or the ftp password is not correct.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException- if the filename is invalid or does not exist.
-
getObjectFromPrinterViaFtp
public static byte[] getObjectFromPrinterViaFtp(String connectionString, String filePathOnPrinter, String ftpPassword) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException Retrieves a file from the printer's file system via FTP and returns the contents of that file as a byte[]. Will retrieve the following file extensions: .FNT, .ZPL, .GRF, .DAT, .BAS, .STO, .PNG, .LBL, .TTF, .PCX, .BMP, .IMG, .TTE, .WML, .CSV, .HTM, .BAE, .TXT.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.filePathOnPrinter- File to retrieve. (e.g. "R:MYFILE.PNG")ftpPassword- Password to use for ftp, if null a default password will be used.- Returns:
- byte[] File contents.
- Throws:
ConnectionException- if there is an error connecting to the device, or the ftp password is not correct.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException- if the filename is invalid or does not exist.
-
getObjectFromPrinterViaFtp
public static void getObjectFromPrinterViaFtp(OutputStream destination, String connectionString, String filePathOnPrinter, String ftpPassword) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException Retrieves a file from the printer's file system via FTP and writes the contents of that file to an output stream. Will retrieve the following file extensions: .FNT, .ZPL, .GRF, .DAT, .BAS, .STO, .PNG, .LBL, .TTF, .PCX, .BMP, .IMG, .TTE, .WML, .CSV, .HTM, .BAE, .TXT.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
destination- Stream to receive the file contents.connectionString- The connection string.filePathOnPrinter- File to retrieve. (e.g. "R:MYFILE.PNG")ftpPassword- password to use for ftp, if null a default password will be used.- Throws:
ConnectionException- if there is an error connecting to the device, or the ftp password is not correct.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException- if the filename is invalid or does not exist.
-
updateFirmware
public static void updateFirmware(String connection, String firmwareFilePath, long timeout) throws ConnectionException, ZebraPrinterLanguageUnknownException, ZebraIllegalArgumentException, DiscoveryException, TimeoutException, FileNotFoundException Update the printer firmware.
Download Firmware Here
See ConnectionBuilder for the format ofconnection.- Parameters:
connection- The connection string.firmwareFilePath- File path of firmware file.timeout- Timeout in milliseconds. The minimum allowed timeout is 10 minutes (600000ms) due to the need to reset the printer after flashing the firmware. If a timeout value less than the minimum is provided, the minimum will be used instead.- Throws:
ConnectionException- if the connection can not be opened or is closed prematurely.ZebraPrinterLanguageUnknownException- if the printer language can not be determined.ZebraIllegalArgumentException- if an invalid firmware file is specified for the printer.DiscoveryException- if an error occurs while waiting for the printer to come back online.TimeoutException- if the maximum timeout is reached prior to the printer coming back online with the new firmware.FileNotFoundException- if the firmware file cannot be found or cannot be opened.
-
convertGraphic
public static void convertGraphic(String filePathOnPrinter, ZebraImageI image, OutputStream convertedGraphicOutputStream) throws ZebraIllegalArgumentException, IOException Encodes supplied image in either ZPL or CPCL after dithering and resizing.- Parameters:
filePathOnPrinter- The printer file path you wish to store the image to.image- ZebraImage to be dithered and resized.convertedGraphicOutputStream- OutputStream to store encoded image data.- Throws:
ZebraIllegalArgumentException- if the file type is not supported or an invalid image is supplied.IOException- Could not read/write to file.
-
convertGraphic
public static void convertGraphic(String filePathOnPrinter, ZebraImageI image, int width, int height, OutputStream convertedGraphicOutputStream) throws ZebraIllegalArgumentException, IOException Encodes supplied image in either ZPL or CPCL after dithering and resizing.- Parameters:
filePathOnPrinter- The printer file path you wish to store the image to.image- ZebraImage to be dithered and resized.width- Width of the resulting image. If 0 the image is not resized.height- Height of the resulting image. If 0 the image is not resized.convertedGraphicOutputStream- OutputStream to store converted image data encoded with the printers native language.- Throws:
ZebraIllegalArgumentException- if the file type is not supported or an invalid image is supplied.IOException- Could not read/write to file.
-
createProfile
public static void createProfile(String connectionString, String profilePath) throws IOException, ZebraIllegalArgumentException, ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Create a profile of your printer's settings, alerts, and files for cloning to other printers. A profile contains setting values which can be used to clone another printer to match the original configuration. Some settings (such as I.P. address) which could conflict with the original printer will not be contained in the profile
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.profilePath- The location of where to store the profile.- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.IOException- if there is an issue creating the profile.ZebraIllegalArgumentException- Could not interpret the response from the printer.NotALinkOsPrinterException- This feature is only available on Link-OS printers.- See Also:
-
createBackup
public static void createBackup(String connectionString, String profilePath) throws ConnectionException, IOException, ZebraPrinterLanguageUnknownException, ZebraIllegalArgumentException, NotALinkOsPrinterException Create a backup of your printer's settings, alerts, and files. A backup contains a snapshot of all pertinent settings to fully restore your printer.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.profilePath- The location of where to store the profile. The extension must be .zprofile; if it is not, the method will change it to .zprofile for you.- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.IOException- if there is an issue creating the profile.ZebraIllegalArgumentException- Could not interpret the response from the printer.NotALinkOsPrinterException- This feature is only available on Link-OS printers.- See Also:
-
loadProfile
public static void loadProfile(String connectionString, String profilePath, FileDeletionOption filesToDelete) throws ConnectionException, IOException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Takes settings, alerts, and files from a profile, and applies them to a printer. Before doing so, it deletes the files described byfilesToDeletefrom the printer.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.profilePath- Path to the profile to load. (e.g. /home/user/profile.zprofile)filesToDelete- An enum describing which files to delete.- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.IOException- if there is an issue loading the profile.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
loadProfile
public static void loadProfile(String connectionString, String profilePath, FileDeletionOption filesToDelete, boolean isVerbose) throws ConnectionException, IOException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Takes settings, alerts, and files from a profile, and applies them to a printer. Before doing so, it deletes the files described byfilesToDeletefrom the printer.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.profilePath- Path to the profile to load. (e.g. /home/user/profile.zprofile)filesToDelete- An enum describing which files to delete.isVerbose- Increases the amount of detail presented to the user.- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.IOException- if there is an issue loading the profile.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
loadBackup
public static void loadBackup(String connectionString, String backupPath) throws ConnectionException, IOException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Takes settings, alerts, and files from a backup, and applies them to a printer. This method will also delete all files on your printer before applying the backup.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.backupPath- Path to the profile to load. (e.g. /home/user/profile.zprofile)- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.IOException- if there is an issue loading the profile.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
loadBackup
public static void loadBackup(String connectionString, String backupPath, boolean isVerbose) throws ConnectionException, IOException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Takes settings, alerts, and files from a backup, and applies them to a printer. This method will also delete all files on your printer before applying the backup.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.backupPath- Path to the profile to load. (e.g. /home/user/profile.zprofile)isVerbose- Increases the amount of detail presented to the user.- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.IOException- if there is an issue loading the profile.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
storeFile
public static void storeFile(String connectionString, String filePath, String remoteName, String authPassword) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException, IOException For printers in Protected Mode: Stores the file on the printer at the specified location and name using any required file wrappers.
If the printer is in protected mode, authentication is required via the provided password for file types (NRD, NRE and PAC). If the printer is not in protected mode, file is stored without authentication. See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.filePath- The path of the file to store.remoteName- The path on the printer.authPassword- Password to use for storing the file in protected mode- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.IOException- if there is an issue storing the file.NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException- if there is an issue storing the file.
-
storeFile
public static void storeFile(String connectionString, String filePath, String remoteName) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException, IOException Stores the file on the printer at the specified location and with specified name using any required file wrappers.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.filePath- The path of the file to store.remoteName- The path on the printer.- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.IOException- if there is an issue storing the file.NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException- if there is an issue storing the file.
-
resetPrinter
public static void resetPrinter(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException - Parameters:
connectionString- The connection string.- Throws:
ConnectionException- if there is an error connecting to the deviceZebraPrinterLanguageUnknownException- if the printer language could not be determinedNotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException
-
resetPrinter
public static void resetPrinter(String connectionString, String authPassword) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException For printers in Protected Mode: Resets the specified printer.
If the printer is in protected mode, authentication is required via the provided password. If the printer is not in protected mode, it resets without authentication.- Parameters:
connectionString- The connection string.authPassword- The authentication password for protected mode.- Throws:
ConnectionException- if there is an error connecting to the deviceZebraPrinterLanguageUnknownException- if the printer language could not be determinedNotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException
-
resetNetwork
public static void resetNetwork(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException Resets the network of the specified printer. Usually performed to enable changed network settings to take effect.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.- Throws:
ConnectionException- if there is an error connecting to the deviceZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraIllegalArgumentException
-
resetNetwork
public static void resetNetwork(String connectionString, String authPassword) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException For printers in Protected Mode: Resets the network configuration of a Zebra printer connected via the specified connection string.
If the printer is in protected mode, authentication is required via the provided password. If the printer is not in protected mode, the network is reset without authentication.- Parameters:
connectionString- the connection string used to establish a connection to the printerauthPassword- the authentication password required if the printer is in protected mode- Throws:
ConnectionException- if a connection to the printer cannot be established or maintainedZebraPrinterLanguageUnknownException- if the printer's language cannot be determinedNotALinkOsPrinterException- if the printer is not a Link-OS enabled printerZebraIllegalArgumentException- if any of the provided arguments are invalid
-
restorePrinterDefaults
public static void restorePrinterDefaults(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException Restores a Zebra printer to its default settings.- Parameters:
connectionString- the connection string used to establish a connection to the printer- Throws:
ConnectionException- if a connection to the printer cannot be establishedZebraPrinterLanguageUnknownException- if the printer's language cannot be determinedNotALinkOsPrinterException- if the printer is not a Link-OS printerZebraIllegalArgumentException- if the printer is in protected mode and requires a password
-
restoreNetworkDefaults
public static void restoreNetworkDefaults(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException Restores the network settings of a Zebra Link-OS printer to their default values.This method establishes a connection to the printer using the provided connection string, checks if the printer is in protected mode, and if not, restores the network defaults. If the printer is in protected mode, an exception is thrown indicating that a password is required. The printer connection is closed after the operation.
- Parameters:
connectionString- the connection string used to connect to the printer (e.g., USB, Bluetooth, TCP/IP)- Throws:
ConnectionException- if there is an error establishing or closing the connection to the printerZebraPrinterLanguageUnknownException- if the printer language cannot be determinedNotALinkOsPrinterException- if the connected printer is not a Link-OS printerZebraIllegalArgumentException- if the printer is in protected mode and a password is required
-
restoreAsmDefaults
public static void restoreAsmDefaults(String connectionString, String authPassword, String sgdBranch) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, ZebraIllegalArgumentException For printers in Protected Mode: Restores the specified SGD branch(ip,wlan or power etc) configuration settings of a Zebra Link-OS printer in protected mode to their default values.It uses the provided authentication password to authenticate protected printer.
- Parameters:
connectionString- the connection string used to connect to the printerauthPassword- the authentication password required if the printer is in protected modesgdBranch- SGD branch name(wlan,ip,display,power,bluetooth,device.alerts and all)- Throws:
ConnectionException- if there is an error connecting to the printerZebraPrinterLanguageUnknownException- if the printer language cannot be determinedNotALinkOsPrinterException- if the connected printer is not a Link-OS printerZebraIllegalArgumentException- if an invalid argument is provided
-
printConfigLabel
public static void printConfigLabel(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Prints the configuration label on a printer using the specified connection string.This method establishes a connection to a Link-OS Zebra printer, sends a command to print the configuration label, and then closes the connection. It ensures that the connection is properly closed even if an exception occurs during the printing process.
- Parameters:
connectionString- the connection string used to connect to the Zebra printer- Throws:
ConnectionException- if there is an error establishing or closing the connectionZebraPrinterLanguageUnknownException- if the printer language cannot be determinedNotALinkOsPrinterException- if the connected printer is not a Link-OS printer
-
printNetworkConfigLabel
public static void printNetworkConfigLabel(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Causes the specified printer to print a network configuration label.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
printDirectoryLabel
public static void printDirectoryLabel(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException Causes the specified printer to print a directory listing of all the files saved on the printer.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.- Throws:
ConnectionException- if there is an error connecting to the device.ZebraPrinterLanguageUnknownException- if the printer language could not be determined.NotALinkOsPrinterException- This feature is only available on Link-OS printers.
-
getSettingsFromPrinter
public static Map<String,Setting> getSettingsFromPrinter(String connectionString) throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException, SettingsException Retrieve all settings and their attributes from the specified printer.
See ConnectionBuilder for the format ofconnectionString.- Parameters:
connectionString- The connection string.- Returns:
- A map of setting names versus Setting objects from the printer specified in the connection string.
- Throws:
NotALinkOsPrinterException- This feature is only available on Link-OS printers.ZebraPrinterLanguageUnknownException- if the printer language can not be determined.ConnectionException- if there is an error connecting to the device.SettingsException- if the settings could not be retrieved.
-
getCurrentStatus
public static PrinterStatus getCurrentStatus(Connection printerConnection, PrinterLanguage language) throws ConnectionException Returns a new instance ofPrinterStatusthat can be used to determine the status of a printer. Each invocation of this method will result in a query of the connected printer. If more than one status value is to be read, it is recommended that a copy ofPrinterStatusis stored locally.
Note: This method must be invoked again to retrieve the most up-to-date status of the printer. ThePrinterStatusobject will only query the printer upon creation.
Note: Some Mobile printers (including the MZ series printers) will not communicate if the printer is not ready to print. On these printers, status information is not available when, for example, the printer is out of paper. This method will throw aConnectionExceptionif it is called when the printer cannot communicate.- Parameters:
printerConnection- Connection to the printer.language- Printer control language to be used.- Returns:
- a new instance of
PrinterStatus. - Throws:
ConnectionException- if there is an issue communicating with the printer (e.g. the connection is not open.)- See Also:
-
validExtensionForPrinterProtected
- Parameters:
filePath-- Returns:
- boolean
-
validSGDBranchName
- Parameters:
sgdBranchName-- Returns:
- boolean
-
isPrintingChannelInLineMode
public static boolean isPrintingChannelInLineMode(Connection connection, PrinterLanguage printerLanguage) Checking line-print mode- Parameters:
connection-printerLanguage-- Returns:
- boolean
-