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
|
||||
#### 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)
|
||||
- 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")
|
||||
|
||||
<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
|
||||
|
||||
@ -30,7 +34,6 @@ Plugin for [Cordova][cordova] to print documents or photos from iOS, Android and
|
||||
- Windows 10 UWP
|
||||
- Browser
|
||||
|
||||
|
||||
## Basics
|
||||
|
||||
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 |
|
||||
| printer | The network URL to the printer. | String | 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 |
|
||||
| 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 |
|
||||
@ -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.
|
||||
|
||||
|
||||
## Printable Document Types
|
||||
|
||||
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);
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||
The plugin can be installed via [CLI][CLI] and is publicly available on [NPM][npm].
|
||||
|
||||
Execute from the projects root folder:
|
||||
|
||||
$ cordova plugin add cordova-plugin-printer
|
||||
@ -197,7 +233,6 @@ Then execute:
|
||||
|
||||
cordova build
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it
|
||||
@ -206,7 +241,6 @@ Then execute:
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create new Pull Request
|
||||
|
||||
|
||||
## 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
|
||||
[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
|
||||
[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",
|
||||
"version": "0.7.3",
|
||||
"version": "0.8.0",
|
||||
"description": "Prints HTML documents",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-printer",
|
||||
"platforms": [
|
||||
"ios",
|
||||
"android",
|
||||
"windows"
|
||||
"windows",
|
||||
"browser"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
@ -21,7 +22,8 @@
|
||||
"ecosystem:cordova",
|
||||
"cordova-ios",
|
||||
"cordova-android",
|
||||
"cordova-windows"
|
||||
"cordova-windows",
|
||||
"cordova-browser"
|
||||
],
|
||||
"engines": [
|
||||
{
|
||||
@ -42,5 +44,6 @@
|
||||
"bugs": {
|
||||
"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"
|
||||
xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
version="0.8.0.alpha">
|
||||
version="0.8.0">
|
||||
|
||||
<name>Printer</name>
|
||||
|
||||
|
@ -28,8 +28,8 @@ import android.print.PageRange;
|
||||
import android.print.PrintAttributes;
|
||||
import android.print.PrintDocumentAdapter;
|
||||
import android.print.PrintDocumentInfo;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.print.PrintHelper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.print.PrintHelper;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -24,8 +24,8 @@ package de.appplant.cordova.plugin.printer;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -26,8 +26,8 @@ import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Base64;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -27,9 +27,9 @@ import android.graphics.Bitmap;
|
||||
import android.print.PrintAttributes;
|
||||
import android.print.PrintDocumentAdapter;
|
||||
import android.print.PrintJob;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.print.PrintHelper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.print.PrintHelper;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
@ -22,8 +22,8 @@
|
||||
package de.appplant.cordova.plugin.printer;
|
||||
|
||||
import android.print.PrintAttributes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.print.PrintHelper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.print.PrintHelper;
|
||||
|
||||
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_PORTRAIT;
|
||||
import static android.print.PrintDocumentInfo.PAGE_COUNT_UNKNOWN;
|
||||
import static android.support.v4.print.PrintHelper.ORIENTATION_LANDSCAPE;
|
||||
import static android.support.v4.print.PrintHelper.ORIENTATION_PORTRAIT;
|
||||
import static android.support.v4.print.PrintHelper.SCALE_MODE_FILL;
|
||||
import static android.support.v4.print.PrintHelper.SCALE_MODE_FIT;
|
||||
import static androidx.print.PrintHelper.ORIENTATION_LANDSCAPE;
|
||||
import static androidx.print.PrintHelper.ORIENTATION_PORTRAIT;
|
||||
import static androidx.print.PrintHelper.SCALE_MODE_FILL;
|
||||
import static androidx.print.PrintHelper.SCALE_MODE_FIT;
|
||||
|
||||
/**
|
||||
* Wrapper for the print job settings.
|
||||
|
@ -27,8 +27,8 @@ import android.os.ParcelFileDescriptor;
|
||||
import android.print.PageRange;
|
||||
import android.print.PrintAttributes;
|
||||
import android.print.PrintDocumentAdapter;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.print.PrintHelper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.print.PrintHelper;
|
||||
|
||||
/**
|
||||
* Simple delegate class to have access to the onFinish method.
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
package de.appplant.cordova.plugin.printer;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
|
@ -121,7 +121,7 @@
|
||||
APPPrinterPaper* paperSpec = [[APPPrinterPaper alloc]
|
||||
initWithDictionary:ctrl.settings[@"paper"]];
|
||||
|
||||
return paperSpec.length || paper.paperSize.height;
|
||||
return (paperSpec.length)?paperSpec.length:paper.paperSize.height;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
@ -47,7 +47,7 @@
|
||||
*/
|
||||
+ (BOOL) canPrintURL:(nullable NSString *)url
|
||||
{
|
||||
if (![NSURL URLWithString:url].scheme)
|
||||
if ([url isEqual:[NSNull null]] || ![NSURL URLWithString:url].scheme)
|
||||
{
|
||||
return UIPrintInteractionController.isPrintingAvailable;
|
||||
}
|
||||
|
@ -57,11 +57,12 @@
|
||||
+ (UIPrintFormatter *) configureFormatter:(UIPrintFormatter *)formatter
|
||||
withSettings:(NSDictionary *)settings
|
||||
{
|
||||
id layout = [[self alloc] initWithDictionary:settings];
|
||||
id layout = [[self alloc] initWithDictionary:settings];
|
||||
SEL setFont = NSSelectorFromString(@"font");
|
||||
|
||||
[layout configureFormatter:formatter];
|
||||
|
||||
if (settings && ![formatter isKindOfClass:UIMarkupTextPrintFormatter.class])
|
||||
if (settings && [formatter respondsToSelector:setFont])
|
||||
{
|
||||
[layout configureTextFormatter:(UISimpleTextPrintFormatter *)formatter
|
||||
withSettings:settings];
|
||||
|
@ -199,7 +199,7 @@ exports.print = function (content, options, callback, scope)
|
||||
var fn = this._createCallbackFn(callback, scope),
|
||||
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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user