Skip to content

画像や PDF を印刷する

画像及び PDF ファイル印刷機能を以下の API で提供します。

ファイル種類 iOS Android
1枚の画像 printImageWithURL:settings: printImage(final String path, final PrintSettings printSettings)
複数の画像 printImageWithURLs:settings: printImage(final String[] paths, final PrintSettings printSettings);
PDF ファイル printPDFWithURL:settings: printPDF(final String path, final PrintSettings printSettings);

サンプルコード

PT/QL シリーズ

PT/QL シリーズから印刷するためには用紙サイズ名を設定する必要があります。

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 シリーズ

RJ/TD シリーズから印刷するためには用紙サイズを設定する必要があります。用紙サイズ指定方法は以下の2通りがあります。

用紙サイズをコードで指定する

この方法には以下のプリンターが対応しています。

  • RJ-4230B/4250WB/RJ-3230B/RJ-3250WB
  • TD-4410D/4510D/4420DN/4520DN/4550DNWB

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();
}

用紙情報ファイルを指定する

用紙情報ファイル(拡張子 .bin)を作成し、印刷時に指定します。 詳しくは カスタム用紙サイズで印刷できるように設定する を参照してください。

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 シリーズ

PJ/MW シリーズから印刷するためには標準規格用紙サイズを指定する必要があります。

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();
}