Compare commits

..

11 Commits

Author SHA1 Message Date
9044cbe1d4 feat: cordova10 2023-08-07 09:45:53 +08:00
Maubic Consultoría Tecnológica
672d804518 Fix wrong value returned from cutLengthForPaper (#213) 2019-05-31 11:10:15 +02:00
Sebastián Katzer
7a3279c11d Add missing margin:false option 2019-03-07 10:46:18 +01:00
Sebastián Katzer
bc234c3cd3 Release v0.8.0 2019-03-01 21:17:51 +01:00
Sebastián Katzer
912eb5c0e6 Merge branch 'master' of github.com:katzer/cordova-plugin-printer 2019-03-01 20:58:30 +01:00
Sebastián Katzer
f3bac4bd3f Update README.md 2019-03-01 20:49:08 +01:00
Sebastián Katzer
829a600f28 Remove meta attributes 2019-03-01 20:00:23 +01:00
Sebastián Katzer
56dba89008 Set content to empty string if null or undefined 2019-03-01 19:58:15 +01:00
Sebastián Katzer
9cbb6b8f9a Fix potential unknown selector exception 2019-03-01 17:48:52 +01:00
Sebastián Katzer
9362e4c341 Fix potential NPE 2019-03-01 12:06:16 +01:00
SimasTuzinas
9a6b4e8dbb Windows crash fix (#175)
* Fixing crash on UWP app

Adding try catch block for numberOfCopies property

* adding copies property in nubmerOfCopies
2019-01-30 12:16:36 +01:00
16 changed files with 89 additions and 47 deletions

View File

@ -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)

View File

@ -5,9 +5,13 @@
# 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")
<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:
![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
@ -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
View File

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

View File

@ -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": {}
} }

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.alpha"> version="0.8.0">
<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 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;

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 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;

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 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;

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 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;

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 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.

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 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.

View File

@ -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;

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 || paper.paperSize.height; return (paperSpec.length)?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 (![NSURL URLWithString:url].scheme) if ([url isEqual:[NSNull null]] || ![NSURL URLWithString:url].scheme)
{ {
return UIPrintInteractionController.isPrintingAvailable; return UIPrintInteractionController.isPrintingAvailable;
} }

View File

@ -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];

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,12 +268,6 @@ exports._mergeWithDefaults = function (options)
} }
} }
options.meta =
{
plugin: 'cordova-plugin-printer',
version: '0.8.0-beta'
};
return options; return options;
}; };