# Convert HTML to PDF with one request

> Convert your own HTML and CSS into a PDF with one API request. Paper size, margins, landscape and backgrounds are options. For invoices and reports.

To convert HTML to a PDF, send the HTML to CurlShot in a POST request with format=pdf. A real browser lays the page out and prints it, so your CSS, web fonts, tables and images come out as they look on screen, with text you can select and search. Paper size, margins, orientation and background printing are options.

Page for people: https://curlshot.com/tools/html-to-pdf

## Steps

1. Write the document as HTML and CSS, as you would a web page.
2. Send it in a POST request with format set to pdf and the paper size you want.
3. Save the PDF that comes back, or make one for every order, user or report.

## What people use it for

- Invoices and receipts from an HTML template
- Reports and statements with tables and charts
- Tickets, certificates and contracts with the details filled in
- A printable version of a page of your app

## The same thing with the API

```bash
curl -X POST "https://curlshot.com/api/v1/screenshot" \
  -H "X-Access-Key: YOUR_ACCESS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html":"<h1>Invoice 1042</h1><p>Total: 120.00</p>","format":"pdf","pdf_paper_format":"a4","pdf_margin":"20mm"}' \
  --output invoice.pdf
```

An access key is free: https://curlshot.com/register. Read more:

- [PDF options](https://curlshot.com/docs/pdf.md)
- [HTML and Markdown input](https://curlshot.com/docs/html-and-markdown.md)

## Questions

### How do I convert HTML to PDF?

Send the HTML to CurlShot in the html field of a POST request and add format=pdf. The answer is the PDF file.

### Do backgrounds and colors print?

Yes. Background colors and images are printed unless you switch them off with pdf_print_background=false, for a document that saves ink.

### Can I control page breaks?

Yes, with normal CSS. Rules such as break-before, break-after and break-inside work as they do when a browser prints.

### Can the whole document be one long page?

Yes. pdf_fit_one_page puts everything on a single tall page with no breaks.

## Related

- [Web page to PDF](https://curlshot.com/tools/website-to-pdf.md): Turn a web page into a PDF document from its address. Real pages, working links and selectable text. Paste the address, nothing to install. Also an API.
- [HTML to image](https://curlshot.com/tools/html-to-image.md): Render your own HTML, CSS or Markdown into an image or a PDF with one API request. For social cards, certificates, receipts and reports.
- [Markdown to PDF](https://curlshot.com/tools/markdown-to-pdf.md): Turn Markdown into a clean, styled PDF or image with one API request. Headings, lists, tables and code are laid out for you. For notes, docs and reports.
