使用AirPrint打印Pdf会导致输出很小 [英] Printing Pdf using AirPrint causes small output

查看:277
本文介绍了使用AirPrint打印Pdf会导致输出很小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 UIPrintInteractionController 打印一个pdf,它在 UIWevView 中加载。好消息是,我可以打印坏的是打印输出很小。

I trying to print a pdf with UIPrintInteractionController that it load in the UIWevView. The good news is that i can print the bad is that the output of the print is to small.

any help would be appreciated :)


- (IBACTION) printPDF {


    if ((!_webView)) return;
    UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        if(!completed && error){
            NSLog(@"FAILED! due to error in domain %@ with error code %ld",
                  error.domain, (long)error.code);
        }
    };
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.duplex = UIPrintInfoDuplexLongEdge;
    controller.printInfo = printInfo;
    controller.showsPageRange = YES;
    _webView.scalesPageToFit = NO;
    UIViewPrintFormatter *viewFormatter = [_webView viewPrintFormatter];
    viewFormatter.startPage = 0;
     controller.printFormatter = viewFormatter;



    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        /*        [controller presentFromBarButtonItem:printButton animated:YES completionHandler:completionHandler]; */
    }else
        [controller presentAnimated:YES completionHandler:completionHandler];
}

输出:

推荐答案

如果找到解决方案避免打印表单 IUWebView 。我直接 NSData 格式下载 PDF

If found the solution by avoid printing form IUWebView . I directly download the PDF in NSData format.

_data represente我通过请求下载的NSData。

 if (_data) {
    UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];

    printController.delegate = self;

    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    //printInfo.jobName = [path lastPathComponent];
    printInfo.duplex = UIPrintInfoDuplexLongEdge;
    printController.printInfo = printInfo;
    printController.showsPageRange = YES;
    printController.printingItem = _data;

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        if (!completed && error) {
            NSLog(@"FAILED! due to error in domain %@ with error code %lu", error.domain, (long)error.code);
        }
    };

    [printController presentAnimated:YES completionHandler:completionHandler];
}

这篇关于使用AirPrint打印Pdf会导致输出很小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