Giter VIP home page Giter VIP logo

react-native-print's Introduction

react-native-print

Print documents using React Native.

Installation

Run npm install react-native-print --save

Add it to your project

Automatic

Run react-native link

Manual

iOS

  1. Open your project in XCode, right click on Libraries and select Add Files to "Your Project Name.
  2. Choose the file node_modules/react-native-print/RNPrint.xcodeproj
  3. Go to Project Manager tab and click on your project's name. Select the name of the target and click on Build Phases
  4. Add libRNPrint.a to Link Binary With Libraries (Screenshot).

Android

  • Edit android/settings.gradle to included
include ':react-native-print'
project(':react-native-print').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-print/android')
  • Edit android/app/build.gradle file to include
dependencies {
  ....
  compile project(':react-native-print')

}
  • Edit MainApplication.java to include
// import the package
import com.christopherdro.RNPrint.RNPrintPackage;

// include package
new MainReactPackage(),
new RNPrintPackage(),

Windows

  1. In windows/myapp.sln add the RNPrint project to your solution:

    • Open the solution in Visual Studio 2019
    • Right-click Solution icon in Solution Explorer > Add > Existing Project
    • Select node_modules\react-native-print\windows\RNPrint\RNPrint.vcxproj
  2. In windows/myapp/myapp.vcxproj ad a reference to RNPrint to your main application project. From Visual Studio 2019:

    • Right-click main application project > Add > Reference...
    • Check RNPrint from Solution Projects.
  3. In pch.h add #include "winrt/RNPrint.h".

  4. In app.cpp add PackageProviders().Append(winrt::RNPrint::ReactPackageProvider()); before InitializeComponent();.

Windows print canvas

On Windows, react-native-print needs an element in the visual tree to add the printable pages to. It will look for a XAML Canvas named RNPrintCanvas and use it. This needs to be added to the XAML tree of the screens where react-native-print is used.

As an example, in windows/myapp/MainPage.xaml from the react-native-windows app template this can be done by adding a XAML Grid with an invisible Canvas alongside the ReactRootView. Change windows/myapp/MainPage.xaml from:

<Page
  ...
  >
  <react:ReactRootView
    x:Name="ReactRootView"
    ...
  />
</Page>

to

<Page
  ...
  >
  <Grid>
    <Canvas x:Name="RNPrintCanvas" Opacity="0" />
    <react:ReactRootView
      x:Name="ReactRootView"
      ...
    />
  </Grid>
</Page>

Usage

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  Button,
  StyleSheet,
  NativeModules,
  Platform,
  Text,
  View
} from 'react-native';


import RNHTMLtoPDF from 'react-native-html-to-pdf';
import RNPrint from 'react-native-print';

export default class RNPrintExample extends Component {
  state = {
    selectedPrinter: null
  }

  // @NOTE iOS Only
  selectPrinter = async () => {
    const selectedPrinter = await RNPrint.selectPrinter({ x: 100, y: 100 })
    this.setState({ selectedPrinter })
  }

  // @NOTE iOS Only
  silentPrint = async () => {
    if (!this.state.selectedPrinter) {
      alert('Must Select Printer First')
    }

    const jobName = await RNPrint.print({
      printerURL: this.state.selectedPrinter.url,
      html: '<h1>Silent Print</h1>'
    })

  }

  async printHTML() {
    await RNPrint.print({
      html: '<h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3>'
    })
  }

  async printPDF() {
    const results = await RNHTMLtoPDF.convert({
      html: '<h1>Custom converted PDF Document</h1>',
      fileName: 'test',
      base64: true,
    })

    await RNPrint.print({ filePath: results.filePath })
  }

  async printRemotePDF() {
    await RNPrint.print({ filePath: 'https://graduateland.com/api/v2/users/jesper/cv' })
  }

