iphone – 如何打印在iOS 4.2?

iphone – 如何打印在iOS 4.2?,第1张

概述我想在我的应用程序中集成打印功能。 我要打印的文档将是.doc或.txt格式。 我在iPhone开发中的经验不是很高,所以发现很难通过遵循Apple的文档来实现它。 如果有人可以通过发布一些示例代码来帮助我,这将是一个很大的帮助。 查看 Drawing and Printing Guide for iOS – 我链接到打印部分。有示例代码和良好的链接到更多的示例代码。 编辑:我现在看到你指出你发现 我想在我的应用程序中集成打印功能。

我要打印的文档将是.doc或.txt格式。
我在iPhone开发中的经验不是很高,所以发现很难通过遵循Apple的文档来实现它。

如果有人可以通过发布一些示例代码来帮助我,这将是一个很大的帮助。

解决方法 查看 Drawing and Printing Guide for iOS – 我链接到打印部分。有示例代码和良好的链接到更多的示例代码。

编辑:我现在看到你指出你发现文档很难遵循。

Word文档很复杂 – 您需要解析数据,这是非常困难的。

文本和HTML更容易。我把苹果的例子用于HTML,并将其改为纯文本:

- (IBAction)printContent:(ID)sender {    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];    pic.delegate = self;    uiprintinfo *printInfo = [uiprintinfo printInfo];    printInfo.outputType = uiprintinfoOutputGeneral;    printInfo.jobname = self.documentname;    pic.printInfo = printInfo;    UISimpleTextPrintFormatter *textformatter = [[UISimpleTextPrintFormatter alloc]                                                 initWithText:yourNsstringWithContextOfTextfileHere];    textformatter.startPage = 0;    textformatter.contentInsets = UIEdgeInsetsMake(72.0,72.0,72.0); // 1 inch margins    textformatter.maximumContentWIDth = 6 * 72.0;    pic.printFormatter = textformatter;    [textformatter release];    pic.showsPageRange = YES;    voID (^completionHandler)(UIPrintInteractionController *,BOol,NSError *) =    ^(UIPrintInteractionController *printController,BOol completed,NSError *error) {        if (!completed && error) {            NSLog(@"Printing Could not complete because of error: %@",error);        }    };    if (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPad) {        [pic presentFrombarbuttonItem:sender animated:YES completionHandler:completionHandler];    } else {        [pic presentAnimated:YES completionHandler:completionHandler];    }}
总结

以上是内存溢出为你收集整理的iphone – 如何打印在iOS 4.2?全部内容,希望文章能够帮你解决iphone – 如何打印在iOS 4.2?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1087190.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存