Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将加密添加到已转换为PDF的Google工作表_Javascript_Pdf_Google Apps Script - Fatal编程技术网

Javascript 将加密添加到已转换为PDF的Google工作表

Javascript 将加密添加到已转换为PDF的Google工作表,javascript,pdf,google-apps-script,Javascript,Pdf,Google Apps Script,在将转换后的谷歌工作表作为电子邮件附件发送之前,是否可以将其加密为PDF格式 这是我当前的代码:它隐藏了我不需要转换的工作表,并将其他工作表转换为PDF。我想在这里实现的是对转换后的PDF进行密码加密,因为它包含一些个人信息 function myFunction() { Utilities.sleep(200); var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1");

在将转换后的谷歌工作表作为电子邮件附件发送之前,是否可以将其加密为PDF格式

这是我当前的代码:它隐藏了我不需要转换的工作表,并将其他工作表转换为PDF。我想在这里实现的是对转换后的PDF进行密码加密,因为它包含一些个人信息

function myFunction() {
  Utilities.sleep(200);

  var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1");
  var pdfsheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");

  sheet.hideSheet();

  var substringsubject = pdfsheet.getRange("B4:B4").getValues();
  var substringnname = pdfsheet.getRange("B3:B3").getValues();
  var substringidnum = pdfsheet.getRange("B7:B7").getValues();

  var startRow =9;  // First row of data to process B9:B9
  var numRows =1;   // Number of rows to process

  // Fetch the range of cells B9:B9
  var dataRange = pdfsheet.getRange(startRow, 1, numRows, 2)

  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var email = row[1];
    var emailcc = row[2];
    // Subject of email message
    var subject = "USER ACCOUNT DETAILS " + substringsubject + " " + substringidnum + ""; 
    var ss= SpreadsheetApp.getActiveSpreadsheet(); 
    // Email Body can  be HTML too 
    var body =    '<body>' + ' Hi ' + substringnname +',<br><br>' +
    'Please see attached file for your account details.</p>' +
    //'<p>  Click <a href="http://www.google.com">here</a> to go to google.<p>'
    '</body>'  

    var pdf = DriveApp.getFileById(ss.getId()).getAs("application/pdf"); 
    pdf.setName(substringsubject+" "+substringidnum+" .pdf");
    // If allowed to send emails, send the email with the PDF attachment  
    MailApp.sendEmail({
       to:email, 
       cc:emailcc,
       subject:subject, 
       htmlBody:body,
       attachments:[pdf]
    });
    sheet.showSheet();  
  }
}
函数myFunction(){
睡眠(200);
var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“表单响应1”);
var pdfsheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“Sheet2”);
sheet.hideSheet();
var substringsubject=pdfsheet.getRange(“B4:B4”).getValues();
var substringnname=pdfsheet.getRange(“B3:B3”).getValues();
var substringidnum=pdfsheet.getRange(“B7:B7”).getValues();
var startRow=9;//要处理B9的第一行数据:B9
var numRows=1;//要处理的行数
//获取单元格B9:B9的范围
var dataRange=pdfsheet.getRange(startRow,1,numRows,2)
//获取范围中每行的值。
var data=dataRange.getValues();
对于(变量i=0;i
'+ '有关您的帐户详细信息,请参阅附件。

'+ //“点击进入谷歌。” '' var pdf=DriveApp.getFileById(ss.getId()).getAs(“application/pdf”); setName(substringsubject+“”+substringidnum+“.pdf”); //如果允许发送电子邮件,请发送带有PDF附件的电子邮件 MailApp.sendmail({ 致:电邮:, 抄送:emailcc, 主题:主题,, htmlBody:body, 附件:[pdf] }); sheet.showSheet(); } }

谢谢。

您不能直接从应用程序脚本保护您的PDF。请看前面的内容。

哦,我明白了,我原以为它会被实施,因为这是3年前的一个问题。谢谢