Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. # Google Apps Script pdfToText Utility#
  2.  
  3. This is a helper function that will convert a given PDF file blob into text, as well as offering options to save the original PDF, intermediate Google Doc, and/or final plain text files. Additionally, the language used for Optical Character Recognition (OCR) may be specified, defaulting to 'en' (English).
  4.  
  5. Note: Updated 12 May 2015 due to deprecation of DocsList. Thanks to Bruce McPherson for the `getDriveFolderFromPath()` utility.
  6.  
  7. ```
  8. // Start with a Blob object
  9. var blob = gmailAttchment.getAs(MimeType.PDF);
  10.  
  11. // fileId will be the ID of a saved text file (default behavior):
  12. var fileId = pdfToText( blob );
  13.  
  14. // filetext will contain text from pdf file, no residual files are saved:
  15. var filetext = pdfToText( blob, {keepTextfile: false} );
  16.  
  17. // we can save other converted file types, too:
  18. var options = {
  19. keepPdf : true, // Keep a copy of the original PDF file.
  20. keepGdoc : true, // Keep a copy of the OCR Google Doc file.
  21. keepTextfile : true, // Keep a copy of the text file. (default)
  22. path : "attachments/today" // Folder path to store file(s) in.
  23. }
  24. filetext = pdfToText( blob, options );
  25. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement