Turn HTML or Markdown into branded, production-ready PDFs from your TypeScript backend. Ships with typed models, streaming downloads, and a sensible retry policy by default.
import fs from 'fs'
import Anvil from '@anvilco/anvil'
const exampleData = {
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. Ut placerat orci nulla pellentesque dignissim enim sit amet venenatis.\n\nMi eget mauris pharetra et ultrices neque ornare aenean.\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'],
],
},
}]
}
const anvilClient = new Anvil({ apiKey })
const { statusCode, data } = await anvilClient.generatePDF(exampleData)
console.log('Making Markdown PDF generation request...')
console.log('Finished! Status code:', statusCode) // => 200, 400, 404, etc
// `data` will be the filled PDF binary data. It is important that the
// data is saved with no encoding! Otherwise the PDF file will be corrupt.
fs.writeFileSync(outputFilepath, data, { encoding: null })
console.log('Generated PDF saved to:', outputFilepath)
The @anvilco/anvil package is MIT-licensed and maintained in the open on GitHub.
$ npm install @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>