  customOptions = () => {
    return (
      <View>
        {this.state.selectedPrinter &&
          <View>
            <Text>{`Selected Printer Name: ${this.state.selectedPrinter.name}`}</Text>
            <Text>{`Selected Printer URI: ${this.state.selectedPrinter.url}`}</Text>
          </View>
        }
      <Button onPress={this.selectPrinter} title="Select Printer" />
      <Button onPress={this.silentPrint} title="Silent Print" />
    </View>

    )
  }

  render() {
    return (
      <View style={styles.container}>
        {Platform.OS === 'ios' && this.customOptions()}
        <Button onPress={this.printHTML} title="Print HTML" />
        <Button onPress={this.printPDF} title="Print PDF" />
        <Button onPress={this.printRemotePDF} title="Print Remote PDF" />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
});

Methods

print(options: Object)

Param Type Note
html string iOS and Android Only: HTML string to print
filePath string Local or remote file url NOTE: iOS only supports https protocols for remote
printerURL string iOS Only: URL returned from selectPrinterMethod()
isLandscape bool Landscape print; default value is false
jobName string iOS and Android Only: Name of printing job; default value is "Document"
baseUrl string Android Only: Used to resolve relative links in the HTML. Also used for the origin header when applying same origin policy (CORS). Reference Android WebView Docs

selectPrinter(options: Object)

Param Type Note
x string iPad Only: The x position of the popup dialog
y string iPad Only: The y position of the popup dialog

react-native-print's People

Contributors

beaur avatar chmac avatar christopherdro avatar ddaeschler avatar dependabot[bot] avatar elgambet avatar everton-trajano avatar flipthibault avatar gingerbear avatar itinance avatar itsnohax avatar jaimecbernardo avatar johnybot avatar kevinresol avatar kfoxb avatar kroniac avatar liamjones avatar lorenzomilesi avatar magrinj avatar markgardner avatar mikeahirsch avatar muhammadowaiswarsi avatar nhayfield avatar nielsdb97 avatar r3nya avatar sam-n-johnston avatar subodhdahal avatar tatianakapos avatar vijaychouhan-rails avatar wootwoot1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-print's Issues

iPad not closing window when printing

iPad when you press print it doesn't close the window & return to the app. iPhone is working though.

Versions:
React Native: 0.58.4
React Native Print: 0.5.1
React Native Navigation: 2

RNPrint is undefined.

I just installed the module using:

npm install react-native-print --save

then ran:

react-native link

I copied the example to one of my screens in RN.

I get the following issue:

Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property 'selectPrinter' of undefined
TypeError: Cannot read property 'selectPrinter' of undefined
at ViewOrder._callee$ (blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:158370:76)
at tryCatch (blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:14084:19)
at Generator.invoke [as _invoke] (blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:14257:24)
at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:14127:23)
at tryCatch (blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:14084:19)
at invoke (blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:14160:22)
at blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:14188:13
at tryCallTwo (blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:13422:7)
at doResolve (blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:13586:15)
at new Promise (blob:http://localhost:8081/29d208a6-8ea9-4f98-8dec-3d931b4349f0:13445:5)

I console.log(RNPrint) and it is undefined.

Is it because i am running it in the simulator perhaps?

Print screen doesn't get past 'Preparing preview...'

When I've tried printing from a file path, I get the 'Preparing preview...' message on the print screen, but it never gets past that. I've tried both in an emulator and on a real device. Has anyone else seen this?

Blank Print Screen coming for first time

@christopherdro I am using the same code given in the example. I have a list of items, where user can print any list item data. But When I install the fresh app & click on print, the blank screen appears. I have checked that all the html data is coming, its not blank but on Print page no data appears.

When I click second time, it works.

Can you please let me know what is the issue at first time? The issue is with dynamic HMTL. Hardcoded HTML is working fine.

Callback works when print is cancelled

I tried writing a simple callback onto the end of the print job to create an alert when the print job is done however if I press cancel the alert still comes up. Is there some way to differentiate between someone pressing print or cancel?

My code is below for reference.

function PrintAlert() {
        const printAlert = AlertIOS.alert(
            alertName + "'s label is being printed now.",
            "Please go and check the printer."
        )
    }

async function PrintDocument() {
        let PrintSettings = {
            html: PrintLabelLayout(),
            fileName: 'PrintLabel',
            base64: false,
            height: 420,
            width: 595,
            padding: 0
        };

        try {
            const results = await RNHTMLtoPDF.convert(PrintSettings);
            const printJob = await RNPrint.print(results.filePath).then(() => {
                PrintAlert()
            });
        } catch (err) {
            console.log(err)
        }
    }

[ios] Need some feedback when filePath is invalid

On ios, when filePath is an invalid URL (e.g. one results in 404 http status code), ios will complain with an error like this (visible on xcode):

ERROR: attempting to display print options with no printing source (item/items/formatter/renderer) set

But there is nothing on JS side, as the promise never resolves/rejects
I wonder if anything can be done to capture that error and bring it back to JS.

Podspec file?

Hi,
I want to use this library with cocoapods with react native - is there a podspec file for it?
Thanks!

[Feature] Enable All Possible Options for the Chosen Printer

First of all I enjoy the ease of use of this library. What I'm still missing is the feature to print multiple copies for a file right out of the iOS option screen. I didn't find a way to enable that. I wanted to extend the library but I'm struggling to find the necessary docs for the objective C code.

Here are some more options I found using the built in iOS file viewer. I would love to have all the options also available for the printer when I'm using this library.

  • change amount of copies to print
  • black and white
  • double sided
  • Paper size
  • Punch
  • Staple

img_0380

UIViewController issue

Commented out this line to enable print options to pop up. Otherwise it fails to present it.

//printInteractionController.delegate = self;

Signing of RNPrintTests required?

I've integrated the library with npm install react-native-print --save && react-native link

Now when I try to publish a new beta, I get this error:

captura de pantalla 2018-07-19 a la s 16 02 14

Is it a mistake on my side? BTW, the build is launched with fastlane beta

UDPATE: As a workaround I've just deleted RNPrintTests target from the linked RNPrint.xcproj, but I don't think this is the best solution!

Silent printing for Android

Hi there,
First of all, thanks for this awesome module, well, currently I am facing an issue where I need to silently print some data directly to LAN or Bluetooth printer without getting that pop-up to select a printer first and then click on the print button.
Is there any way to make this work?
Please help :),

