Skip to content
OCR library to convert pdf files and images into a text with Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


OCR library is based on OCR.Space API, meant to read text from pdf files and images with Go language


  1. Get your API key
  2. Installation
  3. Update
  4. Basic Usage
  5. Example Code

1. Get your API key

You can get your personal API key here (we will need this later)

2. Installation

go get -t

3. Update

Delete the folder situated in $GO_PATH/src/ and then run this command:

go get -t

4. Basic Usage

You need at first to create a configuration:

package main

	Remember to run your program from your $GO_PATH/src/name_of_your_folder
	or to provide the right path to this library that is situated
	in $GO_PATH/src/
	ocr ""
	//Other libraries...

func main(){
	config := ocr.InitConfig("yourApiKeyHere", "eng")
	//More code here...

The first parameter is your API key as a string and the second one is the code of the language you want read from file or image. Here a list of all available languages and their code*:

  • Arabic = ara
  • Bulgarian = bul
  • Chinese(Simplified) = chs
  • Chinese(Traditional) = cht
  • Croatian = hrv
  • Czech = cze
  • Danish = dan
  • Dutch = dut
  • English = eng
  • Finnish = fin
  • French = fre
  • German = ger
  • Greek = gre
  • Hungarian = hun
  • Korean = kor
  • Italian = ita
  • Japanese = jpn
  • Polish = pol
  • Portuguese = por
  • Russian = rus
  • Slovenian = slv
  • Spanish = spa
  • Swedish = swe
  • Turkish = tur

Now we can go ahead and start reading some text; there are three method that allow you to do it:




Method names are self explanatory.

Remember: .ParseFromBase64 need as parameter a valid Base64 format like data:<file>/<extension>;base64,<image> where:

  • <file> is application in case of a pdf file or image in case of an image
  • <extension> is the extension of the file you encode. Only valid are pdf, jpg, png and gif
  • <image> is the actual encode of your file

So basically these methods will give you back the whole struct complete of all parameters that OCR.Space provides to you.

If you are only interested in the output text call .justText() method at the end of one of the three methods mentioned above.

5. Example Code

package main

import (
	ocr ""

func main() {
	//this is a demo api key 

    //setting up the configuration 
    config := ocr.InitConfig(apiKey , "eng")

    //actual converting the image from the url (struct content) 
    result, err := config.ParseFromUrl("")
    if err != nil {
    //printing the just the parsed text

Example output

Maybe we should all just listen to 
records and quit our jobs 
Jack White 
You can’t perform that action at this time.