PDFViewController.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. //
  2. // PDFViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-8-7.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "PDFViewController.h"
  9. #import "RAUtils.h"
  10. #import "const.h"
  11. #import "AppDelegate.h"
  12. @interface PDFViewController ()
  13. @end
  14. @implementation PDFViewController
  15. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  16. {
  17. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  18. if (self) {
  19. // Custom initialization
  20. }
  21. return self;
  22. }
  23. - (void)viewDidLoad
  24. {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  28. ref.tag = 200 ;
  29. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag to refresh"];
  30. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  31. // ref.hidden = true;
  32. [ref addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  33. [self.webView.scrollView addSubview:ref];
  34. self.webView.dataDetectorTypes=UIDataDetectorTypeAll;
  35. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  36. style:UIBarButtonItemStylePlain
  37. target:self
  38. action:@selector( onBackClick:)];
  39. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  40. // closeButton.title = @"Close";
  41. self.navigationItem.leftBarButtonItem = closeButton;
  42. self.btnshare = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"share"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  43. style:UIBarButtonItemStylePlain
  44. target:self
  45. action:@selector(onActionClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onOpenOrderClick:)];
  46. // self.btnshare.tintColor = UIColorFromRGB(0x996633);
  47. self.btnemail =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"mail"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  48. style:UIBarButtonItemStylePlain
  49. target:self
  50. action:@selector(onEmailClick:)];// [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Commit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCommitOrderClick:)];
  51. // self.btnemail.tintColor = UIColorFromRGB(0x996633);
  52. // self.btnSend = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Email", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSendMailClick:)];
  53. self.btnsave = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  54. style:UIBarButtonItemStylePlain
  55. target:self
  56. action:@selector(onSaveClick:)];
  57. // self.btnsave.tintColor = UIColorFromRGB(0x996633);
  58. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  59. fixedItem.width = 20.0f;
  60. NSMutableArray * items = [[NSMutableArray alloc]init];
  61. [items addObject:self.btnshare];
  62. [items addObject:fixedItem];
  63. [items addObject:self.btnemail];
  64. if(self.canSave)
  65. {
  66. [items addObject:fixedItem];
  67. [items addObject:self.btnsave];
  68. }
  69. self.navigationItem.rightBarButtonItems=items;
  70. self.btnshare.enabled =false;
  71. self.btnemail.enabled =false;
  72. self.btnsave.enabled =false;
  73. // self.url=@"http://192.168.1.3:8080/npd/test.pdf";
  74. // NSURL* url = [NSURL URLWithString:self.url];
  75. //
  76. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:2000];
  77. //
  78. //
  79. // [self.webView loadRequest:request];
  80. [self loadcontent];
  81. }
  82. - (void)onBackClick:(UIButton *)sender {
  83. [self.navigationController popViewControllerAnimated:FALSE];
  84. }
  85. -(void)ReloadData
  86. {
  87. // Count ++ ;
  88. // [mytabelview reloadData];
  89. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  90. [reF endRefreshing];
  91. [self loadcontent];
  92. }
  93. -(void) loadcontent
  94. {
  95. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Loading..."];
  96. self.mum.hidden=false;
  97. if(self.isLocalfile)
  98. {
  99. /*
  100. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  101. NSString *cachefolder = [paths objectAtIndex:0];
  102. NSString *pdfFolder = [cachefolder stringByAppendingPathComponent:@"pdf_cache"];
  103. self.url = [pdfFolder stringByAppendingPathComponent:self.url];
  104. */
  105. self.content= [NSData dataWithContentsOfFile:self.url];
  106. [self.webView loadData:self.content MIMEType:@"application/pdf" textEncodingName:nil baseURL:nil];
  107. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  108. self.filename=[self.url lastPathComponent];
  109. self.btnshare.enabled =true;
  110. self.btnemail.enabled =true;
  111. self.btnsave.enabled =true;
  112. if(self.onLoadSuccess)
  113. self.onLoadSuccess(self.url);
  114. if(self.autoPrint)
  115. [self startAirPrintWithData:self.content];
  116. }
  117. else
  118. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  119. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  120. //设置请求方式为get
  121. [request setHTTPMethod:@"GET"];
  122. //添加用户会话id
  123. [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  124. //连接发送请求
  125. NSHTTPURLResponse* urlResponse = nil;
  126. NSError *error = nil;
  127. self.content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  128. self.filename = [urlResponse suggestedFilename];
  129. dispatch_async(dispatch_get_main_queue(), ^{
  130. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  131. [[self navigationController] setNavigationBarHidden:self.hidenavi animated:NO];
  132. self.navigationItem.title = self.save_name;
  133. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  134. // self.content=nil;
  135. if(self.content!=nil&&self.content.length>0)
  136. {
  137. [reF removeFromSuperview];
  138. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  139. NSString *path = NSTemporaryDirectory();
  140. NSString *filePath = [path stringByAppendingPathComponent:self.filename];
  141. // NSError *error = nil;
  142. // BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  143. // NSAssert(bo,@"创建目录失败");
  144. [self.content writeToFile:filePath atomically:YES];
  145. self.btnshare.enabled =true;
  146. self.btnemail.enabled =true;
  147. self.btnsave.enabled =true;
  148. if(self.onLoadSuccess)
  149. self.onLoadSuccess(self.url);
  150. if(self.autoPrint)
  151. [self startAirPrintWithData:self.content];
  152. // int a=0;
  153. }
  154. else
  155. {
  156. [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  157. if(self.autoPrint)
  158. [self.navigationController popViewControllerAnimated:true];
  159. // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  160. }
  161. ;
  162. // DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  163. //
  164. // DebugLog(urlResponse.MIMEType);
  165. [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  166. });
  167. });
  168. }
  169. -(void)changeCell
  170. {
  171. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  172. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  173. if ([self respondsToSelector:@selector(ReloadData)])
  174. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  175. // DebugLog(@"refresh!!!!!!!!");
  176. }
  177. - (void)didReceiveMemoryWarning
  178. {
  179. [super didReceiveMemoryWarning];
  180. // Dispose of any resources that can be recreated.
  181. }
  182. -(void) viewWillAppear:(BOOL)animated
  183. {
  184. [super viewWillAppear:animated];
  185. [[self navigationController] setNavigationBarHidden:self.hidenavi animated:NO];
  186. }
  187. - (IBAction)onActionClick:(id)sender {
  188. //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  189. NSString *path = NSTemporaryDirectory();
  190. NSString* filename =self.filename;
  191. NSString *filePath = [path stringByAppendingPathComponent:filename];
  192. [self openFile:filePath];
  193. }
  194. - (IBAction)onSaveClick:(id)sender {
  195. //UIAlertControllerStyle两种类型UIAlertControllerStyleAlert类似UIAlertView
  196. //UIAlertControllerStyleActionSheet类似UIActionSheet
  197. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Save pdf" message:nil preferredStyle:UIAlertControllerStyleAlert];
  198. //block代码块取代了delegate
  199. [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  200. textField.text = self.save_name;
  201. }];
  202. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  203. UITextField *name = alertControl.textFields.firstObject;
  204. if(name.text.length==0)
  205. {
  206. [RAUtils message_alert:@"Cannot save without name. Save canceled." title:@"Name is missing" controller:self];
  207. }
  208. else
  209. {
  210. self.save_name = name.text;
  211. self.btnsave.enabled =false;
  212. // NSMutableDictionary * info =
  213. if(self.onSavePDF)
  214. self.onSavePDF(self.save_name,self.filename);
  215. }
  216. }];
  217. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  218. DebugLog(@"Cancel");
  219. }];
  220. [alertControl addAction:actionOne];
  221. [alertControl addAction:alertthree];
  222. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  223. [self presentViewController:alertControl animated:YES completion:nil];
  224. }
  225. - (IBAction)onEmailClick:(id)sender {
  226. //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  227. NSString *path = NSTemporaryDirectory();
  228. NSString* filename =self.filename;
  229. NSString *filePath = [path stringByAppendingPathComponent:filename];
  230. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  231. if(mc==nil)
  232. {
  233. //[RAUtils message_alert:@"You must create an email account first." title:@"Send Email" controller:self];
  234. return;
  235. }
  236. mc.mailComposeDelegate = self;
  237. [mc setSubject:self.mail_subject];
  238. [mc setToRecipients:self.mail_to];
  239. if(self.mail_content==nil)
  240. self.mail_content=@"";
  241. NSString* htmlbody = [NSString stringWithFormat:@"<html><p>%@</p></html>",self.mail_content];
  242. [mc setMessageBody:htmlbody
  243. isHTML:YES];
  244. NSData *data = [NSData dataWithContentsOfFile:filePath];
  245. if(self.attachment_name.length>0)
  246. filename = self.attachment_name;
  247. [mc addAttachmentData:data mimeType:@"application/pdf" fileName:filename];
  248. [self presentModalViewController:mc animated:YES];
  249. return;
  250. }
  251. -(void)openFile: (NSString *) file_url {
  252. NSURL *file_URL = [NSURL fileURLWithPath:file_url];
  253. if (file_URL != nil) {
  254. if (self.fileInteractionController == nil) {
  255. //_fileInteractionController = [[UIDocumentInteractionController alloc] init];
  256. _fileInteractionController = [UIDocumentInteractionController interactionControllerWithURL:file_URL];
  257. _fileInteractionController.delegate = self;
  258. // [_fileInteractionController retain];//不适用ARC,记得RETAIN 使用ARC注释这一行
  259. }
  260. else
  261. {
  262. self.fileInteractionController.URL = file_URL;
  263. }
  264. // [self.fileInteractionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
  265. [self.fileInteractionController setName:self.mail_subject];
  266. // [self.fileInteractionController setAnnotation:<#(id _Nullable)#>;
  267. [self.fileInteractionController presentOptionsMenuFromBarButtonItem:self.btnshare animated:YES];
  268. // [self.fileInteractionController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  269. // [self.fileInteractionController presentPreviewAnimated:YES];
  270. }
  271. }
  272. //- (void) sendEmail:(NSString *)to cc:(NSString*)cc subject:(NSString*)subject body:(NSString*)body
  273. //{
  274. // NSString* str = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@",
  275. // to, cc, subject, body];
  276. // str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  277. //
  278. // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
  279. //
  280. //
  281. //}
  282. #pragma mark methods for the UIDocumentInteractionControllerDelegate
  283. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  284. {
  285. // if (controller == self.fileInteractionController) {
  286. // self.fileInteractionController = nil;
  287. // }
  288. }
  289. - (void)previewDocumentWithURL:(NSURL*)url
  290. {
  291. UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
  292. preview.delegate = self;
  293. [preview presentPreviewAnimated:YES];
  294. }
  295. - (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
  296. {
  297. }
  298. - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
  299. return self;
  300. }
  301. - (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller{
  302. return self.view.frame;
  303. }
  304. - (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller{
  305. return self.view;
  306. }
  307. - (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(nullable NSString *)application // bundle ID
  308. {
  309. }
  310. #pragma mark - web view delegate
  311. - (void)webViewDidFinishLoad:(UIWebView *)webView
  312. {
  313. self.mum.hidden=true;
  314. }
  315. #pragma mark -MFMailComposeViewControllerDelegate delegate
  316. - (void)mailComposeController:(MFMailComposeViewController*)controller
  317. didFinishWithResult:(MFMailComposeResult)result
  318. error:(NSError*)error {
  319. switch (result)
  320. {
  321. case MFMailComposeResultCancelled:
  322. DebugLog(@"Mail send canceled...");
  323. break;
  324. case MFMailComposeResultSaved:
  325. DebugLog(@"Mail saved...");
  326. break;
  327. case MFMailComposeResultSent:
  328. DebugLog(@"Mail sent...");
  329. break;
  330. case MFMailComposeResultFailed:
  331. DebugLog(@"Mail send errored: %@...", [error localizedDescription]);
  332. break;
  333. default:
  334. break;
  335. }
  336. [self dismissModalViewControllerAnimated:YES];
  337. }
  338. /*
  339. #pragma mark - Navigation
  340. In a storyboard-based application, you will often want to do a little preparation before navigation
  341. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  342. {
  343. Get the new view controller using [segue destinationViewController].
  344. Pass the selected object to the new view controller.
  345. }
  346. */
  347. - (void)startAirPrintWithData:(id )data
  348. {
  349. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"preparing print..."];
  350. UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  351. UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  352. printInfo.outputType = UIPrintInfoOutputGeneral;
  353. printInfo.orientation = UIPrintInfoOrientationPortrait;
  354. printInfo.jobName = @"CoolVisitAirPrint";
  355. airPrinterController.printInfo = printInfo;
  356. airPrinterController.printingItem = data;
  357. airPrinterController.delegate = self;
  358. airPrinterController.showsNumberOfCopies=true;
  359. airPrinterController.showsPageRange = true;
  360. airPrinterController.showsPaperSelectionForLoadedPapers=true;
  361. void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  362. if(completed && error)
  363. DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
  364. };
  365. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  366. UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  367. [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  368. {
  369. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  370. if (available&& appDelegate.printerURL.length>0)
  371. {
  372. [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  373. DebugLog(@"AIRPRINTER AVAILABLE");
  374. }
  375. else
  376. {
  377. // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  378. //
  379. //
  380. //
  381. // // [printPicker presentAnimated:YES completionHandler:
  382. // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  383. // {
  384. // if (userDidSelect)
  385. // {
  386. // NSString* sid= printerController.printInfo.printerID;
  387. // UIPrintPaper*paper= printerController.printPaper;
  388. //
  389. // }
  390. // }];
  391. DebugLog(@"AIRPRINTER NOT AVAILABLE");
  392. if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  393. {
  394. UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  395. // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  396. [ printPicker presentFromBarButtonItem:self.btnshare animated:YES completionHandler:
  397. // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  398. // [printPicker presentAnimated:YES completionHandler:
  399. ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  400. {
  401. if (userDidSelect)
  402. {
  403. //User selected the item in the UIPrinterPickerController and got the printer details.
  404. [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  405. //Here you will get the printer and printer details.ie,
  406. // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  407. appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  408. [self startAirPrintWithData:data];
  409. }
  410. else
  411. {
  412. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  413. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  414. // {
  415. //
  416. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  417. // }
  418. // [self prepareReturn:nil];
  419. //[self.navigationController popViewControllerAnimated:true];
  420. }
  421. }];
  422. }
  423. }
  424. }];
  425. }
  426. #pragma mark - UIPrintInteractionControllerDelegate
  427. - (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  428. {
  429. ;
  430. // (int) width = 29700
  431. // Printing description of (*( (int *)0x7caa3a40)):
  432. // (int) height = 42000
  433. //设置纸张大小
  434. for(UIPrintPaper* paper in paperList)
  435. {
  436. if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  437. return paper;
  438. }
  439. CGSize paperSize = CGSizeMake(612, 792);
  440. UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  441. return p;
  442. }
  443. - (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  444. {
  445. }
  446. - (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  447. {
  448. }
  449. - (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  450. {
  451. }
  452. - (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  453. {
  454. }
  455. - (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  456. {
  457. }
  458. - (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  459. {
  460. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  461. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  462. // {
  463. //
  464. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  465. // }
  466. //
  467. // [self prepareReturn:nil];
  468. if(self.autoPrint)
  469. [self.navigationController popViewControllerAnimated:true];
  470. }
  471. @end