OGeek|极客世界-中国程序员成长平台

标题: ios - PDF 未附加 phonegap 电子邮件编辑器 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 00:48
标题: ios - PDF 未附加 phonegap 电子邮件编辑器

我正在使用以下插件从 iphone phongeap 应用程序(使用 ionic)发送电子邮件:https://github.com/katzer/cordova-plugin-email-composer

一切正常,除非我尝试附加保存到设备的 pdf 文件:当电子邮件界面打开时,我可以看到附加的 pdf(称为 test.pdf),但是当电子邮件到达收件人时,有没有PDF。相反,有一个附加的 txt 文件,但没有任何内容。

如果我去 window.replace(pdf 的路径),PDF 会打开,所以我确定 PDF 被保存并且路径是正确的。阅读本文后,https://github.com/katzer/cordova-plugin-email-composer/issues/33 ,我也尝试删除路径开始(file://)并将其替换为(relative://)但没有用。非常感谢您对此的任何意见:以下是相关代码:

    var doc = new jsPDF();

    doc.text(20, 20, 'HELLO!');

    doc.setFont("courier");
    doc.setFontType("normal");
    doc.text(20, 30, 'This is a PDF document generated using JSPDF.');
    doc.text(20, 50, 'YES, Inside of PhoneGap!');

    var pdfOutput = doc.output();
    console.log( pdfOutput );


window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {



  fileSystem.root.getFile("test.pdf", {create: true}, function(entry) {
  var fileEntry = entry;
  console.log(entry);

  $scope.filepath =  fileEntry.toURL();

  $scope.filepath = $scope.filepath.replace('file\:\/\/', 'relative://');




    $scope.emailer($scope.filepath);    


     //  window.location.href = $scope.filepath;




  entry.createWriter(function(writer) {
     writer.onwrite = function(evt) {
     console.log("write success");
  };

  console.log("writing to file");
     writer.write( pdfOutput );
  }, function(error) {
     console.log(error);
  });

  }, function(error){
   console.log(error);
 });





},
function(event){
 console.log( evt.target.error.code );
 });



    $scope.emailer = function(file) {


    alert(file);



    window.plugin.email.open({
            to:      ['[email protected]'],
            subject: 'Congratulations',
            body:    '<h1>Happy Birthday!!!</h1>',
            attachments: [file]     
        });



Best Answer-推荐答案


我们使用的是完全相同的插件并且可以正常工作,我们使用的 URL 看起来像这样

/var/mobile/Applications/998AEF02-5D26-4064-BC7D-A94A218609C5/Documents/yourpdffilenamehere.pdf

URL 从我们使用的 pdf 插件返回到我们的应用程序。

关于ios - PDF 未附加 phonegap 电子邮件编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25380401/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4