我想从我使用JSPDF创建的离子应用中共享一个PDF。我如何将其与社交共享插件一起使用?
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)
}