How to Convert a PDF File to Text with OCR using Go

While vector PDF files can be converted to text directly by accessing the document’s compressed text contents, rasterized (image-based) PDF files require an Optical Character Recognition (OCR) service to make the same conversion. To make this conversion for free, you can easily take advantage of our PDF to Text OCR API using the complementary code examples provided at the bottom of this article in Go. All you’ll need in addition to these examples is a valid Cloudmersive API key, which you can get for free by registering a free account on our website (this will yield a limit of 800 API calls per month).

Before calling the below function, it’s important to note several optional features which can be configured to customize your conversion. These features include:

  1. Basic, Normal or Advanced recognition mode: these provide increasing fault tolerance for the OCR operation and use 1–2, 26–30 & 28–30 API calls respectively. The Advanced option is enabled by default.
  2. Language selection: you can select which language the API should recognize by including your language’s three-letter abbreviation in the “language” field as a string. Dozens of common languages are supported, including English, German, French, Danish, and much more.
  3. Preprocessing mode: by default, this API will automatically enhance the quality of the input image, but you can turn this off by entering ‘none’ as string into the preprocessing field.

To structure your API call, simply copy & paste the below code examples into your file. Once you parse your file path & API key into their respective fields, you’re ready to make your conversion:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.