简体   繁体   English

如何在 Android/IOS 设备上使用 jsPDF for PDF 和 SharePicker 在 Ionic 4 中生成和共享 PDF

[英]How to Generate and Share PDF on Android/IOS Device using jsPDF for PDF and SharePicker for Sharing in Ionic 4

home.html主页.html

<ion-fab vertical="bottom" horizontal="end" slot="fixed">
    <ion-fab-button (click)="sharePicker()">
      <ion-icon name="Share-alt" color="light"></ion-icon>
    </ion-fab-button>
</ion-fab>

home.ts家.ts

async sharePicker() {
var doc = new jsPDF();
var col = ["Id", "Brand name"];
var rows = [];
this.brand.forEach(element => {
  var temp = [
    element.id,
    element.name,
  ];
  console.log("temp", temp)
  rows.push(temp);

});
doc.autoTable(col, rows);
doc.save("BrandList.pdf");

this.platform.ready()
  .then(() => {
    this.socialSharing.share(null, null, doc.save("BrandList.pdf"), null)
      .then((data) => {
        console.log('Shared via SharePicker');
      }).catch((err) => {
        console.log('Was not shared via SharePicker');
      });
   });
  }

Items List get Directly to the Database and Added to the col Parameter,项目列表直接获取到Database并添加到col参数中,

I want when i click FAB Button, then PDF Generate Automatically, and open the share Option and Send PDF on Social Media, like, whatsapp, fb, etc我希望当我单击FAB按钮,然后自动生成PDF ,并打开共享选项并在社交媒体上发送PDF ,例如,whatsapp、fb 等

this code generate PDF in Browser but not on Device.此代码在浏览器中生成PDF ,但不在设备上。

jsPDF won't download file on phones/ tablets / ipads using "pdf.save()". jsPDF 不会使用“pdf.save()”在手机/平板电脑/ipad 上下载文件。

Check this检查这个

The options to send directly via social share is use email with file Param or you can also upload via Firebase and share only the url通过社交共享直接发送的选项是使用带有文件参数的电子邮件,或者您也可以通过 Firebase 上传并仅共享 url

Example using Firebase:使用 Firebase 的示例:

uploadPDF(selected) {  
    return firebase.storage().ref(this.pathFinal).child('/path/').putString(selected, 'data_url')
  }

Then:然后:

upload(){        
    let loading = this.uiUtils.showLoading("uploading...")
    loading.present()

    this.storage.uploadPDF('pathtopdf')

      .then(snapshot => {

        snapshot.ref.getDownloadURL().then(url => {
          loading.dismiss()
            console.log('Share this url: ' + url)
            this.uiUtils.showAlertSuccess('Success')
          })

        }).catch(err => {
          loading.dismiss()
          this.idUrl = ""
          this.uiUtils.showAlert("Atenção", err).present()

        })
      })
      .catch( error => {
        loading.dismiss()
        this.uiUtils.showAlert("Atenção", error).present()

      }).catch(errorSend => {
        loading.dismiss()
        this.uiUtils.showAlert("Atenção", errorSend).present()
      })      
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM