Skip to content

Printing Image/PDF

Brother Print SDK supports printing image(s) and PDF(s) for Android/iOS devices. This page shows you sample codes to print an image file for each series.

To print PDF, you use printPDFWithURL:settings: instead of printImageWithURL:settings:.

Sample Codes

Series-independent APIs used in the sample codes on this page.

iOS Android
BRLMChannel Channel
BRLMPrinterDriverGenerator PrinterDriverGenerator
BRLMPrinterDriver PrinterDriver
printImageWithURL:(NSURL *)url settings:(id)settings; printImage(final String path, final PrintSettings printSettings)

PT/QL Series

The print settings APIs for PT/QL series.

Series iOS Android
PT BRLMPTPrintSettings PTPrintSettings
QL BRLMQLPrintSettings QLPrintSettings

To print from the PT/QL series, you need to set the paper size in the print settings. For information on paper size, see the following link.

Series iOS Android
PT BRLMPTPrintSettingsLabelSize PTPrintSettings LbelSize
QL BRLMQLPrintSettingsLabelSize PTPrintSettings LbelSize

iOS - Objective-C:

- (void)printImage {
    BRLMChannel *channel = [[BRLMChannel alloc] initWithWifiIPAddress:@"IPAddress.of.your.printer"];

    BRLMPrinterDriverGenerateResult *driverGenerateResult = [BRLMPrinterDriverGenerator openChannel:channel];
    if (driverGenerateResult.error.code != BRLMOpenChannelErrorCodeNoError ||
        driverGenerateResult.driver == nil) {
        NSLog(@"%@", @(driverGenerateResult.error.code));
        return;
    }

    BRLMPrinterDriver *printerDriver = driverGenerateResult.driver;

    BRLMQLPrintSettings *qlSettings = [[BRLMQLPrintSettings alloc] initDefaultPrintSettingsWithPrinterModel:BRLMPrinterModelQL_YOURS];
    qlSettings.labelSize = BRLMPrintSettingsLabelSizeYours;

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"YourImageFilename" withExtension:@"Extension"];

    BRLMPrintError *printError = [printerDriver printImageWithURL:url settings:qlSettings];

    if (printError.code != BRLMPrintErrorCodeNoError) {
        NSLog(@"Error - Print Image: %@", @(printError.code));
    }
    else {
        NSLog(@"Success - Print Image");
    }

    [printerDriver closeChannel];
}

iOS - Swift:

func printImage() {
    let channel = BRLMChannel(wifiIPAddress: "IPAddress.of.your.printer")

    let generateResult = BRLMPrinterDriverGenerator.open(channel)
    guard generateResult.error.code == BRLMOpenChannelErrorCode.noError,
        let printerDriver = generateResult.driver else {
            print("Error - Open Channel: \(generateResult.error.code)")
            return
    }
    defer {
        printerDriver.closeChannel()
    }

    guard
        let url = Bundle.main.url(forResource: "YourImageFilename", withExtension: "Extension"),
        let printSettings = BRLMQLPrintSettings(defaultPrintSettingsWith: .YourQLModel)
        else {
            print("Error - Image file is not found.")
            return
    }

    printSettings.labelSize = .YourLabelSize
    printSettings.autoCut = true

    let printError = printerDriver.printImage(with: url, settings: printSettings)

    if printError.code != .noError {
        print("Error - Print Image: \(printError.code)")
    }
    else {
        print("Success - Print Image")
    }
}

Android:

void printImage() {
    Channel channel = Channel.newWifiChannel("IPAddress.of.your.printer");

    PrinterDriverGenerateResult result = PrinterDriverGenerator.openChannel(channel);
    if (result.getError().getCode() != OpenChannelError.ErrorCode.NoError) {
        Log.e("", "Error - Open Channel: " + result.getError().getCode());
        return;
    }

    File dir = getExternalFilesDir(null);
    File file = new File(dir, "YourImageFilename");

    PrinterDriver printerDriver = result.getDriver();
    QLPrintSettings printSettings = new QLPrintSettings(PrinterModel.YourQLModel);

    printSettings.setLabelSize(QLPrintSettings.LabelSize.YourLabelSize);
    printSettings.setAutoCut(true);
    printSettings.setWorkPath(dir.toString());

    PrintError printError = printerDriver.printImage(file.toString(), printSettings);

    if (printError.getCode() != PrintError.ErrorCode.NoError) {
        Log.d("", "Error - Print Image: " + printError.getCode());
    }
    else {
        Log.d("", "Success - Print Image");
    }

    printerDriver.closeChannel();
}

