javascript - 在 ionic 应用程序中共享 PDF

标签 javascript angularjs ionic-framework ionic2 jspdf

我想分享我使用 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 和 Angular 新手。

更新:我研究并关注了this article其中讨论了在 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)
        }

关于javascript - 在 ionic 应用程序中共享 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43749535/

相关文章:

javascript - 如何绑定(bind)方法

javascript - $scope 未绑定(bind)到 Angular JS 中的函数内部

javascript - FOR 循环内的嵌套 IF 仅适用于第一个值

javascript - 检查对象是否有方法,而不实例化它

javascript - Angular JS 动态模板文件

javascript - $firebase 在 AngularJS 中未定义

android - ionic 多重闪屏

ionic-framework - 全局组件 Ionic 3

javascript - 从第 '1' 行的数据源请求未知参数 '0'

html - 缩小 css - 删除标记文件的内联样式中的 angularjs 表达式