Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-tesseract-ocr",
"version": "2.2.1",
"version": "2.2.2",
"description": "A Node.js wrapper for the Tesseract OCR API",
"keywords": [
"ocr",
Expand Down
3 changes: 2 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,5 @@ export type Config = Partial<{
* @param config - any OCR options and control parameters
* @returns default output format is text
*/
export function recognize(input: Input, config?: Config): Promise<string>
export function recognize(input: Input, config: Config & { presets: (string | Preset)[] & ["pdf"] }): Promise<Buffer>
export function recognize(input: Input, config?: Config): Promise<string>
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ function recognize(input, config = {}) {
if (config.debug) log("command", command)

return new Promise((resolve, reject) => {
const child = exec(command, (error, stdout, stderr) => {
const opts = {}
if (!config["tessdata-dir"] && config.presets && Array.isArray(config.presets) && config.presets.includes("pdf"))
opts.encoding = "buffer"

const child = exec(command, {
...opts,
maxBuffer: 1024 * 1024 * 32
}, (error, stdout, stderr) => {
if (config.debug) log(stderr)
if (error) reject(error)
resolve(stdout)
Expand Down