Google-apps-script – Google Apps script to convert 1000s of pdfs to Google Docs

google docsgoogle-apps-scriptgoogle-drive

Can a Google Apps script be written to convert 1000s of PDFs to Google Docs?

Currently you have to open individual PDFs one-by-one "Open with Google Docs" to perform this transformation.

This is my first time working with Google Apps script (Google Doc > Tools > Script editor)

I have attempted to use https://github.com/odeke-em/drive but not having success yet.

Syncdocs https://www.syncdocs.com/forums/topic/pdf-conversion-issues#post-10464 is paid 3rd party tool that might work, but looking to do this for free if possible.

http://patt0.blogspot.com/2014/08/continuous-batch-library-update-for.html has some ideas but I have not been able to understand how to implement them.

keep getting an error

Missing ; before statement. (line 1, file "Code")Dismiss"

when entering any code

Best Answer

Google Apps Script can't run code like

drive init ~/gdrive
cd ~/gdrive

Google Apps Script only can run JavaScript code with some limitations, like it doesn't support by default let statements, promises among other.

Note: Converting files from PDF to Google Documents isn't an straightforward tasks because not all the PDF features could be converted

From Convert PDF to Doc with Google Script Editor

function pdfToDoc() {  
  var fileBlob = DriveApp.getFileById('0B3m2D6239t6aWHo5TVpyYzhxV1U').getBlob();  
  var resource = {
    title: fileBlob.getName(),
    mimeType: fileBlob.getContentType()
  };
  var options = {
    ocr: true
  };
  var docFile = Drive.Files.insert(resource, fileBlob, options);  
  Logger.log(docFile.alternateLink);  
}

Add Drive API to google apps script project https://developers.google.com/apps-script/guides/services/advanced#enabling_advanced_services

You can see you pdf file id on google drive when you download it http://i.imgur.com/3pYvwjx.png

NOTE: I didn't tested the above code yet.

References

Related