使用 AirPrint 打印 PDF 会导致输出较小

2024-03-06

我尝试打印 pdfUIPrintInteractionController它加载在UIWevView。好消息是我可以打印,坏消息是打印输出太小。

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

输出:


除了 @crescendolls 响应之外,这里还有一段完整的代码,用于将 Web 视图中的 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
    }];
} 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 AirPrint 打印 PDF 会导致输出较小 的相关文章

  • 使用 nib 作为带有 nib 类的表节标题

    我想创建一个加载 nib 文件并将其设置为标题 UIView 的节标题 这个 nib 文件还将有一个关联的类 其中插座和操作连接到 因此我想像平常一样使用 nib 加载该类 我在网上搜索并找到了几个类似的答案 但我找不到任何适合我的答案 经
  • iOS 13 检查 CLLocationManager 的临时授权状态

    根据 WWDC 视频 https developer apple com videos play wwdc2019 705 https developer apple com videos play wwdc2019 705 当你要求 Al
  • 如何在 iOS 中将 Firebase 对象持久保存到磁盘?

    看起来Firebase http www firebase comiOS 实现不支持客户端模型的离线缓存 这在实践中意味着 对于需要身份验证的 Firebase 应用程序 您需要首先进行身份验证并等待 Firebase 完成登录 检查用户身
  • 在回调函数中调用目标c函数

    如何在回调函数中调用目标c函数 回调函数 static OSStatus inputRenderCallback void inRefCon AudioUnitRenderActionFlags ioActionFlags const Au
  • iPhone SQLite页面缓存不断增长

    I use sqlite数据库用于存储 还有许多数据库事务 我的问题是 sqlite 页面缓存的内存使用量快速增长 在instruments我可以找到这条线 Graph Category Live Bytes Living Transien
  • 使用特定的 url 启动 UIWebview

    我目前有一个包含四个按钮的视图 并且希望能够启动 UIWebview 并为每个不同的按钮提供特定的 url 我目前可以使用 url 从外部启动 safari 我知道我可以使用代码在每个按钮中显示 UIWebview 并且可以在 UIWebv
  • 如何区分 iTunes Connect / Apple TestFlight 上的 STAGE 和 PRODUCTION 版本?

    阶段构建与阶段服务器的对话 阶段服务器与生产服务器尽可能相同 以用于测试目的 生产构建与生产服务器的通信 生产服务器存储真实的关键数据 这些构建本质上是针对同一应用程序的 但是 iTunes Connect 界面将向您显示以下内容 即构建由
  • SceneKit unproject Z 文档解释?

    我正在经历一些 SceneKit 概念 而我试图在脑海中巩固的一个概念是 unprojectPoint 我知道该函数将获取 2D 中的一个点并返回 3D 中的一个点 因此具有正确的 Z 值 当我阅读文档时 我读到了以下内容 method u
  • 为具有多个目标和不同平台的项目编写 Podfile

    我正在准备一个支持 OS X 和 iOS 的 Pod 我的 pod 有一些自己的依赖项 这些依赖项在 podspec 文件中定义 因此我使用 Podfile 来管理我用来开发 pod 和运行测试的项目的依赖项 我正在使用 CocoaPods
  • 如何使用 Swift 将“完成”按钮添加到 iOS 中的数字键盘?

    它在默认键盘上工作得很好 但我无法让它在数字键盘上工作 有任何想法吗 据我所知 你不能在键盘部分添加 完成 按钮 你应该添加一个inputAccessoryView to the UITextField or UITextView 如果这就
  • 在情节提要中将 Segue 拖至自身

    我想将一个 Segue 从我的视图控制器拖到其自身 所以我可以推送该特定视图控制器的 无限 实例 我知道如何在代码中执行此操作 即以编程方式实例化视图控制器 但是 我想尽可能使用 segues 我发现了一些在故事板中进行自我延续的 技巧 但
  • TTTAttributedLabel 可点击截断标记

    我有一个 TTTAttributedLabel 并为其指定了一个自定义属性截断标记 NSAttributedString atributedTruncationToken NSAttributedString alloc initWithS
  • 使用 BGTaskScheduler 进行后台获取与调试模拟完美配合,但在实践中却不起作用

    我在 appDelegate 的 didFinishLaunchingWithOptions 中注册后台获取任务 BGTaskScheduler shared register forTaskWithIdentifier Backgroun
  • removeItemAtPath 完成

    我正在以这种方式删除路径上的文件 UIPanGestureRecognizer gesture UIPanGestureRecognizer sender UIButton button UIButton gesture view UIPa
  • iOS Swift 和 reloadRowsAtIndexPaths 编译错误

    我与 xCode Swift 陷入僵局并刷新 UITableView 的单行 这条线有效 self tableView reloadData 而这条线没有 self tableView reloadRowsAtIndexPaths curr
  • 在 UITableView 的部分标题文本下方添加一些边距

    我已经设计了标题文本的样式 func tableView tableView UITableView cellForRowAtIndexPath indexPath NSIndexPath gt UITableViewCell let ce
  • UILabel UILongPressGestureRecognizer 不起作用?

    我怎样才能得到UILongPressGestureRecognizer在 uilabel 当我实现以下代码时 它不会调用该函数 那么请告诉我我做错了什么 UILongPressGestureRecognizer longPress UILo
  • 动画 UICollectionView 单元格大小更改并重新定位周围单元格

    Goal 以动画方式改变单元格的高度并重新定位周围的单元格 设想 集合视图中的某些单元格会加载远程图像 最初 这些单元格的大小是静态的 并显示活动指示器 加载图像后 会将其添加到其单元格中 并且更改单元格的高度以适合照片 Notes 我正在
  • 如何观察UserDefaults的变化?

    我有一个 ObservedObject在我看来 struct HomeView View ObservedObject var station Station var body some View Text self station sta
  • 对象指针值作为字典的键

    我想使用对象的引用值作为字典的键 而不是对象值的副本 因此 我本质上想在字典中存储与另一个对象的特定实例关联的对象 并稍后检索该值 这可能吗 是不是完全违背了NSDictionary的理念 我可以看出我可能以错误的方式处理这个问题 因为字典

随机推荐