0

我正在开发一个可以打印创建的 PDF 的应用程序。PDF 是 11 x 8.5,所以我需要它来打印横向模式,但是我在正确设置该方向时遇到了问题。这是我的印刷品。

- (void)printit {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:selectedCountry];
    NSData *pdfData = [NSData dataWithContentsOfFile:pdfPath];

    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    if  (pic && [UIPrintInteractionController canPrintData:pdfData] ) {
        pic.delegate = self;
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = selectedCountry;
        printInfo.duplex = UIPrintInfoDuplexNone;
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
        pic.printingItem = pdfData;
               void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
        ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
                       if (!completed && error)
                NSLog(@"FAILED! due to error in domain %@ with error code %u",
                      error.domain, error.code);
        };
        //if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        //    [pic presentFromBarButtonItem:self.printButton animated:YES
        //                completionHandler:completionHandler];
      //  }
   // else {
            [pic presentAnimated:YES completionHandler:completionHandler];
       // }
    }
}
4

1 回答 1

0

你有没有试过这个:

printInfo.orientation = UIPrintInfoOrientationLandscape;

确保在将 UIPrintInfo 分配给 UIPrintInteractionController 之前添加它——

pic.printInfo = printInfo;

希望这可以为您解决问题。

于 2013-11-22T03:40:47.960 回答