Convert Images to Text Using JavaScript

You can convert images to text with PSPDFKit for Web.

Information

Converting images to text is available when using the Web SDK with Document Engine in server-backed operational mode.

First, make sure to open the image from Document Engine.

Information

This feature requires the Image Documents component to be enabled in your license.

Next, detect the text in the image by running the performOcr operation:

await instance.applyOperations([
  { type: "performOcr", language: "english", pageIndexes: "all" }
]);
Information

This feature requires the OCR component to be enabled in your license.

Then you can extract the text using the PSPDFKit.Instance#textLinesForPageIndex method:

const textLines = await instance.textLineForPageIndex(0);

To log all text in the image on the console, you can then run:

textLines.forEach((l) => console.log(l.contents));

Other Languages

You can extract text written in languages other than English using the language parameter:

await instance.applyOperations([
  { type: "performOcr", language: "spanish", pageIndexes: "all" }
]);

PSPDFKit for Web supports the following languages:

  • Croatian

  • Czech

  • Danish

  • Dutch

  • English

  • Finnish

  • French

  • German

  • Indonesian

  • Italian

  • Malay

  • Norwegian

  • Polish

  • Portuguese

  • Serbian

  • Slovak

  • Slovenian

  • Spanish

  • Swedish

  • Turkish

  • Welsh