Convert Images to Text Using JavaScript

By using PSPDFKit for Web Server-Backed[], you can extract text from images.

First, make sure to open the image from PSPDFKit Server.

ℹ️ Note: 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" }
]);

ℹ️ Note: 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