- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我向自定义 QLPreviewController 的 navigationItem 添加了一个操作按钮。当点击操作按钮时,我会呈现一个 UIPrintInteractionController。 我正在从我的应用程序的文档目录中获取文件。预览时没有问题。但是,当我通过点击操作按钮打印同一文件时,[UIPrintInteractionController canPrintData:data] 返回 false。但如果该文件位于我的应用程序根目录内,它就可以工作。
下面是点击操作按钮时执行的代码。
- (void)tappedPrintButton:(id) sender {
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
NSURL *fileURL = (NSURL *)[self currentPreviewItem];
NSData *data = [NSData dataWithContentsOfURL:fileURL];
if (pic && [UIPrintInteractionController canPrintData:data] ) {
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [(NSURL *)[self.files objectAtIndex:0] lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = data;
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.myActionBarButton animated:YES
completionHandler:completionHandler];
} else {
[pic presentAnimated:YES completionHandler:completionHandler];
}
}
}
我无法想象这个问题。请帮忙...
最佳答案
UIPrintInteractionController
的 printingItem
属性是 documented仅支持 PDF 和图像数据:
The object must be an instance of the NSURL, NSData, UIImage, or ALAsset class. An object of the first two types must reference or contain image data or PDF data.
如果您想使用 UIPrintInteractionController
打印非 PDF、非图像数据(例如 Office 文档),则必须使用 printFormatter
属性。
您可以通过打印格式化程序打印 UIWebView
、UITextView
和 MKMapView
内容,无需任何自定义逻辑。这记录在 UIViewPrintFormatter documentation 中:
An instance of the UIViewPrintFormatter class lays out the drawn content of a view for printing. The view’s content can span multiple pages.
Instances of three system classes offer usable view print formatters to applications: UIWebView and UITextView of the UIKit framework, and MKMapView of the Map Kit framework. To obtain a view print formatter for a print job, call the UIView method viewPrintFormatter and initialize the print formatter’s inherited layout properties.
不幸的是,QLPreviewController
的 View 没有记录为返回有效的viewPrintFormatter
。这意味着您将无法使用 QLPreviewController
滚动自己的自定义打印代码。您可以考虑使用 UIWebView
来代替它来呈现文档。
关于airprint - UIPrintInteractionController打印问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10854492/
我向自定义 QLPreviewController 的 navigationItem 添加了一个操作按钮。当点击操作按钮时,我会呈现一个 UIPrintInteractionController。 我
我正在开发一个应用程序,需要能够在用户完成注册过程后打印出名称标签。它需要在不显示使用 UIPrintInteractionController 时自动创建的弹出窗口的情况下执行此操作。 我知道其他应
我正在制作一个应用程序,用户首先选择默认打印机,然后在单击“打印”按钮时继续,照片会自动打印,无需任何对话框。下面是我的代码。我收到错误消息“PrintViewController 没有初始化程序”
在我的应用程序中,可以打印不同尺寸的照片。这工作正常,但对于 iOS 8,即使打印对话框显示例如 5"x7",纸张大小始终为字母/A4。如果用户再次选择纸张尺寸,则纸张尺寸变为例如5"x7". 有没有
我已经在我的应用程序中实现了 AirPrinting,但我遇到了一个奇怪的问题。每当出现打印对话框时,都不会显示取消或完成/打印按钮,如下图所示。 我使用的代码如下: if ([UIPrintInte
我是否必须使用支持 Apple AirPrint 的打印机才能在我的 iPad 应用程序中使用 AirPrint? 我不能在 Mac 上设置共享 Bonjour 打印服务并连接到它吗? 最佳答案 您必
我想将 AirPrint 功能添加到我的 iPad 应用程序 我一直在尝试显示 Apple 的 Drawing and Printing Guide 中描述的打印机选项。 我有工具栏和UIBarBut
我有一个单例弹出窗口,因此我一次只显示一个弹出窗口。当我执行共享弹出窗口并选择 AirPrint 时,共享弹出窗口会正确消失,并在其位置显示 AirPrint 弹出窗口。 但是,如果我再次按下共享按钮
我有Posiflex打印机。据我所知,它没有启用 AirPrint。而且它也没有wifi。我需要做的是连接到打印机并使用我的 iPad (IOS 5) 中安装的支持 AirPrint 的应用程序打印输
我正在编写使用收据打印机将收据打印到连续纸卷上的代码。这些收据类似于您在商店使用信用卡付款时收到的收据。 我正在使用 UIMarkupTextPrintFormatter,您可以在下面的代码中看到。
我需要在没有用户交互的情况下在后台使用 Xcode 进行 AirPrint。我不在乎是否必须使用第 3 方框架来执行此操作。这是我的代码,但需要用户的交互。 NSMutableString *pri
我愿意在 iOS 中使用 AirPrint 从我的应用程序中导出一些 pdf 文件。然而,当我呈现 UIPrintInteractionController 时,它显示两个后退图标 <<。我附上了图像
我有点卡住了:-) 我有一个小应用程序,它允许我将地址簿中的字段放入标签类型 UIView 中。现在我希望能够打印出这些标签:-)如果它出现在一张普通的纸上,我现阶段不介意 - 我稍后会整理这部分内容
我的应用程序当前正在创建大小为 2480 3508 的图像(A4 页面)如何将此图像发送到 A4 页面上的 AirPrint?创建图像后,它会将其保存到照片应用程序中,我还想将其发送以进行打印。有任何
我可以选择在我的 iPhone 应用程序中进行打印。 按下“打印”按钮后,将显示 UIPrintInteractionController。问题是如果没有连接打印机,我想在按下打印按钮时显示警告。 我
我正在尝试在我的应用程序中实现 AirPrint。目前,我的代码是这样的: AirPrintingViewController.h #import @interface AirPrintingVie
我必须在横向模式下向我的 WebView 发送 Airprint。但是我在设置方向时遇到错误。我写了这段代码 let printcontroller = UIPrintInteractionC
我无法打印到我的打印机模拟器... 这是我所做的: 找到打印机模拟器 https://developer.apple.com/download/more/?=for%20Xcode 下载并安装 Add
我想显示一个列表,其中包含设备可通过 AirPrint 访问的所有打印机。 我使用 UIPrinterPickerController 让它工作。 是否有以自定义方式显示此 PickerControl
在我的 iOS 应用程序中,我有以下代码用于 AirPrinting 一个简单的 NSString。 #pragma mark - Print -(IBAction)print:(id)sender
我是一名优秀的程序员,十分优秀!