PDFViewController.m 25 KB

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