Print photo within text on iMZ320 with iOS SDK (Objective C)


Audience

Hello everybody,
 
I did ask this problem in other thread that I asked about print text. But I think it should be move to new thread.
I couldn't print receipt with function
-(BOOL)printReportAsOneJobUsingNSString:(id)printer withString:(NSMutableString*)fullLabel {     /*      Sending large amounts of data in a single write command can overflow the NSStream buffers which are the underlying mechanism used by the SDK to communicate with the printers.      This method shows one way to break up large strings into smaller chunks to send to the printer      */     NSError *error = nil;         long blockSize = 256;     long totalSize = fullLabel.length;     long bytesRemaining = totalSize;         while (bytesRemaining > 0) {         long bytesToSend = MIN(blockSize, bytesRemaining);         NSRange range = NSMakeRange(0, bytesToSend);                 NSString *partialLabel = [fullLabel substringWithRange:range];                 [[printer getToolsUtil] sendCommand:partialLabel error:&error];                 bytesRemaining -= bytesToSend;                 [fullLabel deleteCharactersInRange:range];             }         return (error == nil); }
 
But now I need to attach one photo to receipt link bellow

I did use print image code bellow
if (_printImage) {         id graphicsUtil = [printer getGraphicsUtil];         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{             NSError *error = nil;             [graphicsUtil printImage:[_printImage CGImage] atX:_posX atY:_posYwithWidth:_printImage.size.width withHeight:_printImage.size.height andIsInsideFormat:NOerror:&error];                     });     }

But I didn't know where I can place this code, I did try to put it in printReportAsOneJobUsingNSString function, next to while loop (send text data), but no photo wasn't printed.

Can anybody help me to solve this problem.

Thank you so much !

Submitted by Anonymous (not verified) on May 04, 2019 Permalink

Hi Nguyen,
Is the image a logo or is it dynamic like a signature?  You have different options if you have the ability to convert the file ahead of time as in a logo.  I'm assuming, based on the fact that you are using an iMZ and printing receipts that you are in line mode.  Line-mode is very limited in what it can do so the printImage function is not going to work. 
If it's a static logo, I recommend converting the image to a pcx file format using GIMP or some other image manipulation tool.  You can then, in your app, send this file to be stored to the printer before you print.  You would create your receipt string and add the recall graphic command in where you wan the image printed.  If you named the image file as it's stored in the printer something like IMAGE.PCX, the receipt data would look something like this:

! U1 JOURNAL
! U1 SETLP 4 0 47
                              Some text
! 0 200 200 500 1
PCX 0 0 !