too much lines advance before print

Hi

 

I´m newbie on mobile Develop

 

Could you give me advice about this ? .... Thanks, Regards

 

 

I have one app on iOS (Xcode 7.1) , the app build a PDF file and then this file send via bluetooth to print on iMZ320 printer and works fine https://www.google.com.mx/search?q=bluetooth&spell=1&sa=X&ved=0ahUKEwivsa-ipevLAhWGkIMKHQ4iAOoQvwUIGCgA&biw=2560&bih=1334only I have one issue:

 

When the PDF file is created, I don't see too much lines(spaces) on the beginning or ending (you can see on cedula.png file)

 

So, when the file it's send to the printer, before the printer advanced much lines before print the file(you can see on ticket.jpeg file, how many spaces are between two print)

 

The code when touch the printer icon:

 

- (IBAction)printButton:(id<GraphicsUtil, NSObject>) graphicsUtil {

   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {  

    NSString* fileName = [self getPDFFileName];

    CFURLRef pdfURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:fileName]);

    if (pdfURL != NULL) {

        CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);

        if (pdf == NULL) {

            [self performSelectorOnMainThread:@selector (showErrorDialog:) withObject:@"Could not retrieve PDF document." waitUntilDone:YES];

        } else {

            size_t nPages = CGPDFDocumentGetNumberOfPages(pdf);

            size_t pageNum;

            BOOL success = NO;

            for (pageNum = 1; pageNum <= nPages; pageNum++) {             

                UIImage* image = [self imageFromPDF:pdf page:pageNum];

                if (nil == image) {

                    [self performSelectorOnMainThread:@selector(showErrorDialog:) withObject:@"Could not render PDF document." waitUntilDone:YES];

                    break;

                }

                [self setZebraPrinter];             

                NSError *error = nil;             

                success = [[self.printer getGraphicsUtil] printImage:[image CGImage] atX:0 atY:0 withWidth:-1 withHeight:-1

                                 andIsInsideFormat:NO error:&error];            

                if(success == NO) {

                    [self performSelectorOnMainThread:@selector(showErrorDialog:) withObject:[error localizedDescription] waitUntilDone:YES];

                    break;

                }

            }         

            if (success == YES) {

                NSString *successMessage = @"Image sent to printer";

                [self performSelectorOnMainThread:@selector(showSuccessDialog:) withObject:successMessage waitUntilDone:YES];

            }   

            CGPDFDocumentRelease(pdf);

        }      

        CFRelease(pdfURL);

    }

});   

}

 

 

-(NSString*)getPDFFileName

{

    NSString* fileName = @"Cedula.PDF";   

    NSArray *arrayPaths =

    NSSearchPathForDirectoriesInDomains(

                                        NSDocumentDirectory,

                                        NSUserDomainMask,

                                        YES);

    NSString *path = [arrayPaths objectAtIndex:0];

    NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];

    return pdfFileName;

}

 

 

-(UIImage *)imageFromPDF:(CGPDFDocumentRef)pdf

                    page:(NSUInteger)pageNumber {   

    CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber);   

    CGRect rect = CGPDFPageGetBoxRect(page, kCGPDFArtBox);  

    UIImage *resultingImage = nil;   

    UIGraphicsBeginImageContext(rect.size);   

    CGContextRef context = UIGraphicsGetCurrentContext();   

    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();

    const CGFloat fillColors[] = {1, 1, 1, 1};   

    CGColorRef colorRef = CGColorCreate(rgb, fillColors);

    CGContextSetFillColorWithColor(context, colorRef);

    CGContextFillRect(context, rect);

    CGColorSpaceRelease(rgb);

    CGColorRelease(colorRef);   

    CGContextTranslateCTM(context, 0.0, rect.size.height);  

    CGContextScaleCTM(context, 1.0, -1.0); 

    if (page != NULL) {

        CGContextSaveGState(context);       

        CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, rect, 0, true);     

        CGContextConcatCTM(context, pdfTransform);     

        CGContextDrawPDFPage(context, page);     

        CGContextRestoreGState(context);     

        resultingImage = UIGraphicsGetImageFromCurrentImageContext();

    } 

    UIGraphicsEndImageContext();  

    return resultingImage;

}