我想分享我使用 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/