{
  "id": "tackOcrSafe00001",
  "name": "OCR scanned PDFs with Tesseract",
  "nodes": [
    {
      "id": "n1",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [0, 0],
      "parameters": {}
    },
    {
      "id": "n2",
      "name": "Read PDFs",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [220, 0],
      "parameters": {
        "fileSelector": "/home/node/.n8n-files/in/*.pdf",
        "options": {}
      }
    },
    {
      "id": "n3",
      "name": "Save PDF",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [440, 0],
      "parameters": {
        "operation": "write",
        "fileName": "=/home/node/.n8n-files/ocr-{{ $execution.id }}-{{ $itemIndex }}.pdf",
        "dataPropertyName": "data",
        "options": {}
      }
    },
    {
      "id": "n4",
      "name": "OCR",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [660, 0],
      "parameters": {
        "executeOnce": false,
        "command": "=f=/home/node/.n8n-files/ocr-{{ $execution.id }}-{{ $itemIndex }}.pdf\nd=$(mktemp -d)\npdftoppm -r 300 -gray \"$f\" \"$d/p\" && ls \"$d\"/p-*.pgm | tesseract stdin stdout --dpi 300\ns=$?; rm -rf \"$d\" \"$f\"; exit $s"
      }
    },
    {
      "id": "n5",
      "name": "Text",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [880, 0],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "t1",
              "name": "fileName",
              "value": "={{ $('Read PDFs').item.json.fileName }}",
              "type": "string"
            },
            {
              "id": "t2",
              "name": "text",
              "value": "={{ $json.stdout }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Read PDFs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read PDFs": {
      "main": [
        [
          {
            "node": "Save PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save PDF": {
      "main": [
        [
          {
            "node": "OCR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OCR": {
      "main": [
        [
          {
            "node": "Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {}
}
