How can I generate a PDF file with n8n?

I have a JSON Object getting as HTTP Response.

{  
    "employee": {  
        "name":       "Rocky",   
        "salary":     "5000",   
        "active":     "true"
    }  
} 

I want to generate a PDF file with this JSON.

Is it possible?

Hi @mcnaveen,

Quick answer is yes you can create a PDF using the APITemplate.io Node

3 Likes

Hello @mcnaveen ,
with carboneio/carbone: Fast and simple report generator, from JSON to pdf, xslx, docx, odt… (github.com)
it could be a good option no ?

1 Like

Wow, This looks super cool. I’ll try and let you know.

1 Like

Hi @mcnaveen

I’m using Google Docs to generate a document from a template and get the pdf of that document

In my use case I start with Google Sheet, but it could be with HTTP Request

Here’s code for this workflow that you can adapt to your use case

{
  "name": "Criar documento de template e enviar pdf por email",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -380,
        240
      ],
      "disabled": true
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "copy",
        "fileId": "=1805eWHwa47dTnOAycE2AuRcJuhett4SOJNCPPEubNyE",
        "options": {
          "name": "=Proposta {{$node[\"IF\"].json[\"NUMERO\"]}}",
          "parents": [
            "1-grFMHLTC6mg1CtxF0BV3QvxU9GoO6ji"
          ]
        }
      },
      "name": "Copiar template para pasta especifica",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        300,
        380
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "11",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "update",
        "documentURL": "={{$json[\"id\"]}}",
        "actionsUi": {
          "actionFields": [
            {
              "action": "replaceAll",
              "text": "{{number}}",
              "replaceText": "={{$node[\"IF\"].json[\"NUMERO\"]}}",
              "matchCase": true
            },
            {
              "action": "replaceAll",
              "text": "{{name}}",
              "replaceText": "={{$node[\"IF\"].json[\"NOME\"]}}",
              "matchCase": true
            },
            {
              "action": "replaceAll",
              "text": "{{service}}",
              "replaceText": "={{$node[\"IF\"].json[\"SERVICO\"]}}",
              "matchCase": true
            },
            {
              "action": "replaceAll",
              "text": "{{value}}",
              "replaceText": "={{$node[\"IF\"].json[\"VALOR\"]}}",
              "matchCase": true
            }
          ]
        }
      },
      "name": "Atualizar documento copiado",
      "type": "n8n-nodes-base.googleDocs",
      "typeVersion": 1,
      "position": [
        520,
        380
      ],
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "12",
          "name": "Google Docs account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "share",
        "fileId": "={{$json[\"documentId\"]}}",
        "permissionsUi": {
          "permissionsValues": {
            "role": "reader",
            "type": "anyone"
          }
        },
        "options": {}
      },
      "name": "Compartilhar documento atualizado",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        740,
        380
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "11",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {},
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        -380,
        780
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "resource": "message",
        "subject": "=n8n Workflow Failure:  {{$json[\"workflow\"][\"name\"]}}",
        "message": "=Workflow: {{$json[\"workflow\"][\"name\"]}}\nErro: {{$json[\"execution\"][\"error\"][\"message\"]}}\nÚltimo nó executado: {{$json[\"execution\"][\"lastNodeExecuted\"]}}\nURL de execução: {{$json[\"execution\"][\"url\"]}}",
        "toList": [
          "[email protected]"
        ],
        "additionalFields": {}
      },
      "name": "Mensagem com erro",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -160,
        780
      ],
      "typeVersion": 1,
      "credentials": {
        "gmailOAuth2": {
          "id": "10",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://docs.google.com/feeds/download/documents/export/Export?id={{$node[\"Copiar template para pasta especifica\"].json[\"id\"]}}&exportFormat=pdf",
        "responseFormat": "file",
        "dataPropertyName": "=data",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        960,
        380
      ],
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "sheetId": "1mGd2bDfBHbIbB5-5dzpJvN2V4XwLsEszWpFYp_nB-FI",
        "options": {
          "valueRenderMode": "FORMATTED_VALUE"
        }
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        -160,
        540
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "9",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"ENVIADO\"]}}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        60,
        540
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        300,
        720
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "ENVIADO",
              "value": "Sim"
            },
            {
              "name": "NUMERO",
              "value": "={{$node[\"IF\"].json[\"NUMERO\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        960,
        720
      ]
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        -380,
        540
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "update",
        "sheetId": "1mGd2bDfBHbIbB5-5dzpJvN2V4XwLsEszWpFYp_nB-FI",
        "key": "NUMERO",
        "options": {
          "valueRenderMode": "FORMATTED_VALUE"
        }
      },
      "name": "Atualizar planilha",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1180,
        720
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "9",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "resource": "message",
        "subject": "=Proposta comercial - {{$node[\"IF\"].json[\"NUMERO\"]}}",
        "message": "=Olá {{$node[\"IF\"].json[\"NOME\"]}}\n\nSegue proposta para execução do serviço de {{$node[\"IF\"].json[\"SERVICO\"]}}\n\nAtt,\n\nClaudio da Vamos Automatizar",
        "toList": [
          "[email protected]"
        ],
        "additionalFields": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "=data"
              }
            ]
          }
        }
      },
      "name": "Enviar proposta",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 1,
      "position": [
        740,
        720
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "10",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "items[0].binary.data.fileName = $node[\"Copiar template para pasta especifica\"].json[\"name\"]+'.pdf' \nreturn items;\n"
      },
      "name": "Alterar nome do arquivo",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        520,
        720
      ]
    }
  ],
  "connections": {
    "Copiar template para pasta especifica": {
      "main": [
        [
          {
            "node": "Atualizar documento copiado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Atualizar documento copiado": {
      "main": [
        [
          {
            "node": "Compartilhar documento atualizado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Mensagem com erro",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Alterar nome do arquivo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compartilhar documento atualizado": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Copiar template para pasta especifica",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Atualizar planilha",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enviar proposta": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alterar nome do arquivo": {
      "main": [
        [
          {
            "node": "Enviar proposta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 30
}
2 Likes

Hey @Claudio_Balbino

This is Perfect. :slight_smile: 100% No Code Solution

Thank you for sharing.

2 Likes