Skip to content

KrazyLabs/react-native-print

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.rnprint.RNPrint.RNPrint;

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

Usage

import React from 'react';
import {
  Platform,
  Text,
  TouchableHighlight,
  View,
} from 'react-native';
import {RNPrint} from 'NativeModules';

var Example = React.createClass({

  printDocument(filePath) {
    RNPrint.print(filePath).then((jobName) => {
      console.log(`Printing ${jobName} complete!`);
    });;
  },

  printHTML(htmlString) {
    // only available on android
    if (Platform.OS === 'android'){
      RNPrint.printhtml(htmlString).then((jobName) => {
        console.log(`Printing ${jobName} complete!`);
      });
    }
  },

  render() {
    <View>
      <TouchableHighlight onPress={this.printPDF(filePath)}>
        <Text>Print Document</Text>
      </TouchableHighlight>
    </View>
  }
});

Example

The example project included demonstrates how you use react-native-html-to-pdf to create a PDF from a html string then prompt the print dialog.

About

Print documents using React Native

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 40.7%
  • Objective-C 37.3%
  • JavaScript 15.3%
  • Python 6.7%