{
  "name": "PDF Central — upload, extract, poll and return records",
  "nodes": [
    {
      "parameters": {
        "formTitle": "PDF Central text extraction",
        "formDescription": "Upload one PDF (guest limit: 5 MiB and 10 pages).",
        "formFields": { "values": [{ "fieldLabel": "PDF", "fieldType": "file", "acceptFileTypes": ".pdf,application/pdf", "requiredField": true }] },
        "responseMode": "lastNode"
      },
      "id": "0d24f244-a208-4f2e-9445-acde08790e01",
      "name": "Receive PDF",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [-1040, 80],
      "webhookId": "pdf-central-extract"
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first();\nconst binaryName = Object.keys(item.binary || {})[0];\nif (!binaryName) throw new Error('A PDF file is required.');\nconst bytes = await this.helpers.getBinaryDataBuffer(0, binaryName);\nitem.json.pdfCentral = { binaryName, filename: item.binary[binaryName].fileName || 'input.pdf', mimeType: item.binary[binaryName].mimeType || 'application/pdf', sizeBytes: bytes.length };\nreturn [item];"
      },
      "id": "0d24f244-a208-4f2e-9445-acde08790e02",
      "name": "Inspect Input",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-820, 80]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://pdf-central.com/api/v1/guest-sessions",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "X-PDF-Central-Client", "value": "n8n-workflow/0.4.0" }, { "name": "X-PDF-Central-Channel", "value": "n8n_template" }] },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "{}",
        "options": {}
      },
      "id": "0d24f244-a208-4f2e-9445-acde08790e03",
      "name": "Create Guest Session",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-600, 80]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://pdf-central.com/api/v1/files/uploads",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "Authorization", "value": "=Bearer {{$node[\"Create Guest Session\"].json.result.token}}" }, { "name": "Idempotency-Key", "value": "=upload-{{$execution.id}}" }, { "name": "X-PDF-Central-Client", "value": "n8n-workflow/0.4.0" }] },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { filename: $node[\"Inspect Input\"].json.pdfCentral.filename, mime_type: $node[\"Inspect Input\"].json.pdfCentral.mimeType, size_bytes: $node[\"Inspect Input\"].json.pdfCentral.sizeBytes } }}",
        "options": {}
      },
      "id": "0d24f244-a208-4f2e-9445-acde08790e04",
      "name": "Create Upload",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-380, 0]
    },
    {
      "parameters": { "mode": "combine", "combineBy": "combineByPosition", "options": {} },
      "id": "0d24f244-a208-4f2e-9445-acde08790e05",
      "name": "Attach Original PDF",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [-160, 80]
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "={{$node[\"Create Upload\"].json.result.upload_url}}",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "Authorization", "value": "=Bearer {{$node[\"Create Guest Session\"].json.result.token}}" }, { "name": "Content-Type", "value": "={{$node[\"Inspect Input\"].json.pdfCentral.mimeType}}" }, { "name": "X-PDF-Central-Client", "value": "n8n-workflow/0.4.0" }] },
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "={{$node[\"Inspect Input\"].json.pdfCentral.binaryName}}",
        "options": {}
      },
      "id": "0d24f244-a208-4f2e-9445-acde08790e06",
      "name": "Upload Bytes",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [60, 80]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://pdf-central.com/api/v1/files/{{$node[\"Create Upload\"].json.result.file_id}}/complete",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "Authorization", "value": "=Bearer {{$node[\"Create Guest Session\"].json.result.token}}" }, { "name": "Idempotency-Key", "value": "=complete-{{$execution.id}}" }, { "name": "X-PDF-Central-Client", "value": "n8n-workflow/0.4.0" }] },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { upload_etag: $json.result.upload_etag } }}",
        "options": {}
      },
      "id": "0d24f244-a208-4f2e-9445-acde08790e07",
      "name": "Complete Upload",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [280, 80]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://pdf-central.com/api/v1/pdf/extract_pdf_text",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "Authorization", "value": "=Bearer {{$node[\"Create Guest Session\"].json.result.token}}" }, { "name": "Idempotency-Key", "value": "=job-{{$execution.id}}" }, { "name": "X-PDF-Central-Client", "value": "n8n-workflow/0.4.0" }] },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { file_ids: [$node[\"Create Upload\"].json.result.file_id], parameters: { include_page_numbers: true }, execution: { max_cost_microusd: 200000 }, idempotency_key: `job-${$execution.id}` } }}",
        "options": {}
      },
      "id": "0d24f244-a208-4f2e-9445-acde08790e08",
      "name": "Extract Text",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [500, 80]
    },
    {
      "parameters": { "conditions": { "options": { "caseSensitive": true, "typeValidation": "strict" }, "conditions": [{ "leftValue": "={{ ['completed','failed','cancelled'].includes($json.result.status) }}", "rightValue": true, "operator": { "type": "boolean", "operation": "true", "singleValue": true } }], "combinator": "and" }, "options": {} },
      "id": "0d24f244-a208-4f2e-9445-acde08790e09",
      "name": "Job Terminal?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [720, 80]
    },
    {
      "parameters": { "amount": 2 },
      "id": "0d24f244-a208-4f2e-9445-acde08790e10",
      "name": "Wait 2 Seconds",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [720, 280],
      "webhookId": "pdf-central-poll-wait"
    },
    {
      "parameters": {
        "url": "=https://pdf-central.com/api/v1/jobs/{{$node[\"Extract Text\"].json.result.job_id}}",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "Authorization", "value": "=Bearer {{$node[\"Create Guest Session\"].json.result.token}}" }, { "name": "X-PDF-Central-Client", "value": "n8n-workflow/0.4.0" }] },
        "options": {}
      },
      "id": "0d24f244-a208-4f2e-9445-acde08790e11",
      "name": "Get Job",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [940, 280]
    },
    {
      "parameters": { "conditions": { "options": { "caseSensitive": true, "typeValidation": "strict" }, "conditions": [{ "leftValue": "={{ $json.result.status }}", "rightValue": "completed", "operator": { "type": "string", "operation": "equals" } }], "combinator": "and" }, "options": {} },
      "id": "0d24f244-a208-4f2e-9445-acde08790e12",
      "name": "Job Completed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [980, 80]
    },
    {
      "parameters": {
        "url": "=https://pdf-central.com/api/v1/artifacts/{{$json.result.artifacts[0].artifact_id}}/records",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "Authorization", "value": "=Bearer {{$node[\"Create Guest Session\"].json.result.token}}" }, { "name": "X-PDF-Central-Client", "value": "n8n-workflow/0.4.0" }] },
        "options": {}
      },
      "id": "0d24f244-a208-4f2e-9445-acde08790e13",
      "name": "Read Artifact Records",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1200, 0]
    },
    {
      "parameters": { "jsCode": "return [{ json: { success: true, job_id: $node['Extract Text'].json.result.job_id, records: $json.result.items, truncated: $json.result.truncated || false } }];" },
      "id": "0d24f244-a208-4f2e-9445-acde08790e14",
      "name": "Return Records",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1420, 0]
    },
    {
      "parameters": { "jsCode": "const job = $json.result; return [{ json: { success: false, job_id: job.job_id, status: job.status, error: job.error || { code: 'JOB_NOT_COMPLETED', message: 'The job did not complete.' } } }];" },
      "id": "0d24f244-a208-4f2e-9445-acde08790e15",
      "name": "Return Job Error",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1200, 160]
    }
  ],
  "pinData": {},
  "connections": {
    "Receive PDF": { "main": [[{ "node": "Inspect Input", "type": "main", "index": 0 }]] },
    "Inspect Input": { "main": [[{ "node": "Create Guest Session", "type": "main", "index": 0 }, { "node": "Attach Original PDF", "type": "main", "index": 1 }]] },
    "Create Guest Session": { "main": [[{ "node": "Create Upload", "type": "main", "index": 0 }]] },
    "Create Upload": { "main": [[{ "node": "Attach Original PDF", "type": "main", "index": 0 }]] },
    "Attach Original PDF": { "main": [[{ "node": "Upload Bytes", "type": "main", "index": 0 }]] },
    "Upload Bytes": { "main": [[{ "node": "Complete Upload", "type": "main", "index": 0 }]] },
    "Complete Upload": { "main": [[{ "node": "Extract Text", "type": "main", "index": 0 }]] },
    "Extract Text": { "main": [[{ "node": "Job Terminal?", "type": "main", "index": 0 }]] },
    "Job Terminal?": { "main": [[{ "node": "Job Completed?", "type": "main", "index": 0 }], [{ "node": "Wait 2 Seconds", "type": "main", "index": 0 }]] },
    "Wait 2 Seconds": { "main": [[{ "node": "Get Job", "type": "main", "index": 0 }]] },
    "Get Job": { "main": [[{ "node": "Job Terminal?", "type": "main", "index": 0 }]] },
    "Job Completed?": { "main": [[{ "node": "Read Artifact Records", "type": "main", "index": 0 }], [{ "node": "Return Job Error", "type": "main", "index": 0 }]] },
    "Read Artifact Records": { "main": [[{ "node": "Return Records", "type": "main", "index": 0 }]] }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "versionId": "0d24f244-a208-4f2e-9445-acde08790eff",
  "meta": { "templateCredsSetupCompleted": true },
  "tags": []
}
