Compare commits
11 Commits
02d54a063f
...
9044cbe1d4
Author | SHA1 | Date | |
---|---|---|---|
9044cbe1d4 | |||
|
672d804518 | ||
|
7a3279c11d | ||
|
bc234c3cd3 | ||
|
912eb5c0e6 | ||
|
f3bac4bd3f | ||
|
829a600f28 | ||
|
56dba89008 | ||
|
9cbb6b8f9a | ||
|
9362e4c341 | ||
|
9a6b4e8dbb |
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,6 +1,13 @@
|
|||||||
## ChangeLog
|
## ChangeLog
|
||||||
#### Version 0.7.4 (not yet released)
|
|
||||||
- Fix broken _check_ and _pick_ on Android N and above
|
#### Version 0.8.0 (01.03.2019)
|
||||||
|
- 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)
|
||||||
|
52
README.md
52
README.md
@ -5,9 +5,13 @@
|
|||||||
|
|
||||||
# Cordova Print Plugin <br> [](http://badge.fury.io/js/cordova-plugin-printer) [](https://opensource.org/licenses/Apache-2.0) [](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> [](http://badge.fury.io/js/cordova-plugin-printer) [](https://opensource.org/licenses/Apache-2.0) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=L3HKQCD9UA35A "Donate once-off to this project using Paypal")
|
||||||
|
|
||||||
<img width="280px" align="right" hspace="20" vspace="10" src="https://github.com/katzer/cordova-plugin-printer/blob/example/images/print-ios.png">
|
Plugin for [Cordova][cordova] to print documents, photos, HTML and plain text from iOS, Android and Windows Universal apps.
|
||||||
|
|
||||||
Plugin for [Cordova][cordova] to print documents or photos from iOS, Android and Windows Universal apps.
|
```js
|
||||||
|
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
|
||||||
|
|
||||||
@ -30,7 +34,6 @@ Plugin for [Cordova][cordova] to print documents or photos from iOS, Android and
|
|||||||
- 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.
|
||||||
@ -101,6 +104,7 @@ 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 |
|
||||||
@ -149,7 +153,6 @@ 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.
|
||||||
@ -172,11 +175,44 @@ 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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## 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
|
||||||
@ -197,7 +233,6 @@ Then execute:
|
|||||||
|
|
||||||
cordova build
|
cordova build
|
||||||
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
1. Fork it
|
1. Fork it
|
||||||
@ -206,7 +241,6 @@ 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].
|
||||||
@ -217,7 +251,5 @@ 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
Normal file
5
package-lock.json
generated
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "cordova-plugin-printer",
|
||||||
|
"version": "0.8.0",
|
||||||
|
"lockfileVersion": 1
|
||||||
|
}
|
11
package.json
11
package.json
@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "cordova-plugin-printer",
|
"name": "cordova-plugin-printer",
|
||||||
"version": "0.7.3",
|
"version": "0.8.0",
|
||||||
"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": {
|
||||||
@ -21,7 +22,8 @@
|
|||||||
"ecosystem:cordova",
|
"ecosystem:cordova",
|
||||||
"cordova-ios",
|
"cordova-ios",
|
||||||
"cordova-android",
|
"cordova-android",
|
||||||
"cordova-windows"
|
"cordova-windows",
|
||||||
|
"cordova-browser"
|
||||||
],
|
],
|
||||||
"engines": [
|
"engines": [
|
||||||
{
|
{
|
||||||
@ -42,5 +44,6 @@
|
|||||||
"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": {}
|
||||||
}
|
}
|
||||||
|
@ -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.alpha">
|
version="0.8.0">
|
||||||
|
|
||||||
<name>Printer</name>
|
<name>Printer</name>
|
||||||
|
|
||||||
|
@ -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 android.support.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import android.support.v4.print.PrintHelper;
|
import androidx.print.PrintHelper;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -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 android.support.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -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 android.support.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
@ -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 android.support.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import android.support.v4.print.PrintHelper;
|
import androidx.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;
|
||||||
|
@ -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 android.support.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import android.support.v4.print.PrintHelper;
|
import androidx.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 android.support.v4.print.PrintHelper.ORIENTATION_LANDSCAPE;
|
import static androidx.print.PrintHelper.ORIENTATION_LANDSCAPE;
|
||||||
import static android.support.v4.print.PrintHelper.ORIENTATION_PORTRAIT;
|
import static androidx.print.PrintHelper.ORIENTATION_PORTRAIT;
|
||||||
import static android.support.v4.print.PrintHelper.SCALE_MODE_FILL;
|
import static androidx.print.PrintHelper.SCALE_MODE_FILL;
|
||||||
import static android.support.v4.print.PrintHelper.SCALE_MODE_FIT;
|
import static androidx.print.PrintHelper.SCALE_MODE_FIT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the print job settings.
|
* Wrapper for the print job settings.
|
||||||
|
@ -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 android.support.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import android.support.v4.print.PrintHelper;
|
import androidx.print.PrintHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple delegate class to have access to the onFinish method.
|
* Simple delegate class to have access to the onFinish method.
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
package de.appplant.cordova.plugin.printer;
|
package de.appplant.cordova.plugin.printer;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
import org.apache.cordova.CallbackContext;
|
import org.apache.cordova.CallbackContext;
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
APPPrinterPaper* paperSpec = [[APPPrinterPaper alloc]
|
APPPrinterPaper* paperSpec = [[APPPrinterPaper alloc]
|
||||||
initWithDictionary:ctrl.settings[@"paper"]];
|
initWithDictionary:ctrl.settings[@"paper"]];
|
||||||
|
|
||||||
return paperSpec.length || paper.paperSize.height;
|
return (paperSpec.length)?paperSpec.length:paper.paperSize.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
*/
|
*/
|
||||||
+ (BOOL) canPrintURL:(nullable NSString *)url
|
+ (BOOL) canPrintURL:(nullable NSString *)url
|
||||||
{
|
{
|
||||||
if (![NSURL URLWithString:url].scheme)
|
if ([url isEqual:[NSNull null]] || ![NSURL URLWithString:url].scheme)
|
||||||
{
|
{
|
||||||
return UIPrintInteractionController.isPrintingAvailable;
|
return UIPrintInteractionController.isPrintingAvailable;
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,11 @@
|
|||||||
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 isKindOfClass:UIMarkupTextPrintFormatter.class])
|
if (settings && [formatter respondsToSelector:setFont])
|
||||||
{
|
{
|
||||||
[layout configureTextFormatter:(UISimpleTextPrintFormatter *)formatter
|
[layout configureTextFormatter:(UISimpleTextPrintFormatter *)formatter
|
||||||
withSettings:settings];
|
withSettings:settings];
|
||||||
|
@ -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,12 +268,6 @@ exports._mergeWithDefaults = function (options)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
options.meta =
|
|
||||||
{
|
|
||||||
plugin: 'cordova-plugin-printer',
|
|
||||||
version: '0.8.0-beta'
|
|
||||||
};
|
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user