├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── demo ├── .gitignore ├── App_Resources │ ├── Android │ │ ├── app.gradle │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ └── res │ │ │ ├── drawable-hdpi │ │ │ ├── background.png │ │ │ ├── icon.png │ │ │ └── logo.png │ │ │ ├── drawable-ldpi │ │ │ ├── background.png │ │ │ ├── icon.png │ │ │ └── logo.png │ │ │ ├── drawable-mdpi │ │ │ ├── background.png │ │ │ ├── icon.png │ │ │ └── logo.png │ │ │ ├── drawable-nodpi │ │ │ └── splash_screen.xml │ │ │ ├── drawable-xhdpi │ │ │ ├── background.png │ │ │ ├── icon.png │ │ │ └── logo.png │ │ │ ├── drawable-xxhdpi │ │ │ ├── background.png │ │ │ ├── icon.png │ │ │ └── logo.png │ │ │ ├── drawable-xxxhdpi │ │ │ ├── background.png │ │ │ ├── icon.png │ │ │ └── logo.png │ │ │ ├── values-v21 │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ │ ├── values-v29 │ │ │ └── styles.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ └── styles.xml │ └── iOS │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── icon-1024.png │ │ │ ├── icon-20.png │ │ │ ├── icon-20@2x.png │ │ │ ├── icon-20@3x.png │ │ │ ├── icon-29.png │ │ │ ├── icon-29@2x.png │ │ │ ├── icon-29@3x.png │ │ │ ├── icon-40.png │ │ │ ├── icon-40@2x.png │ │ │ ├── icon-40@3x.png │ │ │ ├── icon-60@2x.png │ │ │ ├── icon-60@3x.png │ │ │ ├── icon-76.png │ │ │ ├── icon-76@2x.png │ │ │ └── icon-83.5@2x.png │ │ ├── Contents.json │ │ ├── LaunchScreen.AspectFill.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchScreen-AspectFill.png │ │ │ ├── LaunchScreen-AspectFill@2x.png │ │ │ └── LaunchScreen-AspectFill@3x.png │ │ └── LaunchScreen.Center.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchScreen-Center.png │ │ │ ├── LaunchScreen-Center@2x.png │ │ │ └── LaunchScreen-Center@3x.png │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ └── build.xcconfig ├── nativescript.config.ts ├── package.json ├── references.d.ts ├── src │ ├── app-root.xml │ ├── app.css │ ├── assets │ │ ├── pdf-test.pdf │ │ └── printer.png │ ├── data.json │ ├── main-page.ts │ ├── main-page.xml │ ├── main-view-model.ts │ └── main.ts ├── tsconfig.json └── webpack.config.js ├── publish ├── pack.sh ├── package.json └── publish.sh ├── screenshots ├── android │ ├── android-printer-options.png │ └── android-select-printer.png └── ios │ ├── ios-printing-in-progress.png │ └── ios-select-printer.png ├── src ├── .npmignore ├── index.d.ts ├── package.json ├── printer.android.ts ├── printer.common.ts ├── printer.ios.ts ├── references.d.ts └── tsconfig.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .idea 3 | .DS_Store 4 | *.esm.json 5 | *.js 6 | *.js.map 7 | *.log 8 | package-lock.json 9 | src/*.d.ts 10 | !src/index.d.ts 11 | !src/references.d.ts 12 | !src/scripts/*.js 13 | !demo/karma.conf.js 14 | !demo/app/tests/*.js 15 | demo/*.d.ts 16 | !demo/references.d.ts 17 | demo/lib 18 | demo/platforms 19 | node_modules 20 | publish/src 21 | publish/package 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | include: 3 | - stage: "Lint" 4 | language: node_js 5 | os: linux 6 | node_js: "10" 7 | script: cd src && npm run ci.tslint 8 | - stage: "WebPack, Build" 9 | os: osx 10 | env: 11 | - WebPack="iOS" 12 | osx_image: xcode10.2 13 | language: node_js 14 | node_js: "10" 15 | jdk: oraclejdk8 16 | before_script: pod repo update 17 | script: cd demo && npm run build.plugin && npm i && tns build ios --bundle --env.uglify 18 | - language: android 19 | env: 20 | - BuildAndroid="28" 21 | os: linux 22 | dist: trusty 23 | jdk: oraclejdk8 24 | before_install: nvm install 10 25 | script: 26 | - cd src && npm i && npm run tsc && cd ../demo && tns build android 27 | - os: osx 28 | osx_image: xcode10.2 29 | language: node_js 30 | node_js: "10" 31 | jdk: oraclejdk8 32 | before_script: pod repo update 33 | script: 34 | - cd src && npm i && npm run tsc && cd ../demo && tns build ios 35 | 36 | android: 37 | components: 38 | - tools 39 | - platform-tools 40 | - build-tools-28.0.3 41 | - android-28 42 | - extra-android-m2repository 43 | - sys-img-armeabi-v7a-android-21 44 | 45 | before_install: 46 | - sudo pip install --upgrade pip 47 | - sudo pip install six 48 | 49 | install: 50 | - echo no | npm install -g nativescript 51 | - tns usage-reporting disable 52 | - tns error-reporting disable -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NativeScript Printer plugin 2 | 3 | [![Build Status][build-status]][build-url] 4 | [![NPM version][npm-image]][npm-url] 5 | [![Downloads][downloads-image]][npm-url] 6 | [![Twitter Follow][twitter-image]][twitter-url] 7 | 8 | [build-status]:https://travis-ci.org/EddyVerbruggen/nativescript-printer.svg?branch=master 9 | [build-url]:https://travis-ci.org/EddyVerbruggen/nativescript-printer 10 | [npm-image]:http://img.shields.io/npm/v/nativescript-printer.svg 11 | [npm-url]:https://npmjs.org/package/nativescript-printer 12 | [downloads-image]:http://img.shields.io/npm/dm/nativescript-printer.svg 13 | [twitter-image]:https://img.shields.io/twitter/follow/eddyverbruggen.svg?style=social&label=Follow%20me 14 | [twitter-url]:https://twitter.com/eddyverbruggen 15 | 16 | > Think about the environment before printing! 17 | 18 | ## Installation 19 | From the command prompt go to your app's root folder and execute: 20 | 21 | ``` 22 | tns plugin add nativescript-printer 23 | ``` 24 | 25 | ## Demo app 26 | Want to dive in quickly? Check out [the demo](https://github.com/EddyVerbruggen/nativescript-printer/tree/master/demo)! Otherwise, continue reading. 27 | 28 | Run the demo app from the root of the project: `npm run demo.ios` or `npm run demo.android`. 29 | 30 | ### Android screenshots 31 |      32 | 33 | ### iOS screenshots 34 |      35 | 36 | ## API 37 | 38 | ### `isSupported` 39 | Not all devices support printing, so it makes sense to check the device capabilties beforehand. 40 | 41 | ##### TypeScript 42 | ```typescript 43 | // require the plugin 44 | import {Printer} from "nativescript-printer"; 45 | 46 | // instantiate the plugin 47 | let printer = new Printer(); 48 | 49 | printer.isSupported().then((supported) => { 50 | alert(supported ? "Yep!" : "Nope :'("); 51 | }, (error) => { 52 | alert("Error: " + error); 53 | }); 54 | ``` 55 | 56 | ### `printImage` 57 | 58 | ##### TypeScript 59 | ```typescript 60 | // let's load an image that we can print. In this case from a local folder. 61 | let fs = require("file-system"); 62 | let appPath = fs.knownFolders.currentApp().path; 63 | let imgPath = appPath + "/res/printer.png"; 64 | let imgSrc = new ImageSource(); 65 | imgSrc.loadFromFile(imgPath); 66 | 67 | printer.printImage({ 68 | imageSrc: imgSrc 69 | }).then((success) => { 70 | alert(success ? "Printed!" : "Not printed"); 71 | }, (error) => { 72 | alert("Error: " + error); 73 | }); 74 | ``` 75 | 76 | ### `printPDF` 77 | 78 | ##### TypeScript 79 | ```typescript 80 | import { knownFolders } from "tns-core-modules/file-system/file-system"; 81 | 82 | printer.printPDF({ 83 | pdfPath: knownFolders.currentApp().path + "/pdf-test.pdf" 84 | }).then((success) => { 85 | alert(success ? "Printed!" : "Not printed"); 86 | }, (error) => { 87 | alert("Error: " + error); 88 | }); 89 | ``` 90 | 91 | ### `printScreen` 92 | Prints the current screen contents. Anything off screen will not be printed. 93 | 94 | ##### TypeScript 95 | ```typescript 96 | printer.printScreen().then((success) => { 97 | alert(success ? "Printed!" : "Not printed"); 98 | }, (error) => { 99 | alert("Error: " + error); 100 | }); 101 | ``` 102 | 103 | You can also print a specific portion of the screen, which also enables you to print 104 | views that are larger than the viewport. This is an example of a non-Angular NativeScript app: 105 | 106 | **Note** 107 | If the view is either of the following depending on the size of it's contents it would break into multiple pages. 108 | 109 | `Label | TextView | HtmlView | WebView` 110 | 111 | ```xml 112 | 113 | 115 | 116 |