First Apps Script, OCR capture from YouTube & Sheets to PDF

YouTube screen capture convert text

I watch tutorial videos to learn how to do certain things in coding. Sometimes, in the video, they leave a copy of the code so that you can download it, other times this is not the case.

So you have to write the code out longhand for yourself, which can be a bit tedious.

I have recently started using Google Keep again for notes and lists. A nice feature of Keep is that you can open it in your browser, so while on the computer you can quickly add items to current lists.

Another feature that I saw demonstrated and have been tinkering with is the OCR (Optical character recognition) image to text feature. I have been trying to see if I can use a picture of my shopping receipts to get data for my Spending Tracker Form that I created (see previous blog). I am still working on that.

In an earlier post I used autoCrat Addon to merge a template for “Quotes for Services”  from an online Google Form and that generated the pdf files that was an attachment to email. The issue was the saved forms were saved as Google Sheets , not PDF’s (unlike Document Studio add on). I would prefer to have PDF’s as a archive record rather than just the sheets, so you have a non tamperable record.

I found this video:

Using Google Keep OCR feature to capture text

I thought was an elegant way to resolve this issue, but there was no attached code at the bottom of the video. So I zoomed into the video in the browser & took a screenshot of the text:

I imported that image into google Keep

Once in Keep in a new note I could use the GRAB IMAGE TEXT feature and it wrote the text in the form below.

There were missing brackets, equal signs, apostrophes,quotes, colons and semicolons that were missed but you are only editing these items rather than writing the whole code out from scratch.

Its nice to have the image directly above to check the text to see its the same.

The code is here:

function getDocs(){

var folderId=’1tqjJHZe_qJuJogy21cGZkjZVr8g3n8fa’;

var pdfFolder=DriveApp.getFolderById(folderId).createFolder( ‘PDFs’);

var files=DriveApp.getFolderById(folderId).getFiles();

while(files.hasNext()) {

var file;

var pdf =file.getAs(‘application/pdf’);



Testing the captured code

So now I have the code to test.I have to figure out how to run an apps script, the video below shows the steps. Note, in the current version it says this is not a google approved app so go into advanced and choose to approve script anyway.

So, testing the code, first I went to:

Put in the code and saved it, then ran it.

I had to get a link to the folder where the files were located, as per the original video and replace folder name in first line of code below,

In the folder where all of the spreadsheets were it created a new folder, as per the code:

It also generated the PDF files of all the spreadsheets in the directory above

I was worried that, being spreadsheets instead of docs the code may get confused, but as there is only one tab in each spreadsheet the pdf was exactly what I wanted.

End comment

I have been looking at the Apps Scripts and seeing if I can find some pre-made scripts that will help automate some of the things I am working on.  I haven’t found a good repository yet. There seem to be more samples to teaching a process. I am looking for practical ones, like the one above, that will help me automate common processes.

I am pleased with the OCR capture tool in Keep. There are other OCR free tools out there, but Keep is readily available across my devices so at hand for this task. I don’t think I would have loaded up a specific OCR programme just to do this task for such a small amount of text.

I am also pleased with the code operating. A nice solution for AutoCrat sheets addon. I like it more than the Document Studio as its a bit more flexible. I like the fact that it saves the merged sheets as sheets , rather than PDF’s as that will allow me to easily go back and adjust the quote in the original spreadsheet quote without having to setup one specifically for adjustments.  This code solves that issue nicely.

Add a Comment