RJ/TD Series

The print settings APIs for TD/RJ series.

Series iOS Android
TD BRLMTDPrintSettings TDPrintSettings
RJ BRLMRJPrintSettings RJPrintSettings

To print from the RJ/TD series, you need to set the custom paper information in the print settings. For information on custom paper , see the following link.

Series iOS Android
RJ/TD BRLMCustomPaperSize CustomPaperSize

By the one of following methods, you can specify custom paper information.

Specify Paper Information One by One

iOS - Objective-C:

- (void)printImage {
    BRLMChannel *channel = [[BRLMChannel alloc] initWithWifiIPAddress:@"IPAddress.of.your.printer"];

    BRLMPrinterDriverGenerateResult *driverGenerateResult = [BRLMPrinterDriverGenerator openChannel:channel];
    if (driverGenerateResult.error.code != BRLMOpenChannelErrorCodeNoError ||
        driverGenerateResult.driver == nil) {
        NSLog(@"%@", @(driverGenerateResult.error.code));
        return;
    }

    BRLMPrinterDriver *printerDriver = driverGenerateResult.driver;

    BRLMTDPrintSettings *tdSettings = [[BRLMTDPrintSettings alloc] initDefaultPrintSettingsWithPrinterModel:BRLMPrinterModelTD_YOURS];

    BRLMCustomPaperSizeMargins margin = BRLMCustomPaperSizeMarginsMake(0.0, 0.0, 0.0, 0.0);
    BRLMCustomPaperSize *customPaperSize = [[BRLMCustomPaperSize alloc] initRollWithTapeWidth:2.0
                                                                                      margins:margin
                                                                                 unitOfLength:BRLMCustomPaperSizeLengthUnitInch];

    if (customPaperSize != nil) {
        tdSettings.customPaperSize = customPaperSize;
    }

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"YourImageFilename" withExtension:@"Extension"];

    BRLMPrintError *printError = [printerDriver printImageWithURL:url settings:tdSettings];

    if (printError.code != BRLMPrintErrorCodeNoError) {
        NSLog(@"Error - Print Image: %@", @(printError.code));
    }
    else {
        NSLog(@"Success - Print Image");
    }

    [printerDriver closeChannel];
}

iOS - Swift:

func printImage() {
    let channel = BRLMChannel(wifiIPAddress: "IPAddress.of.your.printer")

    let generateResult = BRLMPrinterDriverGenerator.open(channel)
    guard generateResult.error.code == BRLMOpenChannelErrorCode.noError,
        let printerDriver = generateResult.driver else {
            print("Error - Open Channel: \(generateResult.error.code)")
            return
    }
    defer {
        printerDriver.closeChannel()
    }

    guard
        let url = Bundle.main.url(forResource: "YourImageFilename", withExtension: "Extension"),
        let printSettings = BRLMTDPrintSettings(defaultPrintSettingsWith: .YourTDModel)
        else {
            print("Error - Image file is not found.")
            return
    }

    // Set your paper information
    let margins = BRLMCustomPaperSizeMargins(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0)
    let customPaperSize = BRLMCustomPaperSize(rollWithTapeWidth: 2.0,
                                                margins: margins,
                                                unitOfLength: .inch)
    printSettings.customPaperSize = customPaperSize

    let printError = printerDriver.printImage(with: url, settings: printSettings)

    if printError.code != .noError {
        print("Error - Print Image: \(printError.code)")
    }
    else {
        print("Success - Print Image")
    }
}

Android:

void printImage() {
    Channel channel = Channel.newWifiChannel("IPAddress.of.your.printer");

    PrinterDriverGenerateResult result = PrinterDriverGenerator.openChannel(channel);
    if (result.getError().getCode() != OpenChannelError.ErrorCode.NoError) {
        Log.e("", "Error - Open Channel: " + result.getError().getCode());
        return;
    }

    File dir = getExternalFilesDir(null).toString();
    File file = new File(dir, "YourImageFilename");

    PrinterDriver printerDriver = result.getDriver();
    TDPrintSettings printSettings = new TDPrintSettings(PrinterModel.YourTDModel);

    CustomPaperSize.Margins margins = new CustomPaperSize.Margins(0.0f, 0.0f, 0.0f, 0.0f);
    CustomPaperSize customPaperSize = CustomPaperSize.newRollPaperSize(4.0, margins, CustomPaperSize.Unit.Inch);

    printSettings.setCustomPaperSize(customPaperSize);

    PrintError printError = printerDriver.printImage(file.toString(), printSettings);

    if (printError.getCode() != PrintError.ErrorCode.NoError) {
        Log.d("", "Error - Print Image: " + printError.getCode());
    }
    else {
        Log.d("", "Success - Print Image");
    }

    printerDriver.closeChannel();
}

Use Paper Infomartion File

Custom paper information can be exported as .bin file from the Paper Size Setup Tool. As the below sample code show, SDK can use this file. This .bin file cannot be used for other models, so you have to prepare this file for each printer. About Paper Size Setup Tool, see Configuring Your Printer for Printing on Custom-Size Paper.

iOS - Objective-C:

- (void)printImage {
    BRLMChannel *channel = [[BRLMChannel alloc] initWithWifiIPAddress:@"IPAddress.of.your.printer"];

    BRLMPrinterDriverGenerateResult *driverGenerateResult = [BRLMPrinterDriverGenerator openChannel:channel];
    if (driverGenerateResult.error.code != BRLMOpenChannelErrorCodeNoError ||
        driverGenerateResult.driver == nil) {
        NSLog(@"%@", @(driverGenerateResult.error.code));
        return;
    }

    BRLMPrinterDriver *printerDriver = driverGenerateResult.driver;

    BRLMTDPrintSettings *tdSettings = [[BRLMTDPrintSettings alloc] initDefaultPrintSettingsWithPrinterModel:BRLMPrinterModelTD_YOURS];

    NSURL *customPaperFileUrl = [[NSBundle mainBundle] URLForResource:@"YourCustomPaperFile" withExtension:@"bin"];
    if (customPaperFileUrl != nil) {
        BRLMCustomPaperSize *customPaperSize = [[BRLMCustomPaperSize alloc] initWithFile:customPaperFileUrl];
        tdSettings.customPaperSize = customPaperSize;
    }

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"YourImageFilename" withExtension:@"Extension"];

    BRLMPrintError *printError = [printerDriver printImageWithURL:url settings:tdSettings];

    if (printError.code != BRLMPrintErrorCodeNoError) {
        NSLog(@"Error - Print Image: %@", @(printError.code));
    }
    else {
        NSLog(@"Success - Print Image");
    }

    [printerDriver closeChannel];
}

iOS - Swift:

func printImage() {
    let channel = BRLMChannel(wifiIPAddress: "IPAddress.of.your.printer")

    let generateResult = BRLMPrinterDriverGenerator.open(channel)
    guard generateResult.error.code == BRLMOpenChannelErrorCode.noError,
        let printerDriver = generateResult.driver else {
            print("Error - Open Channel: \(generateResult.error.code)")
            return
    }
    defer {
        printerDriver.closeChannel()
    }

    guard
        let url = Bundle.main.url(forResource: "YourImageFilename", withExtension: "Extension"),
        let printSettings = BRLMTDPrintSettings(defaultPrintSettingsWith: .YourTDModel)
        else {
            print("Error - Image file is not found.")
            return
    }

    if let customPaperFileUrl = Bundle.main.url(forResource: "YourCustomPaperFile", withExtension: "bin") {
        let customPaperSize = BRLMCustomPaperSize(file: customPaperFileUrl)
        printSettings.customPaperSize = customPaperSize
    }

    let printError = printerDriver.printImage(with: url, settings: printSettings)

    if printError.code != .noError {
        print("Error - Print Image: \(printError.code)")
    }
    else {
        print("Success - Print Image")
    }
}

Android:

void printImage() {
    Channel channel = Channel.newWifiChannel("IPAddress.of.your.printer");

    PrinterDriverGenerateResult result = PrinterDriverGenerator.openChannel(channel);
    if (result.getError().getCode() != OpenChannelError.ErrorCode.NoError) {
        Log.e("", "Error - Open Channel: " + result.getError().getCode());
        return;
    }

    File dir = getExternalFilesDir(null).toString();
    File file = new File(dir, "YourImageFilename");

    PrinterDriver printerDriver = result.getDriver();
    TDPrintSettings printSettings = new TDPrintSettings(PrinterModel.YourTDModel);

    File customPaperSizeFile = new File(dir, "YourCustomPaperFile");

    CustomPaperSize customPaperSize = CustomPaperSize.newFile(customPaperSizeFile.toString());
    printSettings.setCustomPaperSize(customPaperSize);

    PrintError printError = printerDriver.printImage(file.toString(), printSettings);

    if (printError.getCode() != PrintError.ErrorCode.NoError) {
        Log.d("", "Error - Print Image: " + printError.getCode());
    }
    else {
        Log.d("", "Success - Print Image");
    }

    printerDriver.closeChannel();
}