Thanks!

ANDROID Works in DEBUG but not in RELEASE

Is there anything additional required to make this plugin work in RELEASE? It seems to be working fine in DEBUG on ANDROID.

I ran the following:
react-native link
react-native run-android

Print Dialog is triggered.

When i ran the following:
react-native run-android --variant=release

Print Dialog is not triggered, No errors thrown.

undefined is not an object (evaluating '_reactNativePrint2.default.print')

I am running into an error with a detached RNCA app using Expokit in iOS.

This is the error I'm getting:
undefined is not an object (evaluating '_reactNativePrint2.default.print')

package.json:

{
  "name": "AppName",
  "version": "2.0.0",
  "private": true,
  "devDependencies": {
    "jest-expo": "25.0.0",
    "react-native-scripts": "1.8.1",
    "react-test-renderer": "16.0.0"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "node node_modules/jest/bin/jest.js --watch"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "expo": "^25.0.0",
    "react": "16.2.rea0",
    "react-font-face": "^0.2.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-25.0.0.tar.gz",
    "react-native-auto-height-image": "^1.0.0",
    "react-native-print": "^0.5.0",
    "react-native-storage": "^0.2.2",
    "react-navigation": "^1.0.0-beta.27"
  }
}

Here is what I did to get to this point:

  • Created an app using RNCA
  • Updated React, RN, and Expokit in order to fix some build issues
  • Installed react-native-print by running npm install --save react-native-print, and running react-native-link
  • Detached my app with exp detach
  • Went into the ios directory and ran pod install
  • Opened the xcworkspace file in Xcode
  • Clicked the build and run button

This installs the app on my iPad and allows me to test.

I have the following code in a component:

import RNPrint from 'react-native-print';

