getBlob()将文件转换为pdf [英] getBlob() is converting files to pdf

查看:103
本文介绍了getBlob()将文件转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试跟进此处的讨论:

I am trying to follow up on the discussion here: Zip drive files.

如果执行以下代码,则会看到由于某种原因,它会生成PDF文件.似乎getBlob()正在将它们转换为PDF.

If you execute the following code, you'll see that for some reason, it produces PDF files. It seems getBlob() is converting them to PDF.

  var folderId = DriveApp.getFoldersByName("Test").getId();
  var files = DriveApp.getFoldersByName("Test").getFiles();
  var blobs = [];
  var fileBlob = '';
  var file = '';
  while(files.hasNext()){
    file = files.next();
    fileBlob = file.getBlob();
    blobs.push(fileBlob);
  }
  
  var zippedFolder = Utilities.zip(blobs, 'Test.zip');
  DriveApp.getFoldersByName("Test").getParents().next().createFile(zippedFolder);

我下载了Test.zip,该文件中的每个文件(例如google表格或google docs)都已转换为PDF.其次,如果该文件夹包含任何Google Forms文件,则该代码会失败,并显示一条错误,提示无法将表单转换为pdf.

I download Test.zip and every file in that (like a google sheets or google docs) file has been converted into a PDF. Secondly, if the folder contains any Google Forms file, the code with fail with an error saying unable to convert forms to pdf.

我不想将任何文件转换为pdf.我只想压缩文件夹.有什么想法吗?

I don't want to convert any file to pdf. I just want to zip the folder. Any thoughts?

推荐答案

从Google Apps文件创建Blob时,这是预期的行为,但发现的表单除外.如果不先将其转换为其他格式,就无法压缩本机Doc或Sheet.

This is the expected behavior when you create a blob from a google apps file with the exception of forms which you have found. There is no way to zip up a native Doc or Sheet without converting it to another format first.

这篇关于getBlob()将文件转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