Print-View positioning on iPad
This commit is contained in:
parent
268f1b652d
commit
15aa295cf6
@ -2,6 +2,7 @@
|
||||
#### Version 0.7.1 (not yet released)
|
||||
- [bugfix:] `isAvailable` does not block the main thread anymore.
|
||||
- [bugfix:] iPad+iOS8 incompatibility (Thanks to __zmagyar__)
|
||||
- [enhancement:] Print-View positioning on iPad
|
||||
|
||||
#### Version 0.7.0 (12.09.2014)
|
||||
- Android Printing Framework support
|
||||
|
10
README.md
10
README.md
@ -98,6 +98,7 @@ cordova plugin rm de.appplant.cordova.plugin.printer
|
||||
#### Version 0.7.1 (not yet released)
|
||||
- [bugfix:] `isAvailable` does not block the main thread anymore.
|
||||
- [bugfix:] iPad+iOS8 incompatibility (Thanks to __zmagyar__)
|
||||
- [enhancement:] Print-View positioning on iPad
|
||||
|
||||
#### Version 0.7.0 (12.09.2014)
|
||||
- Android Printing Framework support
|
||||
@ -164,6 +165,7 @@ The method takes a string or a HTML DOM node. The string can contain HTML conten
|
||||
| duplex | Specifies the duplex mode to use for the print job.<br>Either double-sided (duplex:true) or single-sided (duplex:false).<br>Double-sided by default. | Boolean | iOS |
|
||||
| landscape| The orientation of the printed content, portrait or landscape.<br>_Portrait_ by default. | Boolean | all |
|
||||
| graystyle | If your application only prints black text, setting this property to _true_ can result in better performance in many cases.<br>_False_ by default. | Boolean | all |
|
||||
| bounds | The Size & position of the print view | Array | iPad |
|
||||
|
||||
#### Further informations
|
||||
- See the [isAvailable][available] method to find out if printing is available on the device.
|
||||
@ -236,6 +238,14 @@ cordova.plugins.printer.print('123', { name:'Document.html', landscape:true }, f
|
||||
});
|
||||
```
|
||||
|
||||
#### 6. Custom size and position on iPad
|
||||
```javascript
|
||||
// Option one
|
||||
cordova.plugins.printer.print('123', { bounds:[40, 30, 0, 0] });
|
||||
// Option two
|
||||
cordova.plugins.printer.print('123', { bounds:{ left:40, top:30, width:0 height: 0} });
|
||||
```
|
||||
|
||||
|
||||
## Quirks
|
||||
|
||||
|
@ -71,9 +71,11 @@
|
||||
|
||||
UIPrintInteractionController* controller = [self printController];
|
||||
|
||||
CGRect rect = [self convertIntoRect:[settings objectForKey:@"bounds"]];
|
||||
|
||||
[self adjustPrintController:controller withSettings:settings];
|
||||
[self loadContent:content intoPrintController:controller];
|
||||
[self presentPrintController:controller];
|
||||
[self presentPrintController:controller fromRect:rect];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -184,10 +186,9 @@
|
||||
* The prepared print controller with a content
|
||||
*/
|
||||
- (void) presentPrintController:(UIPrintInteractionController*)controller
|
||||
fromRect:(CGRect)rect
|
||||
{
|
||||
if(CDV_IsIPad()) {
|
||||
CGRect rect = CGRectMake(40, 30, 0, 0);
|
||||
|
||||
[controller presentFromRect:rect inView:self.webView animated:YES completionHandler:
|
||||
^(UIPrintInteractionController *ctrl, BOOL ok, NSError *e) {
|
||||
CDVPluginResult* pluginResult =
|
||||
@ -209,6 +210,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Array into Rect object.
|
||||
*
|
||||
* @param bounds
|
||||
* The bounds
|
||||
*
|
||||
* @return
|
||||
* A converted Rect object
|
||||
*/
|
||||
- (CGRect) convertIntoRect:(NSArray*)bounds
|
||||
{
|
||||
return CGRectMake([[bounds objectAtIndex:0] floatValue],
|
||||
[[bounds objectAtIndex:1] floatValue],
|
||||
[[bounds objectAtIndex:2] floatValue],
|
||||
[[bounds objectAtIndex:3] floatValue]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks either the printing service is avaible or not.
|
||||
*
|
||||
|
@ -26,6 +26,20 @@ var exec = require('cordova/exec');
|
||||
*/
|
||||
exports.DEFAULT_DOC_NAME = 'unknown';
|
||||
|
||||
/**
|
||||
* List of all available options with their default value.
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
exports.getDefaults = function () {
|
||||
return {
|
||||
name: exports.DEFAULT_DOC_NAME,
|
||||
duplex: true,
|
||||
landscape: false,
|
||||
bounds: [40, 30, 0, 0]
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if the printer service is avaible (iOS)
|
||||
* or if connected to the Internet (Android).
|
||||
@ -69,12 +83,52 @@ exports.print = function (content, options, callback, scope) {
|
||||
if (typeof params == 'string')
|
||||
params = { name: params };
|
||||
|
||||
params = this.mergeWithDefaults(params);
|
||||
|
||||
if ([null, undefined, ''].indexOf(params.name) > -1)
|
||||
params.name = this.DEFAULT_DOC_NAME;
|
||||
|
||||
exec(fn, null, 'Printer', 'print', [page, params]);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* Merge settings with default values.
|
||||
*
|
||||
* @param {Object} options
|
||||
* The custom options
|
||||
*
|
||||
* @retrun {Object}
|
||||
* Default values merged
|
||||
* with custom values
|
||||
*/
|
||||
exports.mergeWithDefaults = function (options) {
|
||||
var defaults = this.getDefaults();
|
||||
|
||||
if (options.bounds && !options.bounds.length) {
|
||||
options.bounds = [
|
||||
options.bounds.left || defaults.bounds[0],
|
||||
options.bounds.top || defaults.bounds[1],
|
||||
options.bounds.width || defaults.bounds[2],
|
||||
options.bounds.height || defaults.bounds[3],
|
||||
];
|
||||
}
|
||||
|
||||
for (var key in defaults) {
|
||||
if (!options.hasOwnProperty(key)) {
|
||||
options[key] = defaults[key];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof options[key] != typeof defaults[key]) {
|
||||
delete options[key];
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
@ -95,4 +149,4 @@ exports._createCallbackFn = function (callbackFn, scope) {
|
||||
return function () {
|
||||
callbackFn.apply(scope || this, arguments);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user