GCP/Apps Script

Apps Script๋กœ ์ด๋ฏธ์ง€ํŒŒ์ผ/PDF ํŒŒ์ผ OCR ํ•˜๊ธฐ

whistory 2023. 2. 15. 10:57
๋ฐ˜์‘ํ˜•

 

๐Ÿ’กApps Script๋ฅผ ์ด์šฉํ•ด ์ด๋ฏธ์ง€๋‚˜ pdfํŒŒ์ผ์—์„œ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•ด๋ณธ๋‹ค.

 

์ž‘๋™๋ฐฉ์‹์€ ์ด๋ฏธ์ง€๋‚˜ pdf ํŒŒ์ผ์„ Google Drive์— OCR ๋œ ํ˜•ํƒœ์˜ ์ž„์‹œ ํŒŒ์ผ๋กœ  upload ํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค.

 

 

 

Apps Script ์ขŒ์ธก ๋ฉ”๋‰ด์—์„œ

์„œ๋น„์Šค์˜ [+] ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด Drive ์„œ๋น„์Šค๋ฅผ ์ฐพ์•„ ์ถ”๊ฐ€ํ•œ๋‹ค.

 

 

 

 

 

 

 

PDF ํŒŒ์ผ ocr

์›๋ณธ pdf

 

์Šคํฌ๋ฆฝํŠธ

function readTextFromFile() {
  const url = "https://www.africau.edu/images/default/sample.pdf";
  const contentBlob = UrlFetchApp.fetch(url).getBlob();
  const resource = {
    title : contentBlob.getName(),
    mimeType : contentBlob.getContentType()
  }
  const options = {
    ocr : true
  }
  const docFile = Drive.Files.insert(resource, contentBlob, options);
  const doc = DocumentApp.openById(docFile.id);
  const text = doc.getBody().getText();
  Drive.Files.remove(docFile.id);
  console.log(text);
}

 

๊ฒฐ๊ณผ

 

 

์ด๋ฏธ์ง€ ํŒŒ์ผ ocr

์›๋ณธ ์ด๋ฏธ์ง€

 

์Šคํฌ๋ฆฝํŠธ

function readTextFromFile() {
  const url = "https://i.stack.imgur.com/i1Abv.png";
  const contentBlob = UrlFetchApp.fetch(url).getBlob();
  const resource = {
    title : contentBlob.getName(),
    mimeType : contentBlob.getContentType()
  }
  const options = {
    ocr : true
  }
  const docFile = Drive.Files.insert(resource, contentBlob, options);
  const doc = DocumentApp.openById(docFile.id);
  const text = doc.getBody().getText();
  Drive.Files.remove(docFile.id);
  console.log(text);
}

๊ฒฐ๊ณผ

๋ฐ˜์‘ํ˜•