...

  handleClickPrint() {
    console.log('print');
    RNPrint.print({
      html: '<h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3>'
    });
  }

The use of RNPrint.print is causing the error.

I do find it odd that I need to have exp start running for the app to load. It's like it's not building a native app, but instead installing a standalone Expo app that loads my RN app from the local expo server.. Maybe I'm not understanding how detached apps works. Anyway, that's beside the point.

Should this package work in this situation? Is there something I'm doing wrong?

Let me know if I need to provide any further information.

Thanks!

Can't find libRNPrint.a

I installed the package by running npm install react-native-print --save, then I added RNPrint.xcodeproj to Libraries. As per the documentation, the next step is to Add libRNPrint.a to Build Phases -> Link Binary With Libraries, but I can't find that file to add. Am I missing any steps or what may be the reason behind this happening and how can I fix this?

Edit: Figured out how to add libRNPrint.a now. The steps in the docs regarding adding to the project seem to be somewhat lacking. Maybe I'll send a pull request later adding more details to the steps.

Print image from url

Im trying to print a image from url but app close and have error:

java.lang.RuntimeException: Cannot print a malformed PDF file
  android.print.PrintManager$PrintDocumentAdapterDelegate$MyHandler.handleMessage(PrintManager.java:1115)
  at android.os.Handler.dispatchMessage(Handler.java:106)
  at android.os.Looper.loop(Looper.java:164)
  at android.app.ActivityThread.main(ActivityThread.java:7002)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)

Only can print pdfs?

NPM PACKAGE BROKEN

NPM PACKAGE BROKEN npm i react-native-print --save installes in node_modules without several files like index.js

Printing multiple documents in ios loses some documents.

I am using this module to print labels for packages for a courier.
There are often multiple labels to print.

When the labels are printed in succession, the second one gets dropped.

I have created an example project based on the react-native-print sample project.

Steps to replicate:

create a new react-native project
add react-native-print

npm install react-native-print --save
react-native link

Replace the App.js with the following:

import React, { Component } from 'react';
import {
  Button,
  StyleSheet,
  View
} from 'react-native';

import RNPrint from 'react-native-print';

export default class RNPrintExample extends Component {

  async printHTML() {
    await RNPrint.print({
      html: '<h1>First Document</h3>'
    })
    
    await RNPrint.print({
      html: '<h1>Second Document</h3>'
    })

    await RNPrint.print({
      html: '<h1>Third Document</h3>'
    })
  }

