Send signature from signature pad Ionic 3

2019-06-21 15:46发布

问题:

I want to send my signature in an email but I don't manage to do it

Here's my code :

import { Component, ViewChild } from '@angular/core';
import { NavController} from 'ionic-angular';
import { SignaturePad } from 'angular2-signaturepad/signature-pad';
import { EmailComposer } from '@ionic-native/email-composer';

@Component({
  selector: 'page-envoie',
  templateUrl: 'envoie.html',
  providers: [SignaturePad, EmailComposer]
})
export class EnvoiePage {

  @ViewChild(SignaturePad) public signaturePad: SignaturePad;

  public signatureImage : string;
  public signaturePadOptions: Object = {
        'minWidth': 2,
        'canvasWidth': 340,
        'canvasHeight': 200 };

        public Cancel: string;

  constructor(public navCtrl: NavController, private emailComposer: EmailComposer){

    this.signatureImage = this.signaturePad.toDataURL();

    this.Cancel = this.signatureImage;

  }

   drawComplete() {

    this.signatureImage = this.signaturePad.toDataURL();
    this.emailComposer.open({
      to:      'lol@me.com',
      attachments: [this.signatureImage],
      subject: 'Avis de passage',
      body:    'test',
      isHtml: true
    });

  }

  drawClear() {
    this.signaturePad.clear();
  }

}

Can you help me? I'm lost, when I press the button, the email is opened there is my text but not the image

It's the plugin signature pad and the emailcomposer

回答1:

A little late, but I was able to get this working.

The data:image/png;base64, from the signature needs to be removed using

  this.signatureImage = this.signaturePad.toDataURL().replace('data:image/png;base64,', '');

Now just replace the attachment like so:

drawComplete() {

    this.signatureImage = this.signaturePad.toDataURL().replace('data:image/png;base64,', '');
    
    this.emailComposer.open({
      to:      'lol@me.com',
      attachments: ['base64:icon.png//'+this.signatureImage],
      subject: 'Avis de passage',
      body:    'test',
      isHtml: true
    });

  }