Convert HTML to PDF Automatically with n8n and ConvertAPI

Save time converting HTML documents to PDFs with n8n automation using ConvertAPI. This workflow turns HTML content into a polished PDF file quickly, eliminating manual steps and ensuring consistent output.
manualTrigger
httpRequest
code
+3
Workflow Identifier: 2473
NODES in Use: Manual Trigger, Set, Code, HTTP Request, Read Write File, Sticky Note

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

1. Opening Problem Statement

Meet Sarah, a content manager responsible for regularly converting HTML reports into PDF format to share with her team. She spends over an hour daily manually copying HTML code from her system, using conversion software, and then saving PDF files properly named and stored. Sometimes, errors happen—like missing sections in the PDF or misformatted content—leading to confusion and extra follow-ups. This manual routine eats into her valuable time and distracts from higher-priority creative tasks.

Sarah needs a way to automate this workflow to save time and ensure the PDFs are generated consistently and reliably without manual intervention.

2. What This Automation Does

This n8n workflow automates the conversion of HTML content into PDF files by leveraging the ConvertAPI service. Here’s what happens when it runs:

  • Creates an HTML document with preset content.
  • Transforms that HTML string into a binary file usable for uploading.
  • Uses ConvertAPI’s HTTP request node to convert the HTML file into a PDF format remotely.
  • Automatically writes the converted PDF file to your disk with a clear filename.
  • Requires no manual file handling or conversion software during the process.
  • Ensures consistent PDF formatting every time the workflow is triggered.

This automation can save Sarah and anyone needing HTML to PDF conversions several hours weekly by eliminating manual steps and human errors.

3. Prerequisites ⚙️

  • n8n Account: Essential to run this automation and build workflows.
  • ConvertAPI Account: Needed to get an authentication secret for conversion requests. (See ConvertAPI Signup)
  • HTTP Query Auth Credentials: Configured in n8n for secure API access.
  • File System Access: To write the PDF result file locally.

4. Step-by-Step Guide

Step 1: Set Up the Manual Trigger Node

Navigate to your n8n editor. Click the + icon, search for “Manual Trigger,” and add it. This node initiates the workflow manually when you hit the “Test workflow” button.

You should see a simple interface allowing manual execution. No inputs are needed here.

Common mistake: Forgetting to trigger the workflow manually, which halts all subsequent steps.

Step 2: Create the HTML Content Using the Set Node

Add a Set node, rename it to “Create HTML.”

Click to add a new string field named data. Paste in the full HTML content (example below):




    
    
    ConvertAPI Test Document


    

ConvertAPI Test Document

This is a minimal HTML5 document used for testing ConvertAPI's conversion capabilities.

Section Title

This is a section within the document.

© 2024 Test Document

Ensure this node produces a field named data containing valid HTML.

Common mistake: HTML syntax errors or failing to name the field exactly “data” which breaks later nodes.

Step 3: Convert HTML String to Binary File with the Code Node

Add a Code node called “Convert HTML to File.” Use this JavaScript code to convert the HTML string into a binary buffer suitable for file upload:

const text = $node["Create HTML"].json["data"]
const buffer = Buffer.from(text, 'utf8');
const binaryData = {
  data: buffer.toString('base64'),
  mimeType: 'application/octet-stream',
  fileName: 'file.html',
};
items[0].binary = { data: binaryData };
return items;

This prepares the data as a file payload for the next HTTP request.

Common mistake: Forgetting to assign items[0].binary correctly, resulting in an empty file.

Step 4: Configure HTTP Request Node to Convert HTML to PDF

Add an HTTP Request node named “Convert File to PDF.” Configure as follows:

  • Method: POST
  • URL: https://v2.convertapi.com/convert/html/to/pdf
  • Authentication: Use HTTP Query Auth with your ConvertAPI credentials.
  • Body: Set to multipart-form-data with a binary parameter named file linked to data from the previous node.
  • Headers: Add Accept: application/octet-stream
  • Response Format: File (binary)

This sends the HTML file to ConvertAPI, which returns a PDF file.

Common mistake: Misconfiguring authentication or body parameters causing API errors.

Step 5: Save the Resulting PDF with the Write File Node

Add a Read Binary File node renamed “Write Result File to Disk.” Configure:

  • Operation: Write
  • File Name: document.pdf
  • Data Property Name: Set to =data to fetch binary content from input

This writes the PDF to your local disk.

Common mistake: Wrong data property name means an empty or corrupt file.

5. Customizations ✏️

  • Change HTML Content: Edit the Create HTML node’s data field to update the HTML that’s converted, tailoring PDF content.
  • Rename Output PDF: Modify the filename in the Write Result File to Disk node to match your naming conventions.
  • Add Date/Time Stamp: Use an expression in the write file’s filename field like document_{{$now.toISOString().slice(0,10)}}.pdf for versioning.
  • Use Alternate Conversion APIs: Replace the HTTP Request node’s URL and credentials to switch to other HTML to PDF services.
  • Trigger Automatically: Replace manual trigger with a scheduled Cron node for periodic runs.

6. Troubleshooting 🔧

Problem: “Authentication failed” from HTTP Request node.

Cause: Incorrect ConvertAPI secret key or missing HTTP Query Auth setup.

Solution: Double-check your credentials in n8n under Settings → Credentials, and update with the right ConvertAPI key.

Problem: Empty or corrupted PDF saved.

Cause: Incorrect binary data or data property mapping from the Code or Write File node.

Solution: Verify the Code node outputs a binary field named exactly data, and that the Write File node uses the same =data property name.

7. Pre-Production Checklist ✅

  • Verify ConvertAPI credentials are active and correct.
  • Trigger the workflow manually and confirm a PDF file named document.pdf appears in your specified folder.
  • Open the PDF to ensure formatting matches the original HTML content.
  • Backup this workflow JSON before major edits or deployments.

8. Deployment Guide

Once verified, activate the workflow in n8n so it can run on demand. Consider setting up a Cron trigger if you want scheduled PDF generation.

Monitor execution logs within n8n for spotting conversion errors or failed writes. This ensures you catch issues early.

9. FAQs

Q: Can I use another HTML to PDF API instead of ConvertAPI?
A: Yes, you can swap out the HTTP Request node’s URL and credentials to any API that supports HTML to PDF conversion.

Q: Does this workflow consume ConvertAPI credits?
A: Yes, each conversion API call uses credits according to your ConvertAPI plan.

Q: Is my PDF data secure?
A: Using HTTPS and authenticated requests ensures secure transfer, but avoid public API keys in shared environments.

10. Conclusion

Congratulations! You’ve automated the tedious task of turning HTML into PDF files using n8n and ConvertAPI. This workflow saves hours weekly, avoids manual copy-pasting, and guarantees consistent PDF output for your team or clients.

Next steps? You could enhance this setup by integrating email nodes to send PDFs automatically, adding dynamic HTML content generation, or scheduling regular conversions with Cron triggers.

With this knowledge, you’re ready to streamline your document workflows effortlessly.

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation in n8n (Beginner Guide)

A complete beginner guide to building an AI-powered SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free