  render() {
    return (
      <View style={styles.container}>
        <Button onPress={this.printHTML} title="Print HTML" />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
});

When you run the app, there is only one button "Print HTML". Clicking this will print the three documents.
The second document will be lost.

This works OK on Android.

RCTView.h not found?

Hi,

Your project is very usefull for me. I tried to deploy it on ios. But, in xcode, build failed with error RCTview.h not found.
I made react-native link and it has done task correctly.

Could you help me please?

class file for com.facebook.react.ReactApplication not found

I tried to add this package into my react native project. Here is the error I got,

/home/anonymous/myProject2/myProject-phase2-mobile/android/app/src/main/java/com/myProject/MainApplication.java:18: error: cannot access ReactApplication
public class MainApplication extends NavigationApplication {
       ^
  class file for com.facebook.react.ReactApplication not found
/home/anonymous/myProject2/myProject-phase2-mobile/android/app/src/main/java/com/myProject/MainApplication.java:20: error: method does not override or implement a method from a supertype
    @Override
    ^
/home/anonymous/myProject2/myProject-phase2-mobile/android/app/src/main/java/com/myProject/MainApplication.java:41: error: method does not override or implement a method from a supertype
    @Override
    ^
/home/anonymous/myProject2/myProject-phase2-mobile/android/app/src/main/java/com/myProject/MainApplication.java:46: error: method does not override or implement a method from a supertype
    @Override
    ^
/home/anonymous/myProject2/myProject-phase2-mobile/android/app/src/main/java/com/network/NetInfoPackage.java:12: error: NetInfoPackage is not abstract and does not override abstract method createJSModules() in ReactPackage
public class NetInfoPackage implements ReactPackage {
       ^
/home/anonymous/myProject2/myProject-phase2-mobile/android/app/src/main/java/com/myProjectclite/AuditLogPackage.java:12: error: AuditLogPackage is not abstract and does not override abstract method createJSModules() in ReactPackage
public class AuditLogPackage implements ReactPackage {
       ^
/home/anonymous/myProject2/myProject-phase2-mobile/android/app/src/main/java/com/myProjectclite/CouchPackage.java:12: error: CouchPackage is not abstract and does not override abstract method createJSModules() in ReactPackage
public class CouchPackage implements ReactPackage {
       ^
Note: /home/anonymous/myProject2/myProject-phase2-mobile/android/app/src/main/java/com/myProjectclite/CouchModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

I'm using react native version 0.56.0.

[Android] Cannot find printers

Downloaded the example app and tried to run it. Works OK on iOS and was able to print to the printer. However, couldn't do the same on Android... App is stuck on 'Searching for Printers' screen and nothing happens after that.

Looking at the emulator logs, I see the following: (omitted some stuff for better readability)

`
10-26 08:33:38.251 1704-1747/system_process I/ActivityManager: Displayed com.android.printspooler/.ui.PrintActivity: +573ms (total +1s153ms)

10-26 08:33:38.735 7716-7716/com.android.printspooler W/View: requestLayout() improperly called by android.widget.TextView{507e924 V.ED..... ......ID 239,0-265,63 #7f05000a app:id/copies_count_summary} during layout: running second layout pass

10-26 08:33:38.735 7716-7716/com.android.printspooler W/View: requestLayout() improperly called by android.widget.TextView{33f6c8d V.ED..... ......ID 572,0-693,63 #7f05000b app:id/paper_size_summary} during layout: running second layout pass

10-26 08:33:38.737 7716-7732/com.android.printspooler I/MutexFileProvider: Acquired file: /data/user/0/com.android.printspooler/files/print_job_ebd7b2a2-538a-4b8f-aeed-92e30e8fbb68.pdf by thread: Thread[AsyncTask #1,5,main]

10-26 08:33:38.751 7716-7732/com.android.printspooler I/MutexFileProvider: Released file: /data/user/0/com.android.printspooler/files/print_job_ebd7b2a2-538a-4b8f-aeed-92e30e8fbb68.pdf from thread: Thread[AsyncTask #1,5,main]

10-26 08:33:38.899 7716-7716/com.android.printspooler I/MutexFileProvider: Acquired file: /data/user/0/com.android.printspooler/files/print_job_ebd7b2a2-538a-4b8f-aeed-92e30e8fbb68.pdf by thread: Thread[main,5,main]

10-26 08:33:44.221 2154-2995/com.google.android.gms.persistent V/NativeCrypto: Read error: ssl=0x7f78dcd7bdc0: I/O error during system call, Connection reset by peer

10-26 08:33:44.222 2154-2995/com.google.android.gms.persistent V/NativeCrypto: SSL shutdown failed: ssl=0x7f78dcd7bdc0: I/O error during system call, Broken pipe

10-26 08:33:44.224 1704-2355/system_process D/ConnectivityService: reportNetworkConnectivity(100, false) by 10008

10-26 08:33:44.224 1704-2552/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (LTE) - 100]: Forcing reevaluation for UID 10008

10-26 08:33:55.169 7716-7731/com.android.printspooler D/EGL_emulation: eglMakeCurrent: 0x7f78dcd61820: ver 3 1 (tinfo 0x7f78dcd42c80)

10-26 08:33:57.031 1704-2168/system_process I/ActivityManager: START u0 {cmp=com.android.printspooler/.ui.SelectPrinterActivity} from uid 10047 on display 0

10-26 08:33:57.100 7716-7731/com.android.printspooler D/EGL_emulation: eglMakeCurrent: 0x7f78dcd61820: ver 3 1 (tinfo 0x7f78dcd42c80)

10-26 08:33:57.163 7660-7679/com.rnprintexample D/EGL_emulation: eglMakeCurrent: 0xee464600: ver 3 1 (tinfo 0xee4525f0)

10-26 08:33:57.166 7660-7679/com.rnprintexample E/Surface: getSlotFromBufferLocked: unknown buffer: 0xeaaca140

10-26 08:33:57.206 7716-7731/com.android.printspooler D/EGL_emulation: eglMakeCurrent: 0x7f78dcd61820: ver 3 1 (tinfo 0x7f78dcd42c80)

10-26 08:33:57.343 7716-7731/com.android.printspooler E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f78dcd61be0

10-26 08:33:57.349 7716-7731/com.android.printspooler D/OpenGLRenderer: endAllStagingAnimators on 0x7f78d0739400 (ListPopupWindow$DropDownListView) with handle 0x7f78dcd42fa0

10-26 08:33:57.523 7716-7731/com.android.printspooler D/EGL_emulation: eglMakeCurrent: 0x7f78dcd61820: ver 3 1 (tinfo 0x7f78dcd42c80)

10-26 08:33:57.743 1704-1747/system_process I/ActivityManager: Displayed com.android.printspooler/.ui.SelectPrinterActivity: +624ms

10-26 08:33:57.838 7716-7731/com.android.printspooler E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f78d94a4700

10-26 08:34:24.269 1704-2552/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (LTE) - 100]: Probably not a portal: exception java.net.UnknownHostException: Unable to resolve host "connectivitycheck.gstatic.com": No address associated with hostname

10-26 08:34:24.270 1704-1851/system_process D/ConnectivityService: NetworkAgentInfo [MOBILE (LTE) - 100] validation failed

10-26 08:34:24.271 1704-1851/system_process D/ConnectivityService: rematching NetworkAgentInfo [MOBILE (LTE) - 100]

10-26 08:34:24.271 1704-1851/system_process D/ConnectivityService: notifyType CAP_CHANGED for NetworkAgentInfo [MOBILE (LTE) - 100]

10-26 08:34:24.276 1704-1851/system_process D/ConnectivityService: sendStickyBroadcast: action=android.net.conn.INET_CONDITION_ACTION

10-26 08:34:24.277 1906-2374/com.android.systemui D/ConnectivityManager.CallbackHandler: CM callback handler got msg 524294

10-26 08:34:24.283 2396-3417/com.google.android.gms D/ConnectivityManager.CallbackHandler: CM callback handler got msg 524294

10-26 08:34:25.274 1704-2552/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (LTE) - 100]: Probably not a portal: exception java.net.UnknownHostException: Unable to resolve host "connectivitycheck.gstatic.com": No address associated with hostname

10-26 08:34:25.275 1704-1851/system_process D/ConnectivityService: NetworkAgentInfo [MOBILE (LTE) - 100] validation failed

10-26 08:34:59.293 1257-1316/? D/hwcomposer: hw_composer sent 3249 syncs in 60s

10-26 08:35:07.321 1704-2552/system_process
D/NetworkMonitor/NetworkAgentInfo [MOBILE (LTE) - 100]: Probably not a portal: exception java.net.UnknownHostException: Unable to resolve host "connectivitycheck.gstatic.com": No address associated with hostname
`

Tested it on my Mac and Windows PC and both had this problem, whereas the iOS version worked perfectly

iOS build problem RCTView.h

Hi !

First thanks for your work :)

I'm trying to build an app with react-native-print on iOS with RN 0.39.2

This is the error :
#import <React/RCTView.h> file not found
in RNPrint.h

I've tried with :
#import "RCTView.h"

instead but problem still here :/

Someone have a solution ?

Want to print out QRCode

How can I print out qrcode, I only found two method which path and html, someone can teach me?

Make it remember?

After i selected the printer, and i turn off the app. the app itself not remember the printer.
please Help.

Print html with a local image

Hi,

i need to print a custom html with a local image.
I tried but does not find the image.

var html = '<img src="'+ require('ProjectName/src/assets/logo.png') +'" alt="logo" height="150" width="150">';
        await RNPrint.print({
        html: html
})

screen

Upgraded to version 0.5.0 still unable to select a printer on the Ipad (works fine on phone)

I am using a IPAD pro 12.9
this is the select printer method I am using, called from the button below, on the iphone the dialog comes up but on the ipad nothing happens
here is the repo. the detach2 branch is the relevant one
detach-test