PJ/MW Series

The print settings APIs for PJ/MW series.

Series iOS Android
PJ BRLMPJPrintSettings PJPrintSettings
MW BRLMMWPrintSettings MWPrintSettings

To print from the PJ/MW series, you need to set the paper size in the print settings. For information on paper size, see the following link.

Series iOS Android
PJ BRLMPJPrintSettingsPaperSizeStandard PJPaperSize PaperSize
BRLMPJPrintSettingsCustomPaperSize PJCustomPaperSize
MW BRLMMWPrintSettingsPaperSize MWPrintSettings PaperSize

iOS - Objective-C:

- (void)printImage {
    BRLMChannel *channel = [[BRLMChannel alloc] initWithWifiIPAddress:@"IPAddress.of.your.printer"];

    BRLMPrinterDriverGenerateResult *driverGenerateResult = [BRLMPrinterDriverGenerator openChannel:channel];
    if (driverGenerateResult.error.code != BRLMOpenChannelErrorCodeNoError ||
        driverGenerateResult.driver == nil) {
        NSLog(@"%@", @(driverGenerateResult.error.code));
        return;
    }

    BRLMPrinterDriver *printerDriver = driverGenerateResult.driver;

    BRLMPJPrintSettings *pjSettings = [[BRLMPJPrintSettings alloc] initDefaultPrintSettingsWithPrinterModel:BRLMPrinterModelPJ_YOURS];
    pjSettings.paperSize = [[BRLMPJPrintSettingsPaperSize alloc] initWithPaperSizeStandard: BRLMPJPrintSettingsPaperSizeStandardLetter];

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"YourImageFilename" withExtension:@"Extension"];

    BRLMPrintError *printError = [printerDriver printImageWithURL:url settings:pjSettings];

    if (printError.code != BRLMPrintErrorCodeNoError) {
        NSLog(@"Error - Print Image: %@", @(printError.code));
    }
    else {
        NSLog(@"Success - Print Image");
    }

    [printerDriver closeChannel];
}

iOS - Swift:

func printImage() {
    let channel = BRLMChannel(wifiIPAddress: "IPAddress.of.your.printer")

    let generateResult = BRLMPrinterDriverGenerator.open(channel)
    guard generateResult.error.code == BRLMOpenChannelErrorCode.noError,
        let printerDriver = generateResult.driver else {
            print("Error - Open Channel: \(generateResult.error.code)")
            return
    }
    defer {
        printerDriver.closeChannel()
    }

    guard
        let url = Bundle.main.url(forResource: "YourImageFilename", withExtension: "Extension"),
        let printSettings = BRLMPJPrintSettings(defaultPrintSettingsWith: .YourPJModel)
        else {
            print("Error - Image file is not found.")
            return
    }

    let pjPaperSize = BRLMPJPrintSettingsPaperSize(paperSizeStandard: .pjStandardSizeLetter)
    printSettings.paperSize = pjPaperSize

    let printError = printerDriver.printImage(with: url, settings: printSettings)

    if printError.code != .noError {
        print("Error - Print Image: \(printError.code)")
    }
    else {
        print("Success - Print Image")
    }
}

Android:

void printImage() {
    Channel channel = Channel.newWifiChannel("IPAddress.of.your.printer");

    PrinterDriverGenerateResult result = PrinterDriverGenerator.openChannel(channel);
    if (result.getError().getCode() != OpenChannelError.ErrorCode.NoError) {
        Log.e("", "Error - Open Channel: " + result.getError().getCode());
        return;
    }

    File dir = getExternalFilesDir(null);
    File file = new File(dir, "YourImageFilename");

    PrinterDriver printerDriver = result.getDriver();
    PJPrintSettings printSettings = new PJPrintSettings(PrinterModel.YourPJModel);

    printSettings.setPaperSize(PJPaperSize.newPaperSize(PJPaperSize.PaperSize.Letter));
    printSettings.setWorkPath(dir.toString());

    PrintError printError = printerDriver.printImage(file.toString(), printSettings);

    if (printError.getCode() != PrintError.ErrorCode.NoError) {
        Log.d("", "Error - Print Image: " + printError.getCode());
    }
    else {
        Log.d("", "Success - Print Image");
    }

    printerDriver.closeChannel();
}