cesarvr / pdf-generator

Cordova plugin to generate pdf in the client-side
MIT License
107 stars 61 forks source link

Ionic2 Use #15

Closed h2naashley closed 7 years ago

h2naashley commented 7 years ago

Helo, I am currently trying to use this amazing library with ionic2. But i am very new to ionic2 and cordova platform. and now i encounter the following issue : "The app stops at the stage of showing "Preparing preview" step described in the following screencast." screenshot_2017-03-17-20-34-05-928_com android printspooler What things i need to do else in order to overcome it? Thanks u , really appreciate help

cesarvr commented 7 years ago

Hi @h2naashley , this happens because the content is being downloaded and is taking to much (maybe slow connection), are you fetching the template from an external server ?, you can try to put your content in the device itself and try again.

h2naashley commented 7 years ago

Thank u for your kind response, like your advice , I've tested two ways already

  1. with URL to "http://google.com" , pdf.htmlToPDF({ url: "http://www.google.com", //url : this.url_new, documentSize: "A4", landscape: "portrait", type: "base64" }, this.success, this.failure);

  2. without url as following pdf.htmlToPDF({ data: "

    Hello World

    ", documentSize: "A4", landscape: "portrait", type: "base64" }, this.success, this.failure);

Give me the same result.

cesarvr commented 7 years ago

can you try this example just to see if it works with basic cordova? I will try to make a simple ionic 2 "hello world" to check if it I have found any problems. Cheers!.

h2naashley commented 7 years ago

Thanks. I've tried your example cordova app. It works perfectly. thanks. please kindly let me know after u test with ionic2, Thank u your kind help.

h2naashley commented 7 years ago

May I know Is there any update about ionic2 integration?

cesarvr commented 7 years ago

Hi @h2naashley , take a look at this example just make sure you are using version of the plugin 1.0.11, in that release I add implement support to call the module under the cordova.plugins namespace.

basic example:

import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';

declare var cordova:any;    //global; 

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {
      const before = Date.now();

            document.addEventListener('deviceready', () => {
                console.log('DEVICE READY FIRED AFTER', (Date.now() - before), 'ms');

                //generate the pdf.
                cordova.plugins.pdf.htmlToPDF({
                        data: "<html> <h1>  Hello World  </h1> </html>",
                        //url: "www.cloud.org/template.html"
                    },
                    (sucess) => console.log('sucess: ', sucess),
                    (error) => console.log('error:', error));
            });

  }

}

basic ionic 2 example. This example is very basic because I not very good Angular2, feel free to improve it and send a PR if you like :+1: . Cheers.

h2naashley commented 7 years ago

Thank you it works perfectly. Thanks u for your help and guidance.