  selectPrinter = async () => {
    const selectedPrinter = await RNPrint.selectPrinter();
    this.setState({ selectedPrinter });
  };

<Button title="Select Printer" onPress={this.selectPrinter} />

Error when using printhtml method on android

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.instancecloudmobile, PID: 4098
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.destroy()' on a null object reference
at com.rnprint.RNPrint.RNPrintModule$2$1$1$override.onFinish(RNPrintModule.java:173)

await RNPrint.selectPrinter() Not Working on iOS IPAD (works normal on iPhones)

I invoked the RNPrint.selectPrinter() on multiple iPads (of many versions) but the select printer menu that normally appears when using the same method on an iPhone doesn't show up! When on an iPad, pressing the assigned button that would invoke the method would only flash the screen a bit.

Below is the code that I have used

  selectPrinter = async () => {
    if(this.state.selectedPrinter == null || this.state.selectedPrinter == undefined){
      const selectedPrinter = await RNPrint.selectPrinter()
      this.setState({ selectedPrinter })
      console.warn(selectedPrinter)
      console.warn(this.state.selectedPrinter)
    }
  }

This is the printer selection screen which pops on iPhones only (The result I am trying to achieve on iPad)
simulator screen shot - iphone x - 2018-04-08 at 15 39 27

[iOS] Callback fails when print is canceled two times with different print options (html and filePath or viceversa)

In my app I need to print different types of file in different views. So I use print() function both with filePath and html (separately), i.g.:
await RNPrint.print({ html: htmlToPrint });
and somewhere else
await RNPrint.print({ filePath: pdfToPrint });
The problem I'm facing with is that if I cancel both the print attempts above (in my app flow), it's showing an error:

simulator screen shot - iphone x - 2019-02-19 at 12 38 13

After many attempts and some research I found out the problem is that the options passed are not cleared, so that the print() function is trying to resolve itself with both filePath and html
await RNPrint.print({ filePath: pdfToPrint, html: htmlToPrint });

I've just submitted a PR which solves this issue.

You can check it here

Update SDK version

From mid august, Android will need a target sdk version which is minimum API26. Also the compile sdk version should be updated

build error after manuel linking

Hi,
I was trying to use the print library for my app. I tried the manuel linking and follow the steps written in readMe. The issue is this :
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
C:\Users\HasanCan\portabiles\sensor-app\sensorProject\android\app\src\main\java\com\sensorproject\MainApplication.java:13: error: cannot find symbol
import com.rnprint.RNPrint.RNPrint;
^
symbol: class RNPrint
location: package com.rnprint.RNPrint
C:\Users\HasanCan\portabiles\sensor-app\sensorProject\android\app\src\main\java\com\sensorproject\MainApplication.java:33: error: cannot find symbol
new RNPrint()
^
symbol: class RNPrint
2 errors
:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 37.61 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

any ideas?

PDF View

In android, I want one screen of my react native app to convert into PDF.It is possible to use direct comonent of app for converting pdf rather than html? And also can not change the number copies.It has only 1 number

Incorrectly named package in Android manifest

After installing the package and running react-native link and trying to build for Android I get:
/myapp/android/app/src/main/java/com/myapp/MainApplication.java:6: error: cannot find symbol import com.rnprint.RNPrint.RNPrintPackage; ^ symbol: class RNPrintPackage location: package com.rnprint.RNPrint /myapp/android/app/src/main/java/com/myapp/MainApplication.java:29: error: cannot find symbol new RNPrintPackage(), ^ symbol: class RNPrintPackage 2 errors :app:compileDebugJavaWithJavac FAILED

This seems to be due to the package listed in AndroidManifest.xml being the old package name before it was updated in 0.4.0. I'll have a pull request to fix this shortly.

Extra White space

I am using a brother Ql-820NWB thermal label printer and I am getting alot of extra whitespace when printing

Break on [email protected]

The module has been working great for the past few months. We recently updated to [email protected] and subsequently our builds have been failing.

The error lives on line 39 of the Completion handler in RNPrint.m
Too few arguments to block call, expected 3, have 1

I can get around the issue by adding two empty string arguments, but obviously it's not ideal :^/

It would be much appreciated if anyone has a solution for this. Unfortunately my Objective-C chops are non-existent for a pull request. Thanks.

OSX 10.11.3
Xcode 7.2.1
react-native ^0.21.0
react-native-print ^0.1.1

Silent print support

Hi and thanks for the (highly useful) library!

I'm curious if you had any plans to support "silent printing" -- in other words, printing directly to a printer without a print dialog. The usecase here is for things like receipt / ticketing printing, where we want the print to start automatically without intervention.

It looks like this is definitely possible with Apple's printing API - https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPrintInteractionController_Class/index.html#//apple_ref/doc/uid/TP40010141-CH1-SW34 / http://stackoverflow.com/questions/8125560/is-there-a-way-to-silent-print-using-ios-airprint-e-g-no-print-dialog for an example implementation.

The one other thing that would need to be added is a method to list the connected printers (so that the user could then set the desired printer).

If this isn't something you have the time / interest in building, I would be willing to work on a PR myself... just might be a bit slower due to unfamiliarity with Apple's printing APIs in general :)

Please let me know - thanks again!

Compile Error RNPrintModule.java uses or overrides a deprecated API

Hi, I am getting the following error when trying to compile the project 'react-native run-android'
:react-native-print:compileDebugJavaWithJavac Note: /Library/WebServer/Documents/TestingApp/node_modules/react-native-print/android/src/main/java/com/christopherdro/RNPrint/RNPrintModule.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

> Task :react-native-print:compileDebugJavaWithJavac FAILED /Library/WebServer/Documents/TestingApp/node_modules/react-native-print/android/src/main/java/com/christopherdro/RNPrint/RNPrintPackage.java:26: error: method does not override or implement a method from a supertype @Override ^

"react": "16.6.3",
"react-native": "^0.58.6",

Null Pointer Exception thrown while trying to connect with react-native-print module

This issue leads to application crash for the very first time when I try to connect with the print module which was developed with react-native-print. Please find the error log that I got.

Any help in solving this issue is much appreciated.

2018-12-18 12:37:59.336 18608-18608/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: in.instabike, PID: 18608
java.lang.NullPointerException: Attempt to invoke virtual method 'android.print.PrintDocumentAdapter android.webkit.WebView.createPrintDocumentAdapter()' on a null object reference
at com.christopherdro.RNPrint.RNPrintModule$1$1$1.(RNPrintModule.java:85)
at com.christopherdro.RNPrint.RNPrintModule$1$1.onPageFinished(RNPrintModule.java:83)
at xq.c(SourceFile:228)
at alW.handleMessage(SourceFile:72)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Android minsdkversion

Is there a reason why this library is setting the minsdkversion to 19? RN uses 16 and because of that there is a conflict.

I lowered the version to 16 and I was able to build my project and print a pdf with the library? Can we lower the sdk version in the package?
Shall I make a pull request with that?

help with language settings

So, my app is for a brazilian audience and I'd like to have it on full portuguese if possible.

The problem is the launcher is in english. Is there any way I could change it?

Thanks

selectPrinter not launching

Seems the selectPrinter function doesn't run happily. In the logs I see:
WARNING: Calling -[UIPrinterPickerController presentAnimated:completionHandler:] on iPad

Print Callback

Is there any callback? I want to apply some conditions on it.

@christopherdro can you please let me know about this, I have to perform some action.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.