ocrmypdf-js
v1.1.4
Published
Abstração da lib ocrmypdf
Readme
ocrmypdf-js
A JavaScript library that adds “layers” of text to images in PDFs, making scanned image PDFs searchable using ocrmypdf, which is a Python application and library.
Prerequisites
For everything to work correctly, you need to have it installed on your OS ocrmypdf.
Example
Debian or Ubuntu users can simply use the following:
sudo apt install ocrmypdfFor more information on how to install on different OS, see the installation documents.
Installation
Install ocrmypdf-js with your preferred package manager
npm i ocrmypdf-js
// or
yarn add ocrmypdf-js
// or
pnpm add ocrmypdf-jsUsage/Examples
Basic example ref.
import { OcrMyPdf } from "ocrmypdf-js";
(async () => {
const ocrmypdf = new OcrMyPdf();
await ocrmypdf.execute({
inputPath: "path/to/input.pdf",
outputPath: "path/to/output.pdf",
});
})();Parametros do construtor
When creating the constructor, it is possible to pass some parameters such as:
args: string[]see about arguments in documentationinputPath: stringinput pdf pathoutputPath: stringoutput pdf path
[!TIP] 💡 If the inputPath or outputPath fields are provided, it is not necessary to provide them during execution.
import { resolve } from "path";
import { OcrMyPdf } from "ocrmypdf-js";
(async () => {
const args = ["-l por"]; // troca o idioma padrão para português
const inputPath = resolve("path/simple.pdf");
const inputPath = resolve("path/simple-ocr.pdf");
const ocrmypdf = new OcrMyPdf({ args, inputPath, outputPath });
await ocrmypdf.execute();
})();[!NOTE] The
-l porargs to work requires the additional selected language to be installed, see how install;Custom args
The args: ['--return-text'] args returns the text of the PDF in a string format.
import { OcrMyPdf } from "ocrmypdf-js";
import { resolve } from "path";
(async () => {
const ocrmypdf = new OcrMyPdf();
const { outputText } = await ocrmypdf.execute({
inputPath: resolve("path/simple.pdf"),
outputPath: resolve("path/simple-ocr.pdf"),
args: ["--return-text"],
});
console.log(outputText);
})();