8
n8n 中文网amn8n.com

使用Gotenberg从HTML创建PDF

中级

这是一个AI领域的自动化工作流,包含 6 个节点。主要使用 HttpRequest, ConvertToFile, ExecuteWorkflowTrigger 等节点,结合人工智能技术实现智能自动化。 使用Gotenberg从HTML创建PDF

前置要求
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "e409ea34548a2afe2dffba31130cd1cf2e98ebe2afaeed2a63caf2a0582d1da0"
  },
  "nodes": [
    {
      "id": "f0636fec-85ad-47e8-ab43-9a313664be80",
      "name": "创建 index.html",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        100,
        20
      ],
      "parameters": {
        "options": {
          "encoding": "utf8",
          "fileName": "index.html"
        },
        "operation": "toText",
        "sourceProperty": "html"
      },
      "typeVersion": 1.1
    },
    {
      "id": "efcaebc5-e2cc-4af5-a6f2-c75b58496dec",
      "name": "使用 Gotenberg 转换为 PDF",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        320,
        20
      ],
      "parameters": {
        "url": "http://gotenberg:3000/forms/chromium/convert/html",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "form file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            },
            {
              "name": "scale",
              "value": "1"
            },
            {
              "name": "metadata",
              "value": "={\"Author\":\"IA2S\",\"Copyright\":\"IA2S\",\"CreateDate\":\"{{ $now.format('yyyy-MM-dd') }}\",\"Creator\":\"IA2S\",\"Keywords\":[],\"ModDate\":\"{{ $now.format('yyyy-MM-dd') }}\",\"PDFVersion\":1.7,\"Producer\":\"IA2S\",\"Subject\":\"PDF\",\"Title\":\"IA2S PDF\"}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Gotenberg-Output-Filename",
              "value": "={{ $('Create PDF from HTML').last().json.file_name }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "44f89be8-8516-4d8a-a1e4-959c020ca7ae",
      "name": "从 HTML 创建 PDF",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -120,
        20
      ],
      "parameters": {
        "inputSource": "jsonExample",
        "jsonExample": "{\n  \"html\": \"<h1>Hello World</h1>\",\n  \"file_name\": \"my-report-2024\"\n}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "710d67d4-db4a-4943-9ff7-49af8101443a",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        260,
        -340
      ],
      "parameters": {
        "color": 6,
        "width": 320,
        "height": 540,
        "content": "### 🚀 GOTENBERG API 调用"
      },
      "typeVersion": 1
    },
    {
      "id": "365e90ba-b4fa-42b1-9236-33b2f8fb1e76",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        -340
      ],
      "parameters": {
        "color": 7,
        "width": 440,
        "height": 540,
        "content": "### ▶️ 输入与配置"
      },
      "typeVersion": 1
    },
    {
      "id": "c8b440bc-fb02-4b77-89c7-62c2bb88d28e",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -880,
        -340
      ],
      "parameters": {
        "color": 3,
        "width": 440,
        "height": 280,
        "content": "### 🐳 前提条件:GOTENBERG 服务"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {
    "Create PDF from HTML": [
      {
        "html": "<h1>Hello World</h1>",
        "file_name": "my-report-2024"
      }
    ]
  },
  "connections": {
    "Create index.html": {
      "main": [
        [
          {
            "node": "Convert to PDF with Gotenberg",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create PDF from HTML": {
      "main": [
        [
          {
            "node": "Create index.html",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 人工智能

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量6
分类1
节点类型4
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Lucas Peyrin

Lucas Peyrin

@lucaspeyrin

Innovative builder with a passion for crafting automation solutions that solve real-world challenges. From streamlining workflows to driving efficiency, my work empowers teams and individuals to achieve more with less effort. Experienced in developing scalable tools and strategies that deliver results with n8n, supabase and cline.

外部链接
在 n8n.io 查看

分享此工作流