簡體   English   中英

在 ionic 應用程序中共享 PDF

[英]Share a PDF in ionic app

我想從我使用 jsPDF 創建的 ionic 應用程序中共享 pdf。 如何將其與 SocialSharing 插件一起使用?

doc.save("resume.pdf") 

這會直接下載 pdf 並將我帶到無法執行任何操作的屏幕。

 //share(message, subject, file, url)
 this.socialSharing.share("Test", null, doc.save("resume.pdf"), null); 

這也行不通。 我是離子和角度的新手。

更新:我研究並關注了這篇文章該文章討論了在 ionic 應用程序中使用pdfmake制作 pdf,但我仍然不知道如何共享相同的內容。

import { File } from '@ionic-native/file';

var blob = doc.output('blob', {type: 'application/pdf'});
let pdfUrl = {pdfUrl: URL.createObjectURL(blob)};

if (this.file.checkFile(this.file.cacheDirectory, "myresume.pdf")) 
{
 this.file.writeExistingFile(this.file.cacheDirectory, "myresume.pdf",blob)
         .then(() => console.log('overwrite done'))
         .catch(err => console.log(err +' old copies not removed'));
} else{
    this.file.writeFile(this.file.cacheDirectory, "myresume.pdf", blob, true)
        .then(_ => console.log('write successful'))
        .catch(err => console.log(err+ " write failed"));
}

為了分享,

import { File } from '@ionic-native/file';
import { SocialSharing } from '@ionic-native/social-sharing';
export class ResumeView {
       pdfUrl : String;
       constructor(public navCtrl: NavController, 
                    public navParams: NavParams,
                    private socialSharing: SocialSharing,
                    private file: File
                   ) 
       {
           this.pdfUrl = this.navParams.get('pdfUrl'); 
       }
       regularShare(){
           this.socialSharing.share("test", null, this.file.cacheDirectory + filename, null)
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM