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.
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
filelinked todatafrom 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
=datato 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
datafield 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)}}.pdffor 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.pdfappears 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.