在 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);
这也不行。我是离子和 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)
}
我想分享我使用 jsPDF 创建的 ionic 应用程序中的 pdf。如何将它与 SocialSharing 插件一起使用?
doc.save("resume.pdf")
这直接下载了pdf,把我带到了屏幕上,我什么也做不了。
//share(message, subject, file, url)
this.socialSharing.share("Test", null, doc.save("resume.pdf"), null);
这也不行。我是离子和 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)
}