Send signature with Ionic 3 signature

I want to send my signature by email, but I can’t

Here is 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();
  }

}

Could you help me? I'm lost, when I press the button, an email opens, but there is text, but not an image

This is a plugin signature plugin and email address

+5
source share
1 answer

A bit late, but I was able to get this to work.

data:image/png;base64, from the signature should be removed using

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

Now just replace the attachment as follows:

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
    });

  }
Run codeHide result
0
source

Source: https://habr.com/ru/post/1681361/


All Articles