|
@@ -10,6 +10,8 @@
|
|
|
#import "RAUtils.h"
|
|
#import "RAUtils.h"
|
|
|
#import "const.h"
|
|
#import "const.h"
|
|
|
#import "AppDelegate.h"
|
|
#import "AppDelegate.h"
|
|
|
|
|
+#import "PDFUtils.h"
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@interface PDFViewController ()
|
|
@interface PDFViewController ()
|
|
|
|
|
|
|
@@ -55,9 +57,21 @@
|
|
|
self.btnshare =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
|
|
self.btnshare =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
|
|
|
target:self
|
|
target:self
|
|
|
action:@selector( onActionClick:)];
|
|
action:@selector( onActionClick:)];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- self.navigationItem.rightBarButtonItem =self.btnshare;
|
|
|
|
|
|
|
+ self.btnPrint =[[UIBarButtonItem alloc] initWithTitle:@"Print"
|
|
|
|
|
+ style:UIBarButtonItemStylePlain
|
|
|
|
|
+ target:self
|
|
|
|
|
+ action:@selector( onPrintClick:)];
|
|
|
|
|
+
|
|
|
|
|
+ NSMutableArray * items = [[NSMutableArray alloc]init];
|
|
|
|
|
+ [items addObject:self.btnshare];
|
|
|
|
|
+ [items addObject:self.btnPrint];
|
|
|
|
|
|
|
|
|
|
+ self.navigationItem.rightBarButtonItems =items;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -296,6 +310,138 @@
|
|
|
[super viewWillAppear:animated];
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
[[self navigationController] setNavigationBarHidden:self.hidenavi animated:NO];
|
|
[[self navigationController] setNavigationBarHidden:self.hidenavi animated:NO];
|
|
|
|
|
+}
|
|
|
|
|
+- (IBAction)onPrintClick:(id)sender {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"preparing print..."];
|
|
|
|
|
+
|
|
|
|
|
+ UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
|
|
|
|
|
+ UIPrintInfo *printInfo = [UIPrintInfo printInfo];
|
|
|
|
|
+ printInfo.outputType = UIPrintInfoOutputGeneral;
|
|
|
|
|
+
|
|
|
|
|
+ printInfo.orientation = UIPrintInfoOrientationPortrait;
|
|
|
|
|
+ printInfo.jobName = @"CoolVisitAirPrint";
|
|
|
|
|
+ airPrinterController.printInfo = printInfo;
|
|
|
|
|
+ airPrinterController.printingItem = self.content;
|
|
|
|
|
+ airPrinterController.delegate = self;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ airPrinterController.showsNumberOfCopies=true;
|
|
|
|
|
+ airPrinterController.showsPageRange = true;
|
|
|
|
|
+ airPrinterController.showsPaperSelectionForLoadedPapers=true;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ [airPrinterController presentFromBarButtonItem:self.btnPrint
|
|
|
|
|
+ animated:YES
|
|
|
|
|
+ completionHandler:
|
|
|
|
|
+ ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
|
|
|
|
|
+ }
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+//
|
|
|
|
|
+// void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
|
|
|
|
|
+// if(completed && error)
|
|
|
|
|
+// 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);
|
|
|
|
|
+// };
|
|
|
|
|
+//
|
|
|
|
|
+// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
|
|
|
|
+//
|
|
|
|
|
+// UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
|
|
|
|
|
+// {
|
|
|
|
|
+// [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
|
|
+//
|
|
|
|
|
+// if (available&& appDelegate.printerURL.length>0)
|
|
|
|
|
+// {
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
|
|
|
|
|
+// DebugLog(@"AIRPRINTER AVAILABLE");
|
|
|
|
|
+// }
|
|
|
|
|
+// else
|
|
|
|
|
+// {
|
|
|
|
|
+//
|
|
|
|
|
+// [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// // [printPicker presentAnimated:YES completionHandler:
|
|
|
|
|
+// ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
|
|
|
|
|
+// {
|
|
|
|
|
+// if (userDidSelect)
|
|
|
|
|
+// {
|
|
|
|
|
+// NSString* sid= printerController.printInfo.printerID;
|
|
|
|
|
+// UIPrintPaper*paper= printerController.printPaper;
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+// }];
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// DebugLog(@"AIRPRINTER NOT AVAILABLE");
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//// if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
|
|
|
|
|
+//// {
|
|
|
|
|
+//// UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
|
|
|
|
|
+//// // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// [ printPicker presentFromBarButtonItem:self.btnPrint animated:YES completionHandler:
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// // [printPicker presentAnimated:YES completionHandler:
|
|
|
|
|
+//// ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
|
|
|
|
|
+//// {
|
|
|
|
|
+//// if (userDidSelect)
|
|
|
|
|
+//// {
|
|
|
|
|
+//// //User selected the item in the UIPrinterPickerController and got the printer details.
|
|
|
|
|
+////
|
|
|
|
|
+//// [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
|
|
|
|
|
+////
|
|
|
|
|
+//// //Here you will get the printer and printer details.ie,
|
|
|
|
|
+//// // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
|
|
|
|
|
+////
|
|
|
|
|
+//// [self startAirPrintWithData:self.content];
|
|
|
|
|
+////
|
|
|
|
|
+//// }
|
|
|
|
|
+//// else
|
|
|
|
|
+//// {
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
|
|
|
|
+//// // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
|
|
|
|
|
+//// // {
|
|
|
|
|
+//// //
|
|
|
|
|
+//// // [((MainViewController*)appDelegate.main_vc) Loginout:false];
|
|
|
|
|
+//// // }
|
|
|
|
|
+//// // [self prepareReturn:nil];
|
|
|
|
|
+////
|
|
|
|
|
+//// //[self.navigationController popViewControllerAnimated:true];
|
|
|
|
|
+//// }
|
|
|
|
|
+//// }];
|
|
|
|
|
+//// }
|
|
|
|
|
+// }
|
|
|
|
|
+// }];
|
|
|
|
|
+//
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- (IBAction)onActionClick:(id)sender {
|
|
- (IBAction)onActionClick:(id)sender {
|
|
|
|
|
|
|
@@ -671,14 +817,17 @@
|
|
|
// (int) height = 42000
|
|
// (int) height = 42000
|
|
|
//设置纸张大小
|
|
//设置纸张大小
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ CGSize paperSize=[PDFUtils QueryPDFSizeFromData:self.content];
|
|
|
for(UIPrintPaper* paper in paperList)
|
|
for(UIPrintPaper* paper in paperList)
|
|
|
{
|
|
{
|
|
|
- if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
|
|
|
|
|
|
|
+ if (CGSizeEqualToSize(paper.paperSize, paperSize))
|
|
|
return paper;
|
|
return paper;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
- CGSize paperSize = CGSizeMake(612, 792);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ UIPrintPaper * pp=[[UIPrintPaper alloc] init];
|
|
|
|
|
+
|
|
|
|
|
+// CGSize paperSize = CGSizeMake(612, 792);
|
|
|
UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
|
|
UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
|
|
|
return p;
|
|
return p;
|
|
|
}
|
|
}
|