Support for roll printers (#185)
* Added ability to hint papersize and cut on roleprinters * Documentation of paper formats and cuts * fixed pick printer without bounds * removed NSLog
This commit is contained in:
		
				
					committed by
					
						 Sebastián Katzer
						Sebastián Katzer
					
				
			
			
				
	
			
			
			
						parent
						
							ee9fba07ac
						
					
				
				
					commit
					675b3f5962
				
			| @@ -152,6 +152,9 @@ The method accepts a list of attributes. Not all are supported on each platform | ||||
| | hidePageRange | Set to _true_ to hide the control for the page range.<br>Defaults to: false | Boolean | iOS | | ||||
| | hideNumberOfCopies | Set to _true_ to hide the control for the number of copies.<br>Defaults to: false | Boolean | iOS | | ||||
| | hidePaperFormat | Set to _true_ to hide the control for the paper format.<br>Defaults to: false | Boolean | iOS | | ||||
| | paperWidth | Ability to hint width of the paper – iOS will get a printer supported paperformat which fits the best to this width. Only works when `paperHeight` is given. Width in millimeters. | Number | iOS | | ||||
| | paperHeight | Ability to hint height of the paper – iOS will get a printer paperformat which fits the best to this heigth. Only works when `paperWidth` is given. Height in millimeters. | Number | iOS | | ||||
| | paperCutLength | On roll-fed printers you can decide after how many milimeters the printer cuts the paper. | Number | iOS | | ||||
| | bounds | The Size and position of the print view<br>Defaults to: [40, 30, 0, 0] | Array | iPad | | ||||
|  | ||||
| #### Further informations | ||||
|   | ||||
| @@ -23,7 +23,7 @@ | ||||
| #import <Cordova/CDVPlugin.h> | ||||
|  | ||||
|  | ||||
| @interface APPPrinter : CDVPlugin <UIWebViewDelegate> | ||||
| @interface APPPrinter : CDVPlugin <UIWebViewDelegate, UIPrintInteractionControllerDelegate> | ||||
|  | ||||
| // this is used to cache the uiprinter making repeated prints faster | ||||
| @property (nonatomic) UIPrinter *previousPrinter; | ||||
|   | ||||
| @@ -76,6 +76,7 @@ | ||||
|     self.settings                 = [arguments objectAtIndex:1]; | ||||
|  | ||||
|     UIPrintInteractionController* controller = [self printController]; | ||||
|     controller.delegate = self; | ||||
|  | ||||
|     [self adjustPrintController:controller withSettings:self.settings]; | ||||
|     [self loadContent:content intoPrintController:controller]; | ||||
| @@ -98,8 +99,12 @@ | ||||
|     NSArray*  arguments           = [command arguments]; | ||||
|     NSMutableDictionary* settings = [arguments objectAtIndex:0]; | ||||
|  | ||||
|     NSArray* bounds = [settings objectForKey:@"bounds"]; | ||||
|     CGRect rect     = [self convertIntoRect:bounds]; | ||||
|  | ||||
|     CGRect rect     = CGRectMake(40, 30, 0, 0); //Default in documentation | ||||
|     if (settings != (id)[NSNull null] && [settings objectForKey:@"bounds"] != nil){ | ||||
|         NSArray* bounds = [settings objectForKey:@"bounds"]; | ||||
|         rect     = [self convertIntoRect:bounds]; | ||||
|     } | ||||
|      | ||||
|     [self presentPrinterPicker:rect]; | ||||
| } | ||||
| @@ -332,6 +337,41 @@ | ||||
|     return controller; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Choose paper Delegate. If Paper-Size is given it selects the best fitting papersize | ||||
|  */ | ||||
|  | ||||
| - (UIPrintPaper *) printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray *)paperList { | ||||
|     if ([[self.settings objectForKey:@"paperHeight"] doubleValue] && [[self.settings objectForKey:@"paperHeight"] doubleValue]){ | ||||
|         double heigth = [[self.settings objectForKey:@"paperHeight"] doubleValue]; | ||||
|         double width = [[self.settings objectForKey:@"paperWidth"] doubleValue]; | ||||
|         double dotsHeigth = 72*heigth / 25.4; //convert milimeters to dots | ||||
|         double dotsWidth = 72*width / 25.4; //convert milimeters to dots | ||||
|         CGSize pageSize = CGSizeMake(dotsHeigth, dotsWidth); | ||||
|          | ||||
|         // get best fitting paper size | ||||
|         UIPrintPaper* paper = [UIPrintPaper bestPaperForPageSize:pageSize withPapersFromArray:paperList]; | ||||
|         return paper; | ||||
|     } | ||||
|     else { | ||||
|         return NULL; | ||||
|     } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * cutPaper Delegate. If using roll printers like Label-Printer (brother QL-710W) you can cut paper after given length. | ||||
|  */ | ||||
| - (CGFloat)printInteractionController:(UIPrintInteractionController *)printInteractionController | ||||
|                     cutLengthForPaper:(UIPrintPaper *)paper { | ||||
|     if ([[self.settings objectForKey:@"paperCutLength"] doubleValue]){ | ||||
|         double cutLength = [[self.settings objectForKey:@"paperCutLength"] doubleValue]; | ||||
|         return 72 * cutLength / 25.4; //convert milimeters to dots | ||||
|     } else { | ||||
|         return paper.paperSize.height; | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Loads the content into the print controller. | ||||
|  * | ||||
| @@ -385,3 +425,4 @@ | ||||
| } | ||||
|  | ||||
| @end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user