我已成功将文本打印到作为外设的蓝牙收据打印机。以下是代码:
[self.discoveredPeripheral writeValue:[@"PONG" dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:ch type:CBCharacteristicWriteWithoutResponse];
之后,我想用格式化的收据打印,我想从我设置格式的NSView/UIView
打印。我按部分发送它,因为如果我发送一次,它会显示错误:"特征的长度无效"。以下是代码(我试着将其除以NSData/ Byte
):
除以NSData
:
CGRect myRect = CGRectMake(0, 0, _myView2.frame.size.width, _myView2.frame.size.height);
NSData *printedData=[_myView2 dataWithPDFInsideRect:myRect];
NSUInteger len = [printedData length];
int slicingSize = 500;
for (int i=0; i < ceil(len/slicingSize); i++) {
int min = i * slicingSize;
int max = (i + 1) * slicingSize;
if(max > len) max = len;
NSData* tmpData = [printedData subdataWithRange:NSMakeRange(min, max )];
[self.discoveredPeripheral writeValue:tmpData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
但是打印的格式就像NsView
属性一样:
我怎么可能这样做? 谢谢你......