I'm trying to convert an existing .DOCX file on my Google Drive. It works up until the new (PDF) file should be created, then I get this error message: "Conversion from application/vnd.openxmlformats-officedocument.wordprocessingml.document to application/pdf failed".
The relevant DOCX file should not be corrupted as it can be opened by Google Document and manually convertred to PDF from there.
I have enabled Drive API (both in Drive and in API Console)
Anyone else seen this problem?
Code:
function convertPDF(fileid) {
var docId = fileid;
var f=DriveApp.getFileById(docId);
var n=f.getName();
var docFolder = f.getParents().next().getId();
var docblob = f.getAs('application/pdf');
n=n.replace(".docx",".pdf");
docblob.setName(n);
var bn=docblob.getName();
var t=docblob.getContentType();
Logger.log(bn+"-->"+t); // <-- works
var file = DriveApp.createFile(docblob); // <<- error msg here
var fileId = file.getId();
moveFileId(fileId, docFolder);
return (fileId);
}