How to download PDF files from specific links?

Describe the problem/error/question

Hello guys, how are you?

So I’m creating a workflow to automate the download of certain invoices I’ve been receiving. The problem is that these invoices don’t arrive as attachment in my emails. To do it manually, I have to open the email, click on a specific link, then the invoice is opened as you can see in the screenshot so I have to click on a second link in order to save it.

I can extract the URL from the email to open the invoice, but I don’t have any idea on how to save this invoice in my local computer as PDF. Checking the URL of the button “Exportar PDF” I noticed it’s a JavaScript function “javascript: submitForm(‘pdf’)”.

Do you have any idea on how to handle it?

Thanks

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
1 Like

Hi @Felipe Welcome!
You can try using this:

Also if you are stuck at file retrieval then you have to follow two a setup of 2 step HTTP node in order to get that file, once you have it use this node. (Only available in self hosted)

See if below helps……..

You can download files from email links or attachments in n8n using the Gmail (Trigger or Message) or IMAP Email nodes, combined with HTTP Request nodes. The Email nodes fetch the message/link, and the HTTP Request node downloads the actual file, which can then be saved to storage.

Recommended Nodes & Techniques

· Trigger (Real-time): Use the Gmail Trigger or Email Read (IMAP) node to start the workflow when a new email arrives.

· Set “Download Attachments” to true within these nodes to handle files directly.

· Downloading Links from Body:

· Use the Email node to get the email content (HTML/Text).

· Use a Code node (JavaScript) or Regex to extract the specific URL from the body.

· Pass that URL to an HTTP Request node to download the binary file.

· Alternative for Links: Use a Set node to parse the HTML and then HTTP Request to download the file.

Example Workflow

1. Gmail/IMAP Node: Receive Email → Get Body/Attachments.

2. Item Lists/Code Node: Extract the URL (if it’s a link).

3. HTTP Request Node: GET request to the URL.

4. Google Drive/Dropbox Node: Upload the binary data.

The tricky part here is that javascript:submitForm('pdf') means the PDF is generated server-side via a form POST, not a direct file URL. A simple HTTP GET won’t work.

Here’s how to handle this in n8n:

Step 1: Find the actual HTTP request
Open browser DevTools (F12) → Network tab → Click the “Export PDF” button on the invoice page. Look for a POST/GET request that returns the PDF. It usually hits an endpoint like /invoice/123/export?format=pdf or similar.

Step 2: Replicate in n8n
Once you know the real endpoint and parameters:

  1. HTTP Request node → POST to that endpoint with the same headers/cookies/body
  2. Set Response Format to File
  3. The binary data (PDF) will be in the output
  4. Then use Google Drive / Dropbox node to upload, or Email node to attach

Key things to pass:

  • Session cookies (for authentication)
  • Any CSRF token from the form (check for hidden <input> fields)

If the system uses session-based auth, you may need to first do a login request, extract the session cookie, then pass it in the export request.

Can you share what the Network tab shows when you click Export PDF? That’ll help narrow down the exact request to replicate.

1 Like

welcome to the n8n community @Felipe

One thing I’d add is that there are really two separate problems here.
The hard part is reproducing the actual PDF export request behind submitForm(‘pdf’) , since that usually depends on the same session, cookies, CSRF token, and form data the browser is sending.
Once you have that working, saving the PDF is the easy part. In n8n, you just need the HTTP Request node to return the response as a file, and then you can store it wherever you need. The other thing to keep in mind is that saving to your local computer is different from saving from n8n. If you’re self-hosting, you can write the file to the machine where n8n is running. If you’re on n8n Cloud, you’d normally send it to external storage instead.