Turn HTML or Markdown into branded, production-ready PDFs from your JavaScript backend or browser app. Ships with streaming downloads, retry policies, and works in both Node.js and the browser.
import fs from 'fs'
import Anvil from '@anvilco/anvil'
// Your API key from your Anvil organization settings
const apiKey = process.env.ANVIL_API_KEY ?? ''
async function generateMarkdownPDF () {
const anvilClient = new Anvil({ apiKey })
const { statusCode, data, errors } = await anvilClient.generatePDF({
title: 'Example Invoice',
data: [{
label: 'Name',
content: 'Sally Jones',
}, {
content: 'Lorem **ipsum** dolor sit _amet_, consectetur ' +
'adipiscing elit, sed ' +
'[do eiusmod](https://www.useanvil.com/docs) tempor ' +
'incididunt ut labore et dolore magna aliqua.\n\n' +
'* Sagittis eu volutpat odio facilisis.\n\n' +
'* Erat nam at lectus urna.',
}, {
table: {
firstRowHeaders: true,
rows: [
['Description', 'Quantity', 'Price'],
['4x Large Widgets', '4', '$40.00'],
['10x Medium Sized Widgets in dark blue', '10', '$100.00'],
['10x Small Widgets in white', '6', '$60.00'],
],
},
}],
})
if (statusCode === 200 && data) {
// `data` is the generated PDF binary; save it with no encoding or the
// file will be corrupt
fs.writeFileSync(
'generate-markdown-output.pdf', data, { encoding: null }
)
console.log('Generated PDF saved to generate-markdown-output.pdf')
} else {
console.log(
'Error generating PDF:', statusCode, JSON.stringify(errors, null, 2)
)
}
}
generateMarkdownPDF().catch((error) => {
console.error(error)
process.exit(1)
})
The @anvilco/anvil package is MIT-licensed and maintained in the open on GitHub.
$ npm install @anvilco/anvil
$ yarn add @anvilco/anvil
$ pnpm add @anvilco/anvil
$ bun add @anvilco/anvilInstall the Anvil Document SDK plugin in Claude Code and Claude will scaffold the SDK into your codebase — discovery, planning, and production-ready code.
/plugin marketplace add anvilco/anvil-plugins
/plugin install anvil-document-sdk@anvil-pluginsNo API key setup needed. The plugin connects to your Anvil account with OAuth and logs you in automatically.
Use custom HTML and CSS to lay out a 100% pixel-perfect document. Typical response time under 250ms, with 99% of requests completing in under 3.3 seconds. Try the example below and see documentation when ready to generate your own.
<!-- Generate an invoice PDF. Full code: https://github.com/anvilco/html-pdf-invoice-template --> <div class="page-container"> Page <span class="page"></span> of <span class="pages"></span> </div> <div class="logo-container"> <img style="height: 18px" src="https://app.useanvil.com/img/email-logo-black.png" > </div> <table class="invoice-info-container"> <tr> <td rowspan="2" class="client-name"> Client Name </td> <td> Anvil Co </td> </tr> <tr> <td> 123 Main Street </td> </tr> <tr> <td> Invoice Date: <strong>May 24th, 2024</strong> </td> <td> San Francisco CA, 94103 </td> </tr> <tr> <td> Invoice No: <strong>12345</strong> </td> <td> hello@useanvil.com </td> </tr> </table> <table class="line-items-container"> <thead> <tr> <th class="heading-quantity">Qty</th> <th class="heading-description">Description</th> <th class="heading-price">Price</th> <th class="heading-subtotal">Subtotal</th> </tr> </thead> <tbody> <tr> <td>2</td> <td>Blue large widgets</td> <td class="right">$15.00</td> <td class="bold">$30.00</td> </tr> <tr> <td>4</td> <td>Green medium widgets</td> <td class="right">$10.00</td> <td class="bold">$40.00</td> </tr> <tr> <td>5</td> <td>Red small widgets with logo</td> <td class="right">$7.00</td> <td class="bold">$35.00</td> </tr> </tbody> </table> <table class="line-items-container has-bottom-border"> <thead> <tr> <th>Payment Info</th> <th>Due By</th> <th>Total Due</th> </tr> </thead> <tbody> <tr> <td class="payment-info"> <div> Account No: <strong>123567744</strong> </div> <div> Routing No: <strong>120000547</strong> </div> </td> <td class="large">May 30th, 2024</td> <td class="large total">$105.00</td> </tr> </tbody> </table> <div class="footer"> <div class="footer-info"> <span>hello@useanvil.com</span> | <span>555 444 6666</span> | <span>useanvil.com</span> </div> </div>