Back to Templates

Convert HTML to PDF and Compress Files with CustomJS API

Created by

CustomJS

Last update

Last update a month ago

Categories
Share

workflow.png
This n8n template demonstrates how to convert HTML into a PDF, compress the generated PDF, and return it as a binary response using the PDF Toolkit from www.customjs.space.

Notice

Community nodes can only be installed on self-hosted instances of n8n.

@custom-js/n8n-nodes-pdf-toolkit

What this workflow does

  • Convert the requested HTML to PDF.
  • Compress the PDF file.
  • Use a Code node to handle URLs pointing to PDF files if they exceed 6MB.
  • Compress the PDF pages.

Requirements

  • Self-hosted n8n instance
  • CustomJS API key for compressing PDF files.
  • HTML Data to convert PDF files
  • Code node for handling URL that indicates PDF file.

Workflow Steps:

  1. Manual Trigger:

    • Runs with user interaction.
  2. HTML to PDF:

    • Request HTML Data
    • Convert HTML to PDF
    • Request PDF from URL.
  3. Compress Pages from PDF:

    • Compress PDF as a binary file.

Usage

Get API key from customJS

  • Sign up to customJS platform.
  • Navigate to your profile page
  • Press "Show" button to get API key
    1.png

Set Credentials for CustomJS API on n8n

Copy and paste your API key generated from CustomJS here.
2.png

Design workflow

  • A Manual Trigger for starting workflow.
  • HTTP Request Nodes for downloading PDF files.
  • Code node for handling URL that indicates PDF file.
  • Compress PDF files.

You can replace logic for triggering and returning results.
For example, you can trigger this workflow by calling a webhook and get a result as a response from webhook. Simply replace Manual Trigger and Write to Disk nodes.