How to Build an Agent That Outputs Documents?

Hi everyone,

I’m working on an n8n workflow where I want to generate custom company policy documents using OpenAI. Here’s the idea:

  • The system prompt contains a predefined policy template.
  • The user provides a query, and sometimes uploads supporting documents about their company.
  • The goal is to generate a final policy document (e.g. PDF or DOCX) tailored to the user’s input and the template.

I was told that one option is to instruct the OpenAI node to output the result in HTML format, then use a node (or tool) to convert that HTML into a downloadable PDF.

My questions:

  1. What is the best way in n8n to convert HTML (from OpenAI) into a PDF or Word document?
  2. Are there any native or community nodes that make this process easier (e.g. HTML to PDF, Google Docs, etc.)?
  3. Is this the most reliable approach, or do you recommend another workflow for document generation?

Appreciate any ideas or node suggestions!

Information on my n8n setup:

  • n8n version: Version 1.100.1
  • Database :default: SQLite
  • n8n EXECUTIONS_PROCESS setting: default: own, main)
  • Running n8n vian8n cloud,
  • Operating system: Windows

Hi Abeer, have you tried looking into puppeteer?

Hi,
In your case, I think the best approach is to ask OpenAI to output the policy content in HTML format. Then, you can use a Code node in n8n to clean and filter the HTML, and finally insert it into a Word document. That should work well.

Below is a simplified version of the approach — in practice, you might need to adjust it slightly depending on your specific use case.

Hi @abeer-dib,
You can also use a python code to create pdfs, to get those pdfs generated automatically and dynamically you can host that python code on a server and create an api endpoint, then when you have an output from ai agent you can send that to that api endpoint you created and get a pdf file created.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.