gpt4 book ai didi

ios - 使用 AirPrint 打印 Pdf 会导致输出较小

转载 作者:可可西里 更新时间:2023-11-01 05:35:19 36 4
gpt4 key购买 nike

我尝试使用加载到 UIWevView 中的 UIPrintInteractionController 打印 pdf。好消息是我可以打印,坏消息是打印的输出太小。

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];
}

输出:

enter image description here

最佳答案

根据@crescendolls 的回复,这里有一段完整的代码,用于将 webview 中的 PDF 转换为数据,并相应地进行打印。

-(void)printReport {
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = webView.request.URL.absoluteString;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;

UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;

//does not display PDF appropriately
//pic.printFormatter = webView.viewPrintFormatter;

//does display PDF appropriately
NSCachedURLResponse* webResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:[webView request]];
NSData* webData = [webResponse data];
pic.printingItem = webData;

[pic presentFromBarButtonItem:self.printBarButton animated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
// indicate done or error
}];
}

关于ios - 使用 AirPrint 打印 Pdf 会导致输出较小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23155580/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com