A library for interfacing with Brother Mobile printers.
$ dotnet add package com.brother.bms.iOSBindingLibraryThis is a library that takes the Brother SDK for iOS and binds it in a library that users of .NET MAUI can consume
When you download the nuget package, the package will be imported to both iOS and Android.
<Project Sdk="Microsoft.NET.Sdk">
...
...
<!-- Other Nuget packages -->
<PackageReference Include="com.brother.bms.iOSBindingLibrary" Version="1.0.xxxx" />
<!-- Other Nuget packages -->
...
...
</Project>
Move this PackageReference into a target specific tag.
<Project Sdk="Microsoft.NET.Sdk">
...
<!-- Other Nugetpackages -->
...
<ItemGroup Condition="'$(TargetFramework)'=='netX.0-ios'">
<PackageReference Include="com.brother.bms.iOSBindingLibrary" Version="1.0.xxxx" />
</ItemGroup>
...
...
</Project>
<key>UISupportedExternalAccessoryProtocols</key>
<array>
<string>Com.Brother.ptcbp</string>
</array>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to use Bluetooth</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to use Bluetooth</string>
<key>NSBonjourServices</key>
<array>
<string>_ipp._tcp</string>
<string>_printer._tcp</string>
<string>_pdl-datastream._tcp</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>This app requires access to the local network to discover and communicate with network devices.</string>
In your android code, import the library com.brother.sdk.lmprinter
public class iOSPrintingClass
{
public iOSPrintingClass()
{
string PrintResult = string.Empty;
string PDFPath = "path/to/your/pdf/file.pdf"; // Replace with your actual PDF file path
BRLMChannel channel = SetupChannel("serialNumber"); // Replace with your printers actual serial number
BRLMRJPrintSettings rjPrintSettings = new(BRLMPrinterModel.Rj4230b)
{
CustomPaperSize = CreateCustomPaper(UtilityMethods.GetMediaSize(50)),
ScaleMode = BRLMPrintSettingsScaleMode.FitPageAspect,
Halftone = BRLMPrintSettingsHalftone.ErrorDiffusion,
HAlignment = BRLMPrintSettingsHorizontalAlignment.Center,
VAlignment = BRLMPrintSettingsVerticalAlignment.Center,
ImageRotation = BRLMPrintSettingsRotation.BRLMPrintSettingsRotationRotate0,
HalftoneThreshold = 128,
NumCopies = 1,
SkipStatusCheck = false
};
IBRLMPrintSettingsProtocol? validPrintSettings = ValidateSettings(rjPrintSettings);
if (validPrintSettings is null)
{ /* Handle the case where print settings are invalid */ }
else
PrintResult = await PrintMethod(channel, validPrintSettings, PDFPath); //NOTE: THIS SHOULD BE CALLED IN AN ASYNC METHOD
//Do something with PrintResult
}
private static IBRLMPrintSettingsProtocol? ValidateSettings(IBRLMPrintSettingsProtocol printSettings)
{
BRLMValidatePrintSettingsReport validateReport = BRLMValidatePrintSettings.Validate(printSettings);
if (validateReport.ErrorCount == 0)
return printSettings;
else return null;
}
public static async Task<string> PrintMethod(BRLMChannel channel, IBRLMPrintSettingsProtocol printSettings, string thingToPrint)
{
BRLMPrinterDriverGenerateResult driverResult = BRLMPrinterDriverGenerator.OpenChannel(channel);
BRLMOpenChannelErrorCode driverError = driverResult.Error.Code;
if (driverError != BRLMOpenChannelErrorCode.NoError)
{
string errorMessage = $"Error opening channel : {driverError}";
return errorMessage;
}
BRLMPrinterDriver? printerDriver = driverResult.Driver;
if (printerDriver == null)
{
string errorMessage = "Printer driver is null.";
return errorMessage;
}
string result = await Task.Run(() =>
{
BRLMPrinterDriver? printerDriver = null;
try
{
BRLMPrinterDriverGenerateResult driverResult = BRLMPrinterDriverGenerator.OpenChannel(channel);
BRLMOpenChannelErrorCode driverError = driverResult.Error.Code;
if (driverError != BRLMOpenChannelErrorCode.NoError)
return driverError.ToString();
printerDriver = driverResult.Driver;
if (printerDriver == null)
return PRINTER_DRIVER_NULL;
var url = new NSUrl(thingToPrint);
if (url == null || url.AbsoluteString == string.Empty)
return "Invalid PDF file path";
BRLMPrintError printResult = printerDriver.PrintPDFWithURL(url, printSettings);
Debug.WriteLine($"PDFPrint Result: {printResult.ErrorDescription}");
return $"{printResult.Code}\n{printResult.ErrorDescription}";
}
catch (Exception ex)
{
return $"SDK Exception (inner): {ex}";
}
finally
{
printerDriver?.CloseChannel();
}
});
return result;
}
public static BRLMChannel SetupChannel(string serialNumber)
{
var channel = new BRLMChannel();
channel.initWithBluetoothSerialNumber(serialNumber);
return channel;
}
}
https://support.brother.com/g/s/es/htmldoc/mobilesdk/index.html
https://brothermobilesolutions.com/
E-mail us: bmsdevsupport@brother.com
This library binding is completed against SDK version 4.13.0