PDFViewController.m 25 KB

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