# HTML to PDF in Claude Code

Convert HTML or any public URL to PDF from Claude Code with the html-pdf.com remote MCP server. Run one command to connect, then just ask Claude.

**Quick answer:** run `claude mcp add --transport http html-pdf https://html-pdf.com/mcp --header "Authorization: Bearer $HTML_PDF_KEY"`, then ask Claude "Render invoice.html to a PDF".

## Get an API key

You need a key before you connect. Sign up with one call and copy the `api_key` from the response (it is shown once). Then open the link we email you to confirm your address. That adds 100 free credits, and 1 credit = 1 PDF page.

```bash
curl -X POST https://html-pdf.com/v1/signup \
  -H "Content-Type: application/json" \
  -d '{"email": "you@example.com"}'
```

You can also get a key by email at https://html-pdf.com/login. Then export it:

```bash
export HTML_PDF_KEY=hp_live_...
```

## Connect

This step adds the remote MCP server (Streamable HTTP) to Claude Code. There is nothing to install and no `npx`.

```bash
claude mcp add --transport http html-pdf https://html-pdf.com/mcp \
  --header "Authorization: Bearer $HTML_PDF_KEY"
```

Run `/mcp` inside Claude Code to check that `html-pdf` is connected. You get four tools: `html_to_pdf`, `url_to_pdf`, `get_credits`, and `buy_credits`.

No key yet? Add the server without the header and Claude Code opens an html-pdf.com login in your browser. New accounts get 100 free credits.

## Try it

Once connected, you just ask in plain words. You don't write any code. For example:

- "Render `invoice.html` in this repo to an A4 PDF with 15mm margins and page numbers in the footer."
- "Make a PDF of https://example.com in landscape Letter, using screen styles."
- "Turn the README into a styled PDF report and give me the download link. How many html-pdf credits do I have left?"

The tool returns a download link valid for 24 hours, the page count and your remaining credits.

## Tips

These requests help you get cleaner PDFs and repeatable builds.

- **Page breaks:** ask Claude to add `break-before: page` before each section and `break-inside: avoid` on tables and cards.
- **Page numbers:** footers use `<span class="pageNumber"></span>` and `<span class="totalPages"></span>`. Ask for a margin too, or the footer has no room.
- **Guard against runaway documents:** tell Claude to set `max_pages` (for example 10). If the PDF would be longer, the render fails and costs nothing.
- **Scripts in your repo:** for repeatable builds, ask Claude to write a script that calls `POST https://html-pdf.com/v1/pdf` directly with `"response": "url"` or the binary response.

## Troubleshooting

Most issues come from an empty key variable or pages that need more time to load.

- **`html-pdf` shows as failed in `/mcp`:** check that `$HTML_PDF_KEY` was set in the shell where you ran `claude mcp add`. The header value is stored as you typed it, so re-add the server if the variable was empty.
- **`insufficient_credits` (402):** ask Claude to call `buy_credits`. It returns a Stripe payment link. Purchased credits never expire.
- **403 `email_not_confirmed`:** the email behind the key isn't confirmed yet. Click the link we emailed you (it adds the 100 free credits), then try again.
- **Blank or half-rendered page from a URL:** the page needs JavaScript time. Ask for `wait_delay` of 2 to 3 seconds. Pages behind a login won't work, so send their HTML instead.

## FAQ

### How do I add a PDF MCP server to Claude Code?

Run `claude mcp add --transport http html-pdf https://html-pdf.com/mcp` with an `Authorization: Bearer` header holding your key. Then check it with `/mcp`.

### Do I need to install anything locally?

No. html-pdf.com is a remote MCP server, so there is no `npx`, Chrome or Puppeteer to install. Rendering happens on our servers.

### Is there a free tier?

Yes. Every new account gets 100 free credits once you confirm your email, with no card. 1 credit = 1 PDF page, and failed renders cost nothing.

### Does it support page numbers?

Yes. Use `<span class="pageNumber"></span>` and `<span class="totalPages"></span>` in the footer and set a bottom margin so the footer has room.

Full reference: [API docs](https://html-pdf.com/docs) · [MCP server](https://html-pdf.com/mcp)
