PDFViewController.m 24 KB

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