如何将NsView / UiView打印到蓝牙收据打印机?

时间:2016-02-10 09:57:50

标签: ios objective-c uiview printing core-bluetooth

我已成功将文本打印到作为外设的蓝牙收据打印机。以下是代码:

[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属性一样:

  1. endstream
  2. endobj
  3. 5 0 obj
  4. 119
  5. endobj ....等等。
  6. 我怎么可能这样做? 谢谢你......

0 个答案:

没有答案