Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

## PDF Generator for React Native.

Is a light weight native library that transform HTML to PDF, or even better transform the content of a URL like ```https://google.com``` into a PDF.
Is a light weight native library that transform HTML to PDF, or even better transform the content of a URL like `https://google.com` into a PDF.

The PDF is returned in base64 format so you can use more specialized modules to mail, sharing, visualizing, etc.

Expand All @@ -15,17 +14,14 @@ For Android it just use [WebView](https://developer.android.com/reference/androi

#### Changelog

**1.6.4:** Adding React Native ``0.6x`` compatibility.
**1.6.5:** Added maven plugin on android build.gradle for compatibility with gradle 7.x version.
**1.6.4:** Adding React Native `0.6x` compatibility.
**1.6.1:** Removed deprecated UIWebView.


### Supported Devices

* iOS >=8
* Android >=19



- iOS >=8
- Android >=19

## Getting started

Expand All @@ -42,39 +38,32 @@ To install the library:

[hard way...](https://facebook.github.io/react-native/docs/linking-libraries-ios)


### Usage

To transform raw HTML into PDF:

```javascript
import PDF from 'rn-pdf-generator';
import PDF from "rn-pdf-generator"

PDF.fromHTML(`<P>HELLO WORLD</P>`, `http://localhost`)
.then( data => console.log(data)) // WFuIGlzIGRpc3Rpbm....
.catch( err => console.log('error->', err) )
.then(data => console.log(data)) // WFuIGlzIGRpc3Rpbm....
.catch(err => console.log("error->", err))
```

> In case you this HTML fetch resources from external servers you can specify the location using the second parameter ``<base-url>``.
> In case you this HTML fetch resources from external servers you can specify the location using the second parameter `<base-url>`.

Transforming a remote webpage:

```javascript
import PDF from "rn-pdf-generator"

import PDF from 'rn-pdf-generator';

PDF.fromURL('https://www.google.com/')
.then( data => console.log(data)) // WFuIGlzIGRpc3Rpbm....
.catch( err => console.log('error->', err) )

PDF.fromURL("https://www.google.com/")
.then(data => console.log(data)) // WFuIGlzIGRpc3Rpbm....
.catch(err => console.log("error->", err))
```

### Demo

### Demo

[This demo](https://github.com/cesarvr/react-native-pdf-generator-demo) that generates a PDF and then display it using [react-native-pdf plugin](https://www.npmjs.com/package/react-native-pdf).
[This demo](https://github.com/cesarvr/react-native-pdf-generator-demo) that generates a PDF and then display it using [react-native-pdf plugin](https://www.npmjs.com/package/react-native-pdf).

![Demo](https://github.com/cesarvr/react-native-pdf-generator-demo/blob/master/demo-img/pdf_document.gif?raw=true)



23 changes: 11 additions & 12 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_MIN_SDK_VERSION = 19
def DEFAULT_TARGET_SDK_VERSION = 28

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'

buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
Expand All @@ -39,7 +39,7 @@ buildscript {
}

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
Expand Down Expand Up @@ -124,12 +124,12 @@ afterEvaluate { project ->
}

task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
from androidJavadoc.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
archiveClassifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}
Expand All @@ -148,12 +148,11 @@ afterEvaluate { project ->
archives androidJavadocJar
}

task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://${projectDir}/../android/maven"
configureReactNativePom pom
publishing {
publications {
maven(MavenPublication) {
artifact androidSourcesJar
}
}
}
}
}
62 changes: 31 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{
"name": "rn-pdf-generator",
"version": "1.6.4",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/cesarvr/react-native-pdf-generator.git"
},
"keywords": [
"react-native",
"pdf",
"generator",
"html to pdf",
"html2pdf"
],
"author": {
"name": "Cesar Valdez",
"email": "cvaldezrx@gmail.com"
},
"license": "MIT",
"peerDependencies": {
"react": "^16.8.1",
"react-native": ">=0.60.0-rc.0 <1.0.x"
},
"devDependencies": {
"react": "^16.9.0",
"react-native": "^0.61.5"
}
"name": "rn-pdf-generator",
"version": "1.6.5",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/cesarvr/react-native-pdf-generator.git"
},
"keywords": [
"react-native",
"pdf",
"generator",
"html to pdf",
"html2pdf"
],
"author": {
"name": "Cesar Valdez",
"email": "cvaldezrx@gmail.com"
},
"license": "MIT",
"peerDependencies": {
"react": "^16.8.1",
"react-native": ">=0.60.0-rc.0 <1.0.x"
},
"devDependencies": {
"react": "^16.9.0",
"react-native": "^0.61.5"
}
}