cordova-pdf-generator
Advanced tools
Comparing version 1.9.0 to 1.9.2
{ | ||
"name": "cordova-pdf-generator", | ||
"version": "1.9.0", | ||
"version": "1.9.2", | ||
"description": "is a HTML to PDF (offline) Generator.", | ||
@@ -5,0 +5,0 @@ "cordova": { |
170
README.md
@@ -58,3 +58,3 @@ # cordova-pdf-generator | ||
``` | ||
```js | ||
document.addEventListener('deviceready', function(){ | ||
@@ -71,3 +71,3 @@ // start using cordova plugin here. | ||
###### pdf.usingURL( url, options ) | ||
#### pdf.usingURL( url, options ) | ||
@@ -81,3 +81,3 @@ Creates a PDF using a URL, it download the document into an in memory Webkit object, and renders it into a PDF. | ||
``` | ||
```js | ||
let options = { | ||
@@ -88,8 +88,8 @@ documentSize: "A4", | ||
pdf.usingURL( "http://www.google.es", options ) | ||
.then(()=>'ok') | ||
.catch((err)=>console.err(err)) | ||
pdf.usingURL("http://www.google.es", options) | ||
.then(()=>'ok') | ||
.catch((err)=>console.err(err)) | ||
``` | ||
###### pdf.usingData( url, options ) | ||
#### pdf.usingData( url, options ) | ||
@@ -102,3 +102,3 @@ Creates a PDF using string with the HTML representation, it download the document into an in memory Webkit object, and renders it into a PDF. | ||
``` | ||
```js | ||
let options = { | ||
@@ -109,7 +109,5 @@ documentSize: "A4", | ||
pdf.usingData( "<html> <h1> Hello World </h1> </html>", options ) | ||
.then((base64)=>'ok') // it will | ||
.catch((err)=>console.err(err)) | ||
pdf.usingData("<html><h1>Hello World</h1></html>", options) | ||
.then((base64)=>'ok') // it will | ||
.catch((err)=>console.err(err)) | ||
``` | ||
@@ -125,4 +123,5 @@ | ||
- ```base64``` it will return a Base64 representation of the PDF file. ```{ type: 'base64' } ``` | ||
``` | ||
- ```base64``` it will return a Base64 representation of the PDF file. ```{ type: 'base64' } ``, is not type is provided this one is choosen by default. ` | ||
```js | ||
let options = { | ||
@@ -133,5 +132,5 @@ documentSize: "A4", | ||
pdf.usingData( "<html> <h1> Hello World </h1> </html>", options ) | ||
.then((base64)=> console.log(base64) ) // returns base64:JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9DcmVh... | ||
.catch((err)=>console.err(err)) | ||
pdf.usingData("<html><h1>Hello World</h1></html>", options) | ||
.then((base64)=> console.log(base64) ) // returns base64:JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9DcmVh... | ||
.catch((err)=>console.err(err)) | ||
@@ -145,3 +144,3 @@ | ||
``` | ||
```js | ||
let options = { | ||
@@ -152,5 +151,5 @@ documentSize: "A4", | ||
pdf.usingData( "<html> <h1> Hello World </h1> </html>", options ) | ||
.then((stats)=> console.log('status', stats) ) // ok..., ok if it was able to handle the file to the OS. | ||
.catch((err)=>console.err(err)) | ||
pdf.usingData( "<html><h1>Hello World</h1></html>", options) | ||
.then((stats)=> console.log('status', stats) ) // ok..., ok if it was able to handle the file to the OS. | ||
.catch((err)=>console.err(err)) | ||
@@ -166,58 +165,8 @@ ``` | ||
**Legacy Examples** | ||
#### Other Use Cases | ||
##### Loading from Device Filesystem. | ||
Here are examples to use the legacy method pdf API below 1.9. | ||
This generates a pdf from a URL, it convert HTML to PDF and returns the file representation in base64. | ||
```js | ||
document.addEventListener('deviceready', function() { | ||
pdf.htmlToPDF({ | ||
url: "http://www.google.es", | ||
documentSize: "A4", | ||
landscape: "portrait", | ||
type: "base64" | ||
}, this.success, this.failure); | ||
}); | ||
``` | ||
The same but giving HTML without URL. | ||
```js | ||
document.addEventListener('deviceready', function() { | ||
pdf.htmlToPDF({ | ||
data: "<html> <h1> Hello World </h1> </html>", | ||
documentSize: "A4", | ||
landscape: "portrait", | ||
type: "base64" | ||
}, this.success, this.failure); | ||
}); | ||
``` | ||
Opening the pdf with other app menu. | ||
```js | ||
document.addEventListener('deviceready', function() { | ||
pdf.htmlToPDF({ | ||
data: "<html> <h1> Hello World </h1> </html>", | ||
documentSize: "A4", | ||
landscape: "portrait", | ||
type: "share" //use share to open the open-with-menu. | ||
}, this.success, this.failure); | ||
}); | ||
``` | ||
Loading from Device Filesystem. | ||
```js | ||
//Example: file:///android_asset/index.html | ||
@@ -260,7 +209,4 @@ | ||
[Gist](https://gist.github.com/cesarvr/6dc7156963dbfa7606b54c85fae84dba) | ||
##### Ionic/Angular 2 Example: | ||
## Ionic/Angular 2 Example: | ||
```js | ||
@@ -295,40 +241,60 @@ import { Component } from '@angular/core'; | ||
#### Deprecated | ||
Here are examples to use the deprecated methods. | ||
# Demo | ||
This generates a pdf from a URL, it convert HTML to PDF and returns the file representation in base64. | ||
- Cordova/Javascript [Demo](https://github.com/cesarvr/pdf-generator-example). | ||
- Ionic/Angular 2 [Example](https://github.com/cesarvr/ionic2-basic-example) | ||
```js | ||
document.addEventListener('deviceready', function() { | ||
pdf.htmlToPDF({ | ||
url: "http://www.google.es", | ||
documentSize: "A4", | ||
landscape: "portrait", | ||
type: "base64" | ||
}, this.success, this.failure); | ||
# API reference | ||
}); | ||
``` | ||
The same but giving HTML without URL. | ||
Due to the different way each platform generates the PDF, options not supported in the platform are just silently ignored. | ||
```js | ||
document.addEventListener('deviceready', function() { | ||
- Android/iOS | ||
- data: here you sent raw HTML. | ||
- url: url location of the webpage. | ||
pdf.htmlToPDF({ | ||
data: "<html> <h1> Hello World </h1> </html>", | ||
documentSize: "A4", | ||
landscape: "portrait", | ||
type: "base64" | ||
}, this.success, this.failure); | ||
- iOS | ||
- documentSize: for now only support "A4" and "A3". | ||
- landscape: portrait or landscape. | ||
- success callback: only expect one parameter base64 in case you choose 'base64' type option or boolean in case you to share. | ||
- type: | ||
- *base64* give you the pdf in Base64 format. | ||
- *share* opens IOS menu with all options available, this came handy when you want IOS take ownership of the generated document.. | ||
}); | ||
- Android | ||
- documentSize: parameter is ignored but required. | ||
- landscape: parameter is ignored but required. | ||
- type: | ||
- *base64* give you the pdf in Base64 format. | ||
- *share* opens Android native PDF viewer. | ||
- fileName : saved file name | ||
``` | ||
- failure callback: receive error information about what going wrong, for now is just raw exception so i need to improve this. | ||
Opening the pdf with other app menu. | ||
```js | ||
document.addEventListener('deviceready', function() { | ||
pdf.htmlToPDF({ | ||
data: "<html> <h1> Hello World </h1> </html>", | ||
documentSize: "A4", | ||
landscape: "portrait", | ||
type: "share" //use share to open the open-with-menu. | ||
}, this.success, this.failure); | ||
}); | ||
``` | ||
# Demo | ||
- Cordova/Javascript [Demo](https://github.com/cesarvr/pdf-generator-example). | ||
- Ionic/Angular 2 [Example](https://github.com/cesarvr/ionic2-basic-example) | ||
Install iOS or Android platform | ||
@@ -335,0 +301,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71206
304