{
  "workflow": {
    "id": 3869,
    "name": "Convert HTML to PDF and compress files with CustomJS API",
    "views": 2152,
    "recentViews": 0,
    "totalViews": 2152,
    "createdAt": "2025-05-05T10:43:39.715Z",
    "description": "![workflow.png](fileId:1268)\nThis n8n template demonstrates how to convert HTML into a PDF, compress the generated PDF, and return it as a binary response using the PDF Toolkit from www.customjs.space.\n\n### Notice\n\nCommunity nodes can only be installed on self-hosted instances of n8n.\n\n[@custom-js/n8n-nodes-pdf-toolkit](https://www.npmjs.com/package/@custom-js/n8n-nodes-pdf-toolkit)\n\n### What this workflow does\n\n- **Convert** the requested HTML to PDF.\n- **Compress** the PDF file.\n- **Use** a Code node to handle URLs pointing to PDF files if they exceed 6MB.\n- **Compress** the PDF pages.\n\n### Requirements\n\n- **Self-hosted** n8n instance\n- **CustomJS API key** for compressing PDF files.\n- **HTML** Data to convert PDF files\n- **Code node** for handling URL that indicates PDF file.\n\n### Workflow Steps:\n\n1. **Manual Trigger**:\n\n   - Runs with user interaction.\n\n2. **HTML to PDF**:\n\n   - Request HTML Data\n   - Convert HTML to PDF\n   - Request PDF from URL.\n\n3. **Compress Pages from PDF**:\n   - Compress PDF as a binary file.\n\n---\n\n### Usage\n\n### Get API key from [customJS](https://www.customjs.space)\n\n- Sign up to customJS platform.\n- Navigate to your profile page\n- Press \"Show\" button to get API key\n![1.png](fileId:1269)\n\n### Set Credentials for CustomJS API on n8n\n\nCopy and paste your API key generated from CustomJS here.\n![2.png](fileId:1267)\n\n### Design workflow\n\n- A Manual Trigger for starting workflow.\n- HTTP Request Nodes for downloading PDF files.\n- Code node for handling URL that indicates PDF file.\n- Compress PDF files.\n\nYou can replace logic for triggering and returning results.\nFor example, you can trigger this workflow by calling a webhook and get a result as a response from webhook. Simply replace Manual Trigger and Write to Disk nodes.\n",
    "workflow": {
      "meta": {
        "instanceId": "7599ed929ea25767a019b87ecbc83b90e16a268cb51892887b450656ac4518a2"
      },
      "nodes": [
        {
          "id": "b962ef3d-b0ad-4b21-bb15-61b6521bfd03",
          "name": "HTML to PDF",
          "type": "@custom-js/n8n-nodes-pdf-toolkit.html2Pdf",
          "position": [
            220,
            0
          ],
          "parameters": {
            "htmlInput": "<h1>Hello World</h1>"
          },
          "credentials": {
            "customJsApi": {
              "id": "credential-id",
              "name": "customJsApi Credential"
            }
          },
          "notesInFlow": false,
          "typeVersion": 1
        },
        {
          "id": "988f427e-7eca-43e5-a77d-c69a92ec6158",
          "name": "Compress PDF file",
          "type": "@custom-js/n8n-nodes-pdf-toolkit.CompressPDF",
          "position": [
            460,
            0
          ],
          "parameters": {},
          "credentials": {
            "customJsApi": {
              "id": "credential-id",
              "name": "customJsApi Credential"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "bbbf9fb1-2fc2-4de1-9854-149b63c7070c",
          "name": "When clicking ‘Test workflow’",
          "type": "n8n-nodes-base.manualTrigger",
          "position": [
            0,
            100
          ],
          "parameters": {},
          "typeVersion": 1
        },
        {
          "id": "492b07d3-4643-4d1e-acbb-b0a7b7fde350",
          "name": "Compress PDF file1",
          "type": "@custom-js/n8n-nodes-pdf-toolkit.CompressPDF",
          "position": [
            460,
            200
          ],
          "parameters": {
            "resource": "url",
            "field_name": "={{ $json.path }}"
          },
          "credentials": {
            "customJsApi": {
              "id": "credential-id",
              "name": "customJsApi Credential"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "d60193ff-0bf6-4692-83e2-d0e1e59c5656",
          "name": "Set PDF URL",
          "type": "n8n-nodes-base.code",
          "position": [
            220,
            200
          ],
          "parameters": {
            "jsCode": "return {\"json\": {\"path\": \"https://www.nlbk.niedersachsen.de/download/164891/Test-pdf_3.pdf.pdf\"}};"
          },
          "typeVersion": 2
        },
        {
          "id": "c68fc714-fc5a-456d-9126-ccbcfedce3ca",
          "name": "Sticky Note",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            140,
            -100
          ],
          "parameters": {
            "color": 4,
            "height": 260,
            "content": "### HTML to PDF\n- Request HTML Data\n- Convert HTML to PDF"
          },
          "typeVersion": 1
        },
        {
          "id": "5388484e-5b74-4ece-90a0-75fc3d9963b5",
          "name": "Sticky Note1",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            380,
            -100
          ],
          "parameters": {
            "color": 5,
            "width": 260,
            "height": 260,
            "content": "### Compress Pages from PDF\n- Compress PDF as a binary file."
          },
          "typeVersion": 1
        },
        {
          "id": "014c6536-0270-4ac7-881a-4334816a9ffb",
          "name": "Sticky Note2",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            140,
            160
          ],
          "parameters": {
            "color": 3,
            "height": 260,
            "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### Set PDF URL\n- Request PDF from URL."
          },
          "typeVersion": 1
        },
        {
          "id": "f6e18c8b-3109-414b-a539-dbb586d6e75e",
          "name": "Sticky Note3",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            380,
            160
          ],
          "parameters": {
            "color": 2,
            "width": 260,
            "height": 260,
            "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### Compress Pages from PDF\n- Compress PDF as a binary file."
          },
          "typeVersion": 1
        }
      ],
      "pinData": {},
      "connections": {
        "HTML to PDF": {
          "main": [
            [
              {
                "node": "Compress PDF file",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Set PDF URL": {
          "main": [
            [
              {
                "node": "Compress PDF file1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Compress PDF file": {
          "main": [
            []
          ]
        },
        "When clicking ‘Test workflow’": {
          "main": [
            [
              {
                "node": "HTML to PDF",
                "type": "main",
                "index": 0
              },
              {
                "node": "Set PDF URL",
                "type": "main",
                "index": 0
              }
            ]
          ]
        }
      }
    },
    "lastUpdatedBy": 29,
    "workflowInfo": {
      "nodeCount": 9,
      "nodeTypes": {
        "n8n-nodes-base.code": {
          "count": 1
        },
        "n8n-nodes-base.stickyNote": {
          "count": 4
        },
        "n8n-nodes-base.manualTrigger": {
          "count": 1
        },
        "@custom-js/n8n-nodes-pdf-toolkit.html2Pdf": {
          "count": 1
        },
        "@custom-js/n8n-nodes-pdf-toolkit.CompressPDF": {
          "count": 2
        }
      }
    },
    "status": "published",
    "readyToDemo": null,
    "user": {
      "name": "CustomJS",
      "username": "customjs",
      "bio": "",
      "verified": true,
      "links": [
        "https://www.customjs.space"
      ],
      "avatar": "https://gravatar.com/avatar/942ecdadf17761bc7f516b67fb0f3617809720caf8912cfd1815ed2a9f8b9ad3?r=pg&d=retro&size=200"
    },
    "nodes": [
      {
        "id": 565,
        "icon": "fa:sticky-note",
        "name": "n8n-nodes-base.stickyNote",
        "codex": {
          "data": {
            "alias": [
              "Comments",
              "Notes",
              "Sticky"
            ],
            "categories": [
              "Core Nodes"
            ],
            "nodeVersion": "1.0",
            "codexVersion": "1.0",
            "subcategories": {
              "Core Nodes": [
                "Helpers"
              ]
            }
          }
        },
        "group": "[\"input\"]",
        "defaults": {
          "name": "Sticky Note",
          "color": "#FFD233"
        },
        "iconData": {
          "icon": "sticky-note",
          "type": "icon"
        },
        "displayName": "Sticky Note",
        "typeVersion": 1,
        "nodeCategories": [
          {
            "id": 9,
            "name": "Core Nodes"
          }
        ]
      },
      {
        "id": 834,
        "icon": "file:code.svg",
        "name": "n8n-nodes-base.code",
        "codex": {
          "data": {
            "alias": [
              "cpde",
              "Javascript",
              "JS",
              "Python",
              "Script",
              "Custom Code",
              "Function"
            ],
            "details": "The Code node allows you to execute JavaScript in your workflow.",
            "resources": {
              "primaryDocumentation": [
                {
                  "url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.code/"
                }
              ]
            },
            "categories": [
              "Development",
              "Core Nodes"
            ],
            "nodeVersion": "1.0",
            "codexVersion": "1.0",
            "subcategories": {
              "Core Nodes": [
                "Helpers",
                "Data Transformation"
              ]
            }
          }
        },
        "group": "[\"transform\"]",
        "defaults": {
          "name": "Code"
        },
        "iconData": {
          "type": "file",
          "fileBuffer": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTEyIiBoZWl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QYXRoPgo8L2RlZnM+Cjwvc3ZnPgo="
        },
        "displayName": "Code",
        "typeVersion": 2,
        "nodeCategories": [
          {
            "id": 5,
            "name": "Development"
          },
          {
            "id": 9,
            "name": "Core Nodes"
          }
        ]
      },
      {
        "id": 838,
        "icon": "fa:mouse-pointer",
        "name": "n8n-nodes-base.manualTrigger",
        "codex": {
          "data": {
            "resources": {
              "generic": [],
              "primaryDocumentation": [
                {
                  "url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.manualworkflowtrigger/"
                }
              ]
            },
            "categories": [
              "Core Nodes"
            ],
            "nodeVersion": "1.0",
            "codexVersion": "1.0"
          }
        },
        "group": "[\"trigger\"]",
        "defaults": {
          "name": "When clicking ‘Execute workflow’",
          "color": "#909298"
        },
        "iconData": {
          "icon": "mouse-pointer",
          "type": "icon"
        },
        "displayName": "Manual Trigger",
        "typeVersion": 1,
        "nodeCategories": [
          {
            "id": 9,
            "name": "Core Nodes"
          }
        ]
      }
    ],
    "categories": [
      {
        "id": 35,
        "name": "Document Extraction"
      }
    ],
    "image": [
      {
        "id": 1267,
        "url": "https://n8niostorageaccount.blob.core.windows.net/n8nio-strapi-blobs-prod/assets/2_aaaad98615.png"
      },
      {
        "id": 1268,
        "url": "https://n8niostorageaccount.blob.core.windows.net/n8nio-strapi-blobs-prod/assets/workflow_5c7ba2ac93.png"
      },
      {
        "id": 1269,
        "url": "https://n8niostorageaccount.blob.core.windows.net/n8nio-strapi-blobs-prod/assets/1_788c6c46f5.png"
      }
    ]
  }
}