Compare commits

..

No commits in common. "9044cbe1d4cf7c405dd4cbc9c60d4a0a28b5ffce" and "02d54a063fc947331694fe174c24fd151a078e61" have entirely different histories.

16 changed files with 47 additions and 89 deletions

View File

@ -1,13 +1,6 @@
## ChangeLog ## ChangeLog
#### Version 0.7.4 (not yet released)
#### Version 0.8.0 (01.03.2019) - Fix broken _check_ and _pick_ on Android N and above
- Most parts of the code has been rewritten
- Added support for Android 8+
- Added support for iOS 10+
- Added support for the browser platform
- Added support for header and foooter
- Added support to print PDF files, images, Base64 encoded images
- And many more, see the new README
#### Version 0.7.3 (19.12.2016) #### Version 0.7.3 (19.12.2016)
- Fixed incompatibility with Android KitKat (4.4) - Fixed incompatibility with Android KitKat (4.4)

View File

@ -5,13 +5,9 @@
# Cordova Print Plugin <br> [![npm version](https://badge.fury.io/js/cordova-plugin-printer.svg)](http://badge.fury.io/js/cordova-plugin-printer) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=L3HKQCD9UA35A "Donate once-off to this project using Paypal") # Cordova Print Plugin <br> [![npm version](https://badge.fury.io/js/cordova-plugin-printer.svg)](http://badge.fury.io/js/cordova-plugin-printer) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=L3HKQCD9UA35A "Donate once-off to this project using Paypal")
Plugin for [Cordova][cordova] to print documents, photos, HTML and plain text from iOS, Android and Windows Universal apps. <img width="280px" align="right" hspace="20" vspace="10" src="https://github.com/katzer/cordova-plugin-printer/blob/example/images/print-ios.png">
```js Plugin for [Cordova][cordova] to print documents or photos from iOS, Android and Windows Universal apps.
cordova.plugins.printer.print('<b>Hello Cordova!</b>');
```
<img width="280px" align="right" src="https://github.com/katzer/cordova-plugin-printer/blob/example/images/print.png">
### Supported Printer Interfaces ### Supported Printer Interfaces
@ -34,6 +30,7 @@ cordova.plugins.printer.print('<b>Hello Cordova!</b>');
- Windows 10 UWP - Windows 10 UWP
- Browser - Browser
## Basics ## Basics
The plugin creates the object `cordova.plugins.printer` and is accessible after the *deviceready* event has been fired. The plugin creates the object `cordova.plugins.printer` and is accessible after the *deviceready* event has been fired.
@ -104,7 +101,6 @@ The list of possible options depend on the platform, the content type and the ca
| autoFit | Set to _false_ to disable downscaling the image to fit into the content aread. | Boolean | Android | | autoFit | Set to _false_ to disable downscaling the image to fit into the content aread. | Boolean | Android |
| printer | The network URL to the printer. | String | iOS | | printer | The network URL to the printer. | String | iOS |
| maxHeight<br>maxWidth | Defines the maximum size of the content area. | Unit | iOS | | maxHeight<br>maxWidth | Defines the maximum size of the content area. | Unit | iOS |
| margin | Set to _false_ to avoid margins. | Boolean | all |
| margin.top<br>margin.left<br>margin.right<br>margin.bottom | The margins for each printed page. Each printer might have its own minimum margins depends on media type and paper format. | Unit | iOS | | margin.top<br>margin.left<br>margin.right<br>margin.bottom | The margins for each printed page. Each printer might have its own minimum margins depends on media type and paper format. | Unit | iOS |
| ui.hideNumberOfCopies | Set to _true_ to hide the control for the number of copies. | Boolean | iOS | | ui.hideNumberOfCopies | Set to _true_ to hide the control for the number of copies. | Boolean | iOS |
| ui.hidePaperFormat | Set to _true_ to hide the control for the paper format. | Boolean | iOS | | ui.hidePaperFormat | Set to _true_ to hide the control for the paper format. | Boolean | iOS |
@ -153,6 +149,7 @@ cordova.plugins.printer.pick({ top: 40, left: 30 }, callback);
__Note:__ By passing an invalid URL, the application will throw an `Unable to connect to (null)` exception and possibly crash. __Note:__ By passing an invalid URL, the application will throw an `Unable to connect to (null)` exception and possibly crash.
## Printable Document Types ## Printable Document Types
The list of supported document types differ between mobile platforms. As of writing, Windows UWP only supports HTML and plain text. The list of supported document types differ between mobile platforms. As of writing, Windows UWP only supports HTML and plain text.
@ -175,44 +172,11 @@ Or in particular:
cordova.plugins.printer.canPrintItem('file://css/index.css', callback); cordova.plugins.printer.canPrintItem('file://css/index.css', callback);
``` ```
## Sample
```js
var options = {
font: {
size: 22,
italic: true,
align: 'center'
},
header: {
height: '6cm',
label: {
text: "\n\nDie Freuden",
font: {
bold: true,
size: 37,
align: 'center'
}
}
},
footer: {
height: '4cm',
label: {
text: 'Johann Wolfgang von Goethe, 1749-1832, deutscher Dichter, Naturforscher',
font: { align: 'center' }
}
}
};
cordova.plugins.printer.print("Es flattert um die Quelle\nDie wechselnde Libelle,...", options);
```
The result will look like this for iOS:
![ttt](https://github.com/katzer/cordova-plugin-printer/blob/example/images/sample.png)
## Installation ## Installation
The plugin can be installed via [CLI][CLI] and is publicly available on [NPM][npm].
Execute from the projects root folder: Execute from the projects root folder:
$ cordova plugin add cordova-plugin-printer $ cordova plugin add cordova-plugin-printer
@ -233,6 +197,7 @@ Then execute:
cordova build cordova build
## Contributing ## Contributing
1. Fork it 1. Fork it
@ -241,6 +206,7 @@ Then execute:
4. Push to the branch (`git push origin my-new-feature`) 4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request 5. Create new Pull Request
## License ## License
This software is released under the [Apache 2.0 License][apache2_license]. This software is released under the [Apache 2.0 License][apache2_license].
@ -251,5 +217,7 @@ Made with :yum: from Leipzig
[cordova]: https://cordova.apache.org [cordova]: https://cordova.apache.org
[CLI]: http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface
[npm]: https://www.npmjs.com/package/cordova-plugin-printer
[apache2_license]: http://opensource.org/licenses/Apache-2.0 [apache2_license]: http://opensource.org/licenses/Apache-2.0
[appplant]: www.appplant.de [appplant]: www.appplant.de

5
package-lock.json generated
View File

@ -1,5 +0,0 @@
{
"name": "cordova-plugin-printer",
"version": "0.8.0",
"lockfileVersion": 1
}

View File

@ -1,14 +1,13 @@
{ {
"name": "cordova-plugin-printer", "name": "cordova-plugin-printer",
"version": "0.8.0", "version": "0.7.3",
"description": "Prints HTML documents", "description": "Prints HTML documents",
"cordova": { "cordova": {
"id": "cordova-plugin-printer", "id": "cordova-plugin-printer",
"platforms": [ "platforms": [
"ios", "ios",
"android", "android",
"windows", "windows"
"browser"
] ]
}, },
"repository": { "repository": {
@ -22,8 +21,7 @@
"ecosystem:cordova", "ecosystem:cordova",
"cordova-ios", "cordova-ios",
"cordova-android", "cordova-android",
"cordova-windows", "cordova-windows"
"cordova-browser"
], ],
"engines": [ "engines": [
{ {
@ -44,6 +42,5 @@
"bugs": { "bugs": {
"url": "https://github.com/katzer/cordova-plugin-printer/issues" "url": "https://github.com/katzer/cordova-plugin-printer/issues"
}, },
"homepage": "https://github.com/katzer/cordova-plugin-printer#readme", "homepage": "https://github.com/katzer/cordova-plugin-printer#readme"
"dependencies": {}
} }

View File

@ -24,7 +24,7 @@
<plugin id="cordova-plugin-printer" <plugin id="cordova-plugin-printer"
xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
version="0.8.0"> version="0.8.0.alpha">
<name>Printer</name> <name>Printer</name>

View File

@ -28,8 +28,8 @@ import android.print.PageRange;
import android.print.PrintAttributes; import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter; import android.print.PrintDocumentAdapter;
import android.print.PrintDocumentInfo; import android.print.PrintDocumentInfo;
import androidx.annotation.NonNull; import android.support.annotation.NonNull;
import androidx.print.PrintHelper; import android.support.v4.print.PrintHelper;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -24,8 +24,8 @@ package de.appplant.cordova.plugin.printer;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import androidx.annotation.NonNull; import android.support.annotation.NonNull;
import androidx.annotation.Nullable; import android.support.annotation.Nullable;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -26,8 +26,8 @@ import android.content.res.AssetManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import androidx.annotation.NonNull; import android.support.annotation.NonNull;
import androidx.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Base64; import android.util.Base64;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;

View File

@ -27,9 +27,9 @@ import android.graphics.Bitmap;
import android.print.PrintAttributes; import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter; import android.print.PrintDocumentAdapter;
import android.print.PrintJob; import android.print.PrintJob;
import androidx.annotation.NonNull; import android.support.annotation.NonNull;
import androidx.annotation.Nullable; import android.support.annotation.Nullable;
import androidx.print.PrintHelper; import android.support.v4.print.PrintHelper;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;

View File

@ -22,8 +22,8 @@
package de.appplant.cordova.plugin.printer; package de.appplant.cordova.plugin.printer;
import android.print.PrintAttributes; import android.print.PrintAttributes;
import androidx.annotation.NonNull; import android.support.annotation.NonNull;
import androidx.print.PrintHelper; import android.support.v4.print.PrintHelper;
import org.json.JSONObject; import org.json.JSONObject;
@ -35,10 +35,10 @@ import static android.print.PrintAttributes.Margins.NO_MARGINS;
import static android.print.PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE; import static android.print.PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE;
import static android.print.PrintAttributes.MediaSize.UNKNOWN_PORTRAIT; import static android.print.PrintAttributes.MediaSize.UNKNOWN_PORTRAIT;
import static android.print.PrintDocumentInfo.PAGE_COUNT_UNKNOWN; import static android.print.PrintDocumentInfo.PAGE_COUNT_UNKNOWN;
import static androidx.print.PrintHelper.ORIENTATION_LANDSCAPE; import static android.support.v4.print.PrintHelper.ORIENTATION_LANDSCAPE;
import static androidx.print.PrintHelper.ORIENTATION_PORTRAIT; import static android.support.v4.print.PrintHelper.ORIENTATION_PORTRAIT;
import static androidx.print.PrintHelper.SCALE_MODE_FILL; import static android.support.v4.print.PrintHelper.SCALE_MODE_FILL;
import static androidx.print.PrintHelper.SCALE_MODE_FIT; import static android.support.v4.print.PrintHelper.SCALE_MODE_FIT;
/** /**
* Wrapper for the print job settings. * Wrapper for the print job settings.

View File

@ -27,8 +27,8 @@ import android.os.ParcelFileDescriptor;
import android.print.PageRange; import android.print.PageRange;
import android.print.PrintAttributes; import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter; import android.print.PrintDocumentAdapter;
import androidx.annotation.NonNull; import android.support.annotation.NonNull;
import androidx.print.PrintHelper; import android.support.v4.print.PrintHelper;
/** /**
* Simple delegate class to have access to the onFinish method. * Simple delegate class to have access to the onFinish method.

View File

@ -21,8 +21,8 @@
package de.appplant.cordova.plugin.printer; package de.appplant.cordova.plugin.printer;
import androidx.annotation.NonNull; import android.support.annotation.NonNull;
import androidx.annotation.Nullable; import android.support.annotation.Nullable;
import android.webkit.WebView; import android.webkit.WebView;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;

View File

@ -121,7 +121,7 @@
APPPrinterPaper* paperSpec = [[APPPrinterPaper alloc] APPPrinterPaper* paperSpec = [[APPPrinterPaper alloc]
initWithDictionary:ctrl.settings[@"paper"]]; initWithDictionary:ctrl.settings[@"paper"]];
return (paperSpec.length)?paperSpec.length:paper.paperSize.height; return paperSpec.length || paper.paperSize.height;
} }
#pragma mark - #pragma mark -

View File

@ -47,7 +47,7 @@
*/ */
+ (BOOL) canPrintURL:(nullable NSString *)url + (BOOL) canPrintURL:(nullable NSString *)url
{ {
if ([url isEqual:[NSNull null]] || ![NSURL URLWithString:url].scheme) if (![NSURL URLWithString:url].scheme)
{ {
return UIPrintInteractionController.isPrintingAvailable; return UIPrintInteractionController.isPrintingAvailable;
} }

View File

@ -58,11 +58,10 @@
withSettings:(NSDictionary *)settings withSettings:(NSDictionary *)settings
{ {
id layout = [[self alloc] initWithDictionary:settings]; id layout = [[self alloc] initWithDictionary:settings];
SEL setFont = NSSelectorFromString(@"font");
[layout configureFormatter:formatter]; [layout configureFormatter:formatter];
if (settings && [formatter respondsToSelector:setFont]) if (settings && ![formatter isKindOfClass:UIMarkupTextPrintFormatter.class])
{ {
[layout configureTextFormatter:(UISimpleTextPrintFormatter *)formatter [layout configureTextFormatter:(UISimpleTextPrintFormatter *)formatter
withSettings:settings]; withSettings:settings];

View File

@ -199,7 +199,7 @@ exports.print = function (content, options, callback, scope)
var fn = this._createCallbackFn(callback, scope), var fn = this._createCallbackFn(callback, scope),
params = this._mergeWithDefaults(options || {}); params = this._mergeWithDefaults(options || {});
exec(fn, null, 'Printer', 'print', [content || '', params]); exec(fn, null, 'Printer', 'print', [content, params]);
}; };
/** /**
@ -268,6 +268,12 @@ exports._mergeWithDefaults = function (options)
} }
} }
options.meta =
{
plugin: 'cordova-plugin-printer',
version: '0.8.0-beta'
};
return options; return options;
}; };