如何使用UIPrintInteractionController for Airprint摆脱页边距

时间:2016-12-20 07:30:12

标签: objective-c margin airprint uiprintformatter

我正在尝试使用UIPrintInteractionController AirPrint一个UIImage 此代码可以成功运行,除了在打印预览中添加了一个边距,这对我来说是不可取的。如何自定义左,右,顶部和底部边距为零或其他值?我知道printablerect但如何修改它?在此先感谢您的帮助:)

 UIPrintInteractionController *pic = [UIPrintInteractionController    sharedPrintController];
 NSData *imageData=UIImageJPEGRepresentation(imageforPrint, 1.0);
 if (pic && [UIPrintInteractionController canPrintData: imageData] ) {
     pic.delegate = self;

     UIPrintInfo *printInfo = [UIPrintInfo printInfo];
     printInfo.outputType = UIPrintInfoOutputGeneral;
     printInfo.jobName = @"Job 1";
     printInfo.duplex = UIPrintInfoDuplexLongEdge;
     pic.printInfo = printInfo;

     UIPrintPageRenderer *renderer = [[UIPrintPageRenderer alloc] init];

     UIPrintFormatter *Formatter = [[UIPrintFormatter alloc] init];
     Formatter=pic.printFormatter;
     Formatter.startPage=0;
     Formatter.perPageContentInsets = UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);

     Formatter.startPage=0;

     [renderer Formatter startingAtPageAtIndex: 0];

     pic.showsPaperSelectionForLoadedPapers=YES;
     pic.printPageRenderer=renderer;

     pic.printFormatter=Formatter;
     pic.printingItem = imageData;
     pic.showsPageRange = YES;

     void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
                                ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
           //self.content = nil;
           if (!completed && error)
               NSLog(@"FAILED! due to error in domain %@ with error code %ld", error.domain, (long)error.code);

     };

     [pic presentAnimated:YES completionHandler:completionHandler];

0 个答案:

没有答案