Send signature from signature pad Ionic 3

試著忘記壹切 提交于 2019-12-10 14:12:47

问题


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

  }


来源:https://stackoverflow.com/questions/45080538/send-signature-from-signature-pad-ionic-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!