是否可以空气打印整页 UIScrollview?

发布于 2024-11-04 08:55:07 字数 1591 浏览 0 评论 0原文

我陷入这个问题很长时间了。正如我所要求的,我可以打印滚动视图,但只能打印其中的一部分,而不是完整尺寸的视图“contentView”。

代码是这样的:

if ([UIPrintInteractionController isPrintingAvailable])
{
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    UIGraphicsBeginImageContext(sv.contentSize);

    [sv.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    NSData *myData = [NSData dataWithData:UIImagePNGRepresentation(viewImage)];
    if(pic && [UIPrintInteractionController canPrintData: myData] ) {

        pic.delegate =(id<UIPrintInteractionControllerDelegate>) self;

        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = [NSString stringWithFormat:@"QFTicket-%@",self.payment.id];
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
        pic.printingItem = myData;
        pic.printFormatter=[sv viewPrintFormatter];

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

        [pic presentAnimated:YES completionHandler:completionHandler];

    }

}

我错过了什么吗?

谢谢

I fall into this problem for a long time. as I asked, I can print the scrollview but only a part of it, not the full size view "contentView".

the code is like this:

if ([UIPrintInteractionController isPrintingAvailable])
{
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    UIGraphicsBeginImageContext(sv.contentSize);

    [sv.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    NSData *myData = [NSData dataWithData:UIImagePNGRepresentation(viewImage)];
    if(pic && [UIPrintInteractionController canPrintData: myData] ) {

        pic.delegate =(id<UIPrintInteractionControllerDelegate>) self;

        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = [NSString stringWithFormat:@"QFTicket-%@",self.payment.id];
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
        pic.printingItem = myData;
        pic.printFormatter=[sv viewPrintFormatter];

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

        [pic presentAnimated:YES completionHandler:completionHandler];

    }

}

Am I missing something?

